Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using MySql.Data.MySqlClient;
- namespace TextSQL
- {
- /// <summary>
- /// Summary description for TextSQLMainWindow.
- /// </summary>
- public class TextSQLMainWindow : System.Windows.Forms.Form
- {
- private System.Windows.Forms.TextBox LogBox1;
- private System.ComponentModel.IContainer components;
- private MySqlConnection conn;
- private Label SchemaLabel;
- private Label UserLabel;
- private Label HostLabel;
- private Label FileInLabel;
- private Label DirOutLabel;
- private Label TQueryCountLabel;
- private Label NQueryCountLabel;
- private Label QueryCountLabel;
- public Label TQueryCountVarLabel;
- public Label NQueryCountVarLabel;
- public Label QueryCountVarLabel;
- public Label DirInVarLabel;
- public Label DirOutVarLabel;
- public Label UserVarLabel;
- public Label SchemaVarLabel;
- public Label HostVarLabel;
- public Label PasswordVarLabel;
- private Label PasswordLabel;
- private GroupBox GroupStatus1;
- private Timer QueryTimer;
- private Button ReloadCFG;
- private Button QueryPause;
- private Button ClearLogBox;
- private StatusStrip statusStrip1;
- private ToolStripStatusLabel AutoScrollLabel;
- private ToolStripStatusLabel DebugLvlLabel;
- public TextSQLMainWindow()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- ReadCFG();
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TextSQLMainWindow));
- this.LogBox1 = new System.Windows.Forms.TextBox();
- this.TQueryCountVarLabel = new System.Windows.Forms.Label();
- this.TQueryCountLabel = new System.Windows.Forms.Label();
- this.NQueryCountVarLabel = new System.Windows.Forms.Label();
- this.NQueryCountLabel = new System.Windows.Forms.Label();
- this.QueryCountVarLabel = new System.Windows.Forms.Label();
- this.QueryCountLabel = new System.Windows.Forms.Label();
- this.DirInVarLabel = new System.Windows.Forms.Label();
- this.FileInLabel = new System.Windows.Forms.Label();
- this.DirOutVarLabel = new System.Windows.Forms.Label();
- this.DirOutLabel = new System.Windows.Forms.Label();
- this.PasswordVarLabel = new System.Windows.Forms.Label();
- this.UserVarLabel = new System.Windows.Forms.Label();
- this.SchemaLabel = new System.Windows.Forms.Label();
- this.SchemaVarLabel = new System.Windows.Forms.Label();
- this.PasswordLabel = new System.Windows.Forms.Label();
- this.UserLabel = new System.Windows.Forms.Label();
- this.HostVarLabel = new System.Windows.Forms.Label();
- this.HostLabel = new System.Windows.Forms.Label();
- this.GroupStatus1 = new System.Windows.Forms.GroupBox();
- this.QueryTimer = new System.Windows.Forms.Timer(this.components);
- this.ReloadCFG = new System.Windows.Forms.Button();
- this.QueryPause = new System.Windows.Forms.Button();
- this.ClearLogBox = new System.Windows.Forms.Button();
- this.statusStrip1 = new System.Windows.Forms.StatusStrip();
- this.AutoScrollLabel = new System.Windows.Forms.ToolStripStatusLabel();
- this.DebugLvlLabel = new System.Windows.Forms.ToolStripStatusLabel();
- this.GroupStatus1.SuspendLayout();
- this.statusStrip1.SuspendLayout();
- this.SuspendLayout();
- //
- // LogBox1
- //
- this.LogBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.LogBox1.Location = new System.Drawing.Point(3, 216);
- this.LogBox1.Multiline = true;
- this.LogBox1.Name = "LogBox1";
- this.LogBox1.ReadOnly = true;
- this.LogBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
- this.LogBox1.Size = new System.Drawing.Size(500, 292);
- this.LogBox1.TabIndex = 0;
- //
- // TQueryCountVarLabel
- //
- this.TQueryCountVarLabel.Location = new System.Drawing.Point(115, 175);
- this.TQueryCountVarLabel.Name = "TQueryCountVarLabel";
- this.TQueryCountVarLabel.Size = new System.Drawing.Size(112, 23);
- this.TQueryCountVarLabel.TabIndex = 6;
- this.TQueryCountVarLabel.Text = "0";
- //
- // TQueryCountLabel
- //
- this.TQueryCountLabel.Location = new System.Drawing.Point(6, 175);
- this.TQueryCountLabel.Name = "TQueryCountLabel";
- this.TQueryCountLabel.Size = new System.Drawing.Size(103, 23);
- this.TQueryCountLabel.TabIndex = 6;
- this.TQueryCountLabel.Text = "Total Query Count:";
- //
- // NQueryCountVarLabel
- //
- this.NQueryCountVarLabel.Location = new System.Drawing.Point(115, 152);
- this.NQueryCountVarLabel.Name = "NQueryCountVarLabel";
- this.NQueryCountVarLabel.Size = new System.Drawing.Size(112, 23);
- this.NQueryCountVarLabel.TabIndex = 5;
- this.NQueryCountVarLabel.Text = "0";
- //
- // NQueryCountLabel
- //
- this.NQueryCountLabel.Location = new System.Drawing.Point(6, 152);
- this.NQueryCountLabel.Name = "NQueryCountLabel";
- this.NQueryCountLabel.Size = new System.Drawing.Size(103, 23);
- this.NQueryCountLabel.TabIndex = 5;
- this.NQueryCountLabel.Text = "Non Query Count:";
- //
- // QueryCountVarLabel
- //
- this.QueryCountVarLabel.Location = new System.Drawing.Point(115, 129);
- this.QueryCountVarLabel.Name = "QueryCountVarLabel";
- this.QueryCountVarLabel.Size = new System.Drawing.Size(112, 23);
- this.QueryCountVarLabel.TabIndex = 4;
- this.QueryCountVarLabel.Text = "0";
- //
- // QueryCountLabel
- //
- this.QueryCountLabel.Location = new System.Drawing.Point(6, 129);
- this.QueryCountLabel.Name = "QueryCountLabel";
- this.QueryCountLabel.Size = new System.Drawing.Size(103, 23);
- this.QueryCountLabel.TabIndex = 4;
- this.QueryCountLabel.Text = "Query Count:";
- //
- // DirInVarLabel
- //
- this.DirInVarLabel.Location = new System.Drawing.Point(341, 37);
- this.DirInVarLabel.Name = "DirInVarLabel";
- this.DirInVarLabel.Size = new System.Drawing.Size(96, 23);
- this.DirInVarLabel.TabIndex = 3;
- this.DirInVarLabel.Text = "Invalid File In";
- //
- // FileInLabel
- //
- this.FileInLabel.Location = new System.Drawing.Point(223, 37);
- this.FileInLabel.Name = "FileInLabel";
- this.FileInLabel.Size = new System.Drawing.Size(112, 23);
- this.FileInLabel.TabIndex = 3;
- this.FileInLabel.Text = "Text Directory In:";
- //
- // DirOutVarLabel
- //
- this.DirOutVarLabel.Location = new System.Drawing.Point(341, 60);
- this.DirOutVarLabel.Name = "DirOutVarLabel";
- this.DirOutVarLabel.Size = new System.Drawing.Size(96, 23);
- this.DirOutVarLabel.TabIndex = 2;
- this.DirOutVarLabel.Text = "Invalid Directory Out:";
- //
- // DirOutLabel
- //
- this.DirOutLabel.Location = new System.Drawing.Point(223, 60);
- this.DirOutLabel.Name = "DirOutLabel";
- this.DirOutLabel.Size = new System.Drawing.Size(112, 23);
- this.DirOutLabel.TabIndex = 2;
- this.DirOutLabel.Text = "Text Directory Out:";
- //
- // PasswordVarLabel
- //
- this.PasswordVarLabel.Location = new System.Drawing.Point(83, 83);
- this.PasswordVarLabel.Name = "PasswordVarLabel";
- this.PasswordVarLabel.Size = new System.Drawing.Size(99, 23);
- this.PasswordVarLabel.TabIndex = 1;
- this.PasswordVarLabel.Text = "Invalid Password";
- //
- // UserVarLabel
- //
- this.UserVarLabel.Location = new System.Drawing.Point(83, 60);
- this.UserVarLabel.Name = "UserVarLabel";
- this.UserVarLabel.Size = new System.Drawing.Size(99, 23);
- this.UserVarLabel.TabIndex = 1;
- this.UserVarLabel.Text = "Invalid User";
- //
- // SchemaLabel
- //
- this.SchemaLabel.Location = new System.Drawing.Point(9, 37);
- this.SchemaLabel.Name = "SchemaLabel";
- this.SchemaLabel.Size = new System.Drawing.Size(49, 23);
- this.SchemaLabel.TabIndex = 1;
- this.SchemaLabel.Text = "Schema:";
- //
- // SchemaVarLabel
- //
- this.SchemaVarLabel.Location = new System.Drawing.Point(80, 36);
- this.SchemaVarLabel.Name = "SchemaVarLabel";
- this.SchemaVarLabel.Size = new System.Drawing.Size(99, 23);
- this.SchemaVarLabel.TabIndex = 1;
- this.SchemaVarLabel.Text = "Invalid Schema";
- //
- // PasswordLabel
- //
- this.PasswordLabel.Location = new System.Drawing.Point(9, 83);
- this.PasswordLabel.Name = "PasswordLabel";
- this.PasswordLabel.Size = new System.Drawing.Size(64, 23);
- this.PasswordLabel.TabIndex = 1;
- this.PasswordLabel.Text = "Password:";
- //
- // UserLabel
- //
- this.UserLabel.Location = new System.Drawing.Point(9, 60);
- this.UserLabel.Name = "UserLabel";
- this.UserLabel.Size = new System.Drawing.Size(74, 23);
- this.UserLabel.TabIndex = 1;
- this.UserLabel.Text = "User:";
- //
- // HostVarLabel
- //
- this.HostVarLabel.Location = new System.Drawing.Point(83, 14);
- this.HostVarLabel.Name = "HostVarLabel";
- this.HostVarLabel.Size = new System.Drawing.Size(99, 23);
- this.HostVarLabel.TabIndex = 1;
- this.HostVarLabel.Text = "Invalid Host";
- //
- // HostLabel
- //
- this.HostLabel.Location = new System.Drawing.Point(9, 14);
- this.HostLabel.Name = "HostLabel";
- this.HostLabel.Size = new System.Drawing.Size(74, 23);
- this.HostLabel.TabIndex = 1;
- this.HostLabel.Text = "Server/Host:";
- //
- // GroupStatus1
- //
- this.GroupStatus1.Controls.Add(this.SchemaVarLabel);
- this.GroupStatus1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
- this.GroupStatus1.Location = new System.Drawing.Point(3, 1);
- this.GroupStatus1.Name = "GroupStatus1";
- this.GroupStatus1.Size = new System.Drawing.Size(490, 116);
- this.GroupStatus1.TabIndex = 7;
- this.GroupStatus1.TabStop = false;
- //
- // QueryTimer
- //
- this.QueryTimer.Enabled = true;
- this.QueryTimer.Interval = 250;
- this.QueryTimer.Tick += new System.EventHandler(this.QueryTimer_Tick);
- //
- // ReloadCFG
- //
- this.ReloadCFG.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.ReloadCFG.Location = new System.Drawing.Point(387, 170);
- this.ReloadCFG.Name = "ReloadCFG";
- this.ReloadCFG.Size = new System.Drawing.Size(105, 23);
- this.ReloadCFG.TabIndex = 8;
- this.ReloadCFG.Text = "Reload Config";
- this.ReloadCFG.Click += new System.EventHandler(this.ReloadCFG_Click);
- //
- // QueryPause
- //
- this.QueryPause.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.QueryPause.Location = new System.Drawing.Point(294, 170);
- this.QueryPause.Name = "QueryPause";
- this.QueryPause.Size = new System.Drawing.Size(87, 23);
- this.QueryPause.TabIndex = 1;
- this.QueryPause.Text = "Pause";
- this.QueryPause.Click += new System.EventHandler(this.QueryPause_Click);
- //
- // ClearLogBox
- //
- this.ClearLogBox.Location = new System.Drawing.Point(387, 141);
- this.ClearLogBox.Name = "ClearLogBox";
- this.ClearLogBox.Size = new System.Drawing.Size(105, 23);
- this.ClearLogBox.TabIndex = 10;
- this.ClearLogBox.Text = "Clear LogBox";
- this.ClearLogBox.UseVisualStyleBackColor = true;
- this.ClearLogBox.Click += new System.EventHandler(this.ClearLogBox_Click);
- //
- // statusStrip1
- //
- this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.AutoScrollLabel,
- this.DebugLvlLabel});
- this.statusStrip1.Location = new System.Drawing.Point(0, 511);
- this.statusStrip1.Name = "statusStrip1";
- this.statusStrip1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
- this.statusStrip1.Size = new System.Drawing.Size(504, 22);
- this.statusStrip1.SizingGrip = false;
- this.statusStrip1.TabIndex = 11;
- this.statusStrip1.Text = "statusStrip1";
- //
- // AutoScrollLabel
- //
- this.AutoScrollLabel.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Right)));
- this.AutoScrollLabel.Name = "AutoScrollLabel";
- this.AutoScrollLabel.Size = new System.Drawing.Size(81, 17);
- this.AutoScrollLabel.Text = "AutoScroll: ON";
- this.AutoScrollLabel.Click += new System.EventHandler(this.AutoScrollLabel_Click);
- //
- // DebugLvlLabel
- //
- this.DebugLvlLabel.BorderSides = ((System.Windows.Forms.ToolStripStatusLabelBorderSides)((System.Windows.Forms.ToolStripStatusLabelBorderSides.Left | System.Windows.Forms.ToolStripStatusLabelBorderSides.Right)));
- this.DebugLvlLabel.Name = "DebugLvlLabel";
- this.DebugLvlLabel.Size = new System.Drawing.Size(94, 17);
- this.DebugLvlLabel.Text = "DebugLevel: OFF";
- this.DebugLvlLabel.Click += new System.EventHandler(this.DebugLvlLabel_Click);
- //
- // TextSQLMainWindow
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(504, 533);
- this.Controls.Add(this.statusStrip1);
- this.Controls.Add(this.ClearLogBox);
- this.Controls.Add(this.ReloadCFG);
- this.Controls.Add(this.TQueryCountVarLabel);
- this.Controls.Add(this.TQueryCountLabel);
- this.Controls.Add(this.NQueryCountVarLabel);
- this.Controls.Add(this.NQueryCountLabel);
- this.Controls.Add(this.QueryCountVarLabel);
- this.Controls.Add(this.QueryCountLabel);
- this.Controls.Add(this.DirInVarLabel);
- this.Controls.Add(this.FileInLabel);
- this.Controls.Add(this.DirOutVarLabel);
- this.Controls.Add(this.DirOutLabel);
- this.Controls.Add(this.PasswordVarLabel);
- this.Controls.Add(this.UserVarLabel);
- this.Controls.Add(this.SchemaLabel);
- this.Controls.Add(this.PasswordLabel);
- this.Controls.Add(this.UserLabel);
- this.Controls.Add(this.HostVarLabel);
- this.Controls.Add(this.HostLabel);
- this.Controls.Add(this.GroupStatus1);
- this.Controls.Add(this.QueryPause);
- this.Controls.Add(this.LogBox1);
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "TextSQLMainWindow";
- this.Text = "TextSQL";
- this.GroupStatus1.ResumeLayout(false);
- this.statusStrip1.ResumeLayout(false);
- this.statusStrip1.PerformLayout();
- this.ResumeLayout(false);
- this.PerformLayout();
- this.WindowState = GlobalVars.Mini;
- }
- #endregion
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main(string[] args) // Entry point, --mini
- {
- foreach(string arg in args)
- {
- if (arg == "--minimized")
- {
- GlobalVars.Mini = FormWindowState.Minimized;
- }
- }
- Application.Run(new TextSQLMainWindow());
- }
- public void TextReturnLines(String returnfile, String Line, int entireline) // Text Files out
- {
- if (!File.Exists(returnfile)) //File Doesn't exist
- {
- using (StreamWriter FileOut = File.CreateText(returnfile))
- {
- if (entireline == 0) // We are just writing some text, not entire line
- {
- FileOut.Write(Line);
- }
- else if (entireline == 1) // Go for a line
- {
- FileOut.WriteLine(Line);
- }
- }
- }
- else
- {
- using (StreamWriter FileOut = File.AppendText(returnfile))
- {
- if (entireline == 0) // We are just writing some text, not entire line
- {
- FileOut.Write(Line);
- }
- else if (entireline == 1) // Go for a line
- {
- FileOut.WriteLine(Line);
- }
- }
- }
- }
- public void LogBoxEntry(String LogEntry) // Drops entries to LogBox and Log File
- {
- if (LogEntry == "Clear LogBox")
- {
- this.LogBox1.Text = "";
- }
- else
- {
- this.LogBox1.AppendText(LogEntry + Environment.NewLine);
- TextReturnLines("log.txt", DateTime.Now + ": " + LogEntry, 1);
- if (GlobalVars.CarrotScroll)
- {
- this.LogBox1.SelectionStart = LogBox1.Text.Length;
- this.LogBox1.ScrollToCaret();
- }
- }
- }
- public void QueryCountUpdate() // Updates The query Counters
- {
- this.NQueryCountVarLabel.Text = Convert.ToString(GlobalVars.NQCount);
- this.QueryCountVarLabel.Text = Convert.ToString(GlobalVars.QCount);
- this.TQueryCountVarLabel.Text = Convert.ToString(GlobalVars.NQCount + GlobalVars.QCount);
- }
- public void QueryBuild(FileInfo file, MySqlConnection conn, String[] FileTextLine, String[] FormatingReturn) // Executes The Query and Return Lines
- {
- try
- {
- String QueryLine = FileTextLine[1];
- MySqlCommand cmd = new MySqlCommand(QueryLine, conn);
- if (Convert.ToInt32(FileTextLine[0]) >= 1)
- {
- //int QueryBack = Convert.ToInt32(FileTextLine[0]);
- MySqlDataReader reader = null;
- reader = cmd.ExecuteReader();
- int QueryBack = reader.FieldCount;
- String[,] QueryLinesBack = new String[256, QueryBack + 1];
- int m = 0;
- while (reader.Read())
- {
- for (int i = 0; i < QueryBack; i++)
- {
- if (reader.IsDBNull(i))
- {
- QueryLinesBack[m, i] = GlobalVars.NullString;
- }
- else
- {
- QueryLinesBack[m, i] = reader.GetString(i);
- }
- }
- m++;
- }
- String QueryLineBack = "";
- //No Need to confuse Lua, get rid of the old file if one was once there
- if (File.Exists(GlobalVars.OutputDir + "\\" + file.Name)) File.Delete(GlobalVars.OutputDir + "\\" + file.Name);
- TextReturnLines(GlobalVars.OutputDir + "\\" + file.Name, "1", 1);
- for (int p = 0; p < m; p++)
- {
- for (int k = 0; k < QueryBack; k++)
- {
- if (k == 0)
- {
- QueryLineBack = GlobalVars.QSep + QueryLinesBack[p, k] + GlobalVars.QSep;
- }
- else if ((k > 0))
- {
- QueryLineBack += " " + GlobalVars.QSep + QueryLinesBack[p, k] + GlobalVars.QSep;
- }
- }
- TextReturnLines(GlobalVars.OutputDir + "\\" + file.Name, QueryLineBack, 1);
- if (GlobalVars.DebugLvl >= 3) LogBoxEntry("QueryLine: " + QueryLineBack);
- }
- //TextReturnLines(GlobalVars.OutputDir + file.Name, GlobalVars.StopString, 1);
- if (GlobalVars.DebugLvl >= 3) LogBoxEntry("Query: Completed");
- GlobalVars.QCount++;
- QueryCountUpdate();
- if (reader != null) reader.Close();
- }
- if (FileTextLine[0] == "0")
- {
- cmd.ExecuteNonQuery();
- TextReturnLines(GlobalVars.OutputDir + "\\" + file.Name, "1", 1);
- //TextReturnLines(GlobalVars.OutputDir + file.Name, GlobalVars.StopString, 1);
- if (GlobalVars.DebugLvl >= 3) LogBoxEntry("NonQuery: Completed");
- GlobalVars.NQCount++;
- QueryCountUpdate();
- }
- //Delete the Query File
- file.Delete(); // (Path.ChangeExtension(, ".old"));
- if (GlobalVars.DebugLvl >= 3) LogBoxEntry("QueryFile Deleted!");
- }
- catch (MySqlException ex)
- {
- //If we had a problem let's not screw around and possibly send it back fed up
- if (File.Exists(GlobalVars.OutputDir + "\\" + file.Name)) File.Delete(GlobalVars.OutputDir + file.Name);
- TextReturnLines(GlobalVars.OutputDir + "\\" + file.Name, "0", 1);
- TextReturnLines(GlobalVars.OutputDir + "\\" + file.Name, ex.Message, 1);
- LogBoxEntry("Query Failed to Execute: " + ex.Message);
- }
- finally
- {
- TextReturnLines(GlobalVars.OutputDir + "\\" + file.Name, GlobalVars.StopString, 1);
- }
- }
- public void CheckTextStop(FileInfo file, String[] FormatingReturn) // Parses in Files in sends to QueryBuild
- {
- try
- {
- //Read from file
- StreamReader FileText =
- new StreamReader(file.FullName);
- //Single line from config.cfg
- //string strLine;
- string[] FileTextLine = new string[4];
- //Parse the Text, 3 lines only
- for (int x = 0; x < 4; x++)
- {
- FileTextLine[x] = FileText.ReadLine();
- }
- //Cleanup
- //Close the Config File
- FileText.Close();
- //We need to make sure our stop String is there, //
- //we don't want to execute half queries now do we //
- if (FileTextLine[2] == GlobalVars.StopString)
- {
- //Lets get the database Connection going
- if (GlobalVars.DebugLvl >= 1)
- {
- LogBoxEntry("Query Found: " + file.Name);
- if (GlobalVars.DebugLvl >= 2)
- {
- LogBoxEntry(FileTextLine[1]);
- }
- }
- string connStr = String.Format("server={0};uid={1};pwd={2};database={3}",
- GlobalVars.Host, GlobalVars.User, GlobalVars.Password, GlobalVars.Schema);
- conn = new MySqlConnection(connStr);
- try
- {
- conn.Open();
- QueryBuild(file, conn, FileTextLine, FormatingReturn);
- }
- catch (MySqlException ex)
- {
- LogBoxEntry("Failed to Connect to Database: " + ex.Message);
- }
- finally
- {
- conn.Close();
- }
- }
- }
- catch (System.IO.IOException ex)
- {
- LogBoxEntry(ex.Message);
- }
- }
- public void ReadCFG() // Called when ReloadCFG Button is clicked, and at Start
- {
- String config = "config.cfg";
- if (! File.Exists(config))
- {
- //File.Create("config.cfg");
- LogBoxEntry("Exception: No ConfigFile, Default created");
- using (StreamWriter sw = new StreamWriter(config))
- {
- sw.WriteLine("Server/Host");
- sw.WriteLine("User");
- sw.WriteLine("Password");
- sw.WriteLine("Schema");
- sw.WriteLine("Directory In");
- sw.WriteLine("Directory Out");
- sw.WriteLine("StopString");
- sw.WriteLine("QuerySeperator");
- sw.WriteLine("NullString");
- }
- }
- //Read from file
- StreamReader ConfigFile =
- new StreamReader(config);
- //Single line from config.cfg
- //string strLine;
- string[] Conn_Details = new string[9];
- for (int x = 0; x < 9; x++)
- {
- Conn_Details[x] = ConfigFile.ReadLine();
- }
- //Assign the Config to The GlobalVars
- GlobalVars.Host = Conn_Details[0];
- GlobalVars.User = Conn_Details[1];
- GlobalVars.Password = Conn_Details[2];
- GlobalVars.Schema = Conn_Details[3];
- GlobalVars.InputDir = Conn_Details[4];
- GlobalVars.OutputDir = Conn_Details[5];
- GlobalVars.StopString = Conn_Details[6];
- GlobalVars.QSep = Conn_Details[7];
- GlobalVars.NullString = Conn_Details[8];
- //Sets the text box crap
- this.HostVarLabel.Text = GlobalVars.Host;
- this.UserVarLabel.Text = GlobalVars.User;
- this.PasswordVarLabel.Text = GlobalVars.Password;
- this.SchemaVarLabel.Text = GlobalVars.Schema;
- this.DirInVarLabel.Text = GlobalVars.InputDir;
- this.DirOutVarLabel.Text = GlobalVars.OutputDir;
- //The Better way
- //this.LogBox1.Text += "Using Stop String: \"" + GlobalVars.StopString + "\"" + Environment.NewLine;
- //Even Better Way
- if (GlobalVars.DebugLvl >= 1)
- {
- LogBoxEntry("Using Stop String: \"" + GlobalVars.StopString + "\"");
- LogBoxEntry("Using Query Seperator: \"" + GlobalVars.QSep + "\"");
- LogBoxEntry("Using Null String: \"" + GlobalVars.NullString + "\"");
- }
- //Cleanup
- //Close the Config File
- ConfigFile.Close();
- //We need to make sure our Directories Exist, Right?
- if (!Directory.Exists(GlobalVars.InputDir))
- {
- Directory.CreateDirectory(GlobalVars.InputDir);
- LogBoxEntry("Input Directory Not Found, Creating");
- }
- if (!Directory.Exists(GlobalVars.OutputDir))
- {
- Directory.CreateDirectory(GlobalVars.OutputDir);
- LogBoxEntry("Output Directory Not Found, Creating");
- }
- }
- public void QueryCheck() // Calls CheckTextStop - For each file *.txt found
- {
- DirectoryInfo InDir = new DirectoryInfo(GlobalVars.InputDir);
- FileInfo[] InFiles = InDir.GetFiles("*.txt");
- foreach ( FileInfo f in InFiles)
- {
- String[] FormatingReturn = new String[8];
- CheckTextStop(f, FormatingReturn);
- }
- }
- private void QueryPause_Click(object sender, System.EventArgs e)
- {
- GlobalVars.Running = (!GlobalVars.Running);
- if (GlobalVars.Running)
- {
- this.QueryPause.Text = "Pause";
- if (GlobalVars.DebugLvl >= 1) LogBoxEntry("Querying: Resumed");
- }
- else
- {
- this.QueryPause.Text = "Resume";
- if (GlobalVars.DebugLvl >= 1) LogBoxEntry("Querying: Paused");
- }
- }
- private void QueryTimer_Tick(object sender, System.EventArgs e)
- {
- QueryTimer.Enabled = false;
- if (GlobalVars.Running)
- QueryCheck();
- QueryTimer.Enabled = true;
- }
- private void ReloadCFG_Click(object sender, EventArgs e)
- {
- LogBoxEntry("Clear LogBox");
- LogBoxEntry("Reloaded config file, Log Box Cleared!");
- ReadCFG();
- }
- private void AutoScrollLabel_Click(object sender, EventArgs e) //Toggle AutoScrolling on the LogBox
- {
- GlobalVars.CarrotScroll = (!GlobalVars.CarrotScroll);
- if (GlobalVars.CarrotScroll) //True Scroll
- {
- this.AutoScrollLabel.Text = "AutoScroll: ON";
- }
- else
- {
- this.AutoScrollLabel.Text = "AutoScroll: OFF";
- }
- }
- private void ClearLogBox_Click(object sender, EventArgs e)
- {
- LogBoxEntry("Clear LogBox");
- LogBoxEntry("LogBox Cleared!");
- }
- private void DebugLvlLabel_Click(object sender, EventArgs e)
- {
- if (GlobalVars.DebugLvl == 3)
- {
- this.DebugLvlLabel.Text = "DebugLevel: OFF";
- GlobalVars.DebugLvl = 0;
- LogBoxEntry("DebugMode: OFF");
- }
- else if (GlobalVars.DebugLvl == 0)
- {
- this.DebugLvlLabel.Text = "DebugLevel: 1";
- GlobalVars.DebugLvl = 1;
- LogBoxEntry("DebugMode: Level 1");
- }
- else if (GlobalVars.DebugLvl == 1)
- {
- this.DebugLvlLabel.Text = "DebugLevel: 2";
- GlobalVars.DebugLvl = 2;
- LogBoxEntry("DebugMode: Level 2");
- }
- else if (GlobalVars.DebugLvl == 2)
- {
- this.DebugLvlLabel.Text = "DebugLevel: 3";
- GlobalVars.DebugLvl = 3;
- LogBoxEntry("DebugMode: Level 3");
- }
- }
- }
- public class GlobalVars
- {
- public static String Host;
- public static String StopString;
- public static String InputDir;
- public static String OutputDir;
- public static String Password;
- public static String User;
- public static String Schema;
- public static String QSep;
- public static String NullString;
- public static FormWindowState Mini = FormWindowState.Normal;
- public static bool CarrotScroll = true;
- public static bool Running = true;
- public static int DebugLvl = 0;
- public static int QCount = 0;
- public static int NQCount = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement