|
//
// Text2Mambo - convert HTML to mambo CMS
// Copyright (C) 2009-2011 John Janssen
// http://www.travelisfun.org
//
// This program is free software; you can redistribute it and/or modify
// it any way you want as long as the above copyright statement is maintained.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Runtime;
using System.Diagnostics;
using Microsoft.Win32;
using TIFTools;
using Text2Mambo.Controls;
using Text2Mambo.Tools;
// [assembly: CLSCompliant(true)]
namespace Text2Mambo
{
public partial class MainForm : Form
{
private static String outputFile;
private Cursor dragDropCursor = null;
private ArrayList fileProcessList = new ArrayList();
private static UCTextImport textImportCtrl = null;
private static UCDatabaseLogin databaseLoginCtrl = null;
private static UCSyncOnline syncOnline = null;
private static UCFTPLogin ftpLogin = null;
private static MainForm instance;
public static MainForm Instance
{
get { return instance; }
}
public static UCSyncOnline SyncOnline
{
get { return syncOnline; }
}
public static UCFTPLogin FtpLogin
{
get { return ftpLogin; }
}
/// <summary>
///
/// </summary>
public static String OutputFile
{
get { return outputFile; }
}
/// <summary>
/// Start of program
/// </summary>
public MainForm()
{
instance = this;
ProgramSettings.RegistryPath = @"software\TravelisFun\Text2Mambo";
if (Program.CommandLineArgs.Length != 0)
{
ProgramSettings.NoUserInterface = true;
}
outputFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\TravelIsFun\Text2Mambo\out.txt";
Application.EnableVisualStyles();
InitializeComponent();
}
/// <summary>
/// Do commandline processing.
/// </summary>
/// <param name="args"></param>
private void ProcessCommandLine(String[] args)
{
foreach (String inputFile in args)
{
if (inputFile.Length > 0 && inputFile[0] != '/')
{
TextImportCtrl.ReadAndProcessInputFile(inputFile);
}
}
}
/// <summary>
/// Close the connection with the mambo mysql server
/// </summary>
static public void CloseConnection()
{
MamboConnection.Disconnect();
}
/// <summary>
/// Close the connection with the mambo mysql server if opened is true.
/// </summary>
/// <param name="opened"></param>
static public void CloseConnection(bool opened)
{
if (opened)
CloseConnection();
}
/// <summary>
/// Tries to open the connection. Return true is a connection is opened.
/// return false if a previous opened connection is returned.
/// </summary>
/// <returns></returns>
public static bool OpenConnection()
{
if (databaseLoginCtrl == null)
return false;
if (MamboConnection.IsOpen)
return false;
MamboConnection.Connect(databaseLoginCtrl.Servername,
databaseLoginCtrl.Database,
databaseLoginCtrl.Username,
databaseLoginCtrl.Password,
databaseLoginCtrl.ConnectOptions);
return MamboConnection.IsOpen;
}
/// <summary>
///
/// </summary>
/// <param name="uc"></param>
/// <param name="name"></param>
private void AddTabPage(UserControl uc, String name)
{
TabPage tp;
tp = new TabPage(uc.ToString());
tp.Name = name;
tp.UseVisualStyleBackColor = true;
tp.Controls.Add(uc);
tabControlMain.TabPages.Add(tp);
}
/// <summary>
/// Loading the main form.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
this.Width = 900;
this.Height = 600;
HTMLCharTable.Check(); // create the HTMLCharTable
TrySoftware(); // run test software, if any
tabControlMain.TabPages.Clear();
AddTabPage(databaseLoginCtrl = new UCDatabaseLogin(), "tabpageDatabaseLogin");
AddTabPage(textImportCtrl = new UCTextImport(), "tabpageTextImport");
AddTabPage(new UCAdvancedSetup(), "tabpageAdvancedSetup");
AddTabPage(new UCTextExport(), "tabpageTextExport");
AddTabPage(new UCOtherTools(), "tabpageOtherTools");
AddTabPage(syncOnline = new UCSyncOnline(), "tabpageSyncOnline");
AddTabPage(ftpLogin = new UCFTPLogin(), "tabpageFTPLogin");
AddTabPage(new UCCodeProjectTxt(), "tappageCodeproject");
if (databaseLoginCtrl.ConnectOptions.Length == 0)
{
databaseLoginCtrl.ConnectOptions = "Persist Security Info=False";
databaseLoginCtrl.Servername = "Localhost";
databaseLoginCtrl.Database = "Mambo";
databaseLoginCtrl.Username = "root";
databaseLoginCtrl.Password = String.Empty;
}
String selectPageName = (MamboConnection.IsOpen) ? "tabpageTextImport" : "tabpageDatabaseLogin";
// Select the Text Import tab page as a startup
// and run the Loading method if the tabpage is a MyUserControl.
foreach (TabPage tp in tabControlMain.TabPages)
{
foreach (Control c in tp.Controls)
{
if (c is MyUserControl)
((MyUserControl)c).Loading();
}
if (tp.Name == selectPageName)
{
tabControlMain.SelectedTab = tp;
}
}
// Hide the userinterface if commandline method is used.
if (ProgramSettings.NoUserInterface)
{
this.Visible = false;
ProcessCommandLine(Program.CommandLineArgs);
Close();
}
}
#region Code for testing purposes
private void TrySoftware()
{
#if DEBUG
//TestDateTime();
#endif
return;
}
private void TestDateTime()
{
CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
DateTimeFormatInfo dtfi = ci.DateTimeFormat; // new DateTimeFormatInfo(); // ci.DateTimeFormat;
dtfi.MonthNames = new String[] { "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december", "" };
dtfi.MonthGenitiveNames = dtfi.MonthNames;
dtfi.LongDatePattern = "d-MMMM-yyyy";
String dateStr = "1 augustus 2011";
DateTime dt = DateTime.Parse(dateStr, dtfi, DateTimeStyles.None);
MessageBox.Show(dt.ToShortDateString());
}
#endregion
/// <summary>
/// Form Closing handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
// Call the closing method for each MyUserControl in he tabpages.
foreach (TabPage tp in tabControlMain.TabPages)
{
foreach (Control uc in tp.Controls)
{
if (uc is MyUserControl)
{
((MyUserControl)uc).Closing();
uc.Dispose(); // kill the control.
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_DragDrop(object sender, DragEventArgs e)
{
try
{
String[] filedropList = e.Data.GetData(DataFormats.FileDrop, true) as String[];
if (filedropList != null)
{
for (int i = 0; i < filedropList.Length; i++)
{
// Call OpenFile asynchronously.
// Explorer instance from which file is dropped is not responding
// all the time when DragDrop handler is active, so we need to return
// immidiately (especially if OpenFile shows MessageBox)
lock (fileProcessList)
{
fileProcessList.Add(filedropList[i]);
}
}
if (!backgroundWorker.IsBusy)
backgroundWorker.RunWorkerAsync();
}
}
catch (Exception ex)
{
Trace.WriteLine("Error in DragDrop function: " + ex.Message);
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_DragEnter(object sender, DragEventArgs e)
{
if (dragDropCursor != null)
Cursor.Current = dragDropCursor;
//IDataObject obj = e.Data;
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_DragLeave(object sender, EventArgs e)
{
Cursor.Current = Cursors.Default;
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
while (fileProcessList.Count != 0)
{
String filename = "";
lock (fileProcessList)
{
filename = (String)fileProcessList[0];
fileProcessList.RemoveAt(0);
}
TextImportCtrl.ReadAndProcessInputFile(filename);
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public UCTextImport TextImportCtrl
{
get { return textImportCtrl; }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Started in 1988 programming in Pascal, making a 68000 emulator on a DOS platform. Then from Pascal to Clipper, to C++ and now using C#. I've been programming for all walks of businesses; opticians, opthomologist, carbage collectors, reinforcement steel producers, retail chains, and more.
I'm now travelling through Africa with a home-build expedition truck.