using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; using System.IO; using System.Drawing.Text; using System.Runtime.InteropServices; using System.Reflection; namespace IntelliDispatch { public partial class Login : Form { private string MyConString = IntelliDispatch.Global.MyConString; PrivateFontCollection pfc = new PrivateFontCollection(); public Login() { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); InitializeComponent(); //pfc.AddFontFile(Application.StartupPath+@"\fonts\mono1.ttf"); //label3.Font = new Font(pfc.Families[0], 35, FontStyle.Regular); database.SelectedIndex = database.FindStringExact("MasterDatabase"); username.Text = "demo"; password.Text = "demo"; Rectangle screen = Screen.PrimaryScreen.Bounds; if (screen.Width < 1024) { MessageBox.Show("Your screen resolution is below the recommended!"); } statuslabel.Text = "Ready"; } private static string _Username = ""; public static string LoginUsername { get { return _Username; } set { _Username = value; } } private void username_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { password.Focus(); } } private void password_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { button1.PerformClick(); } } private void button1_Click(object sender, EventArgs e) { statuslabel.Text = "Validating Username & Password"; Cursor.Current = Cursors.WaitCursor; bool validusername = false; MySqlConnection connection = new MySqlConnection(MyConString); MySqlCommand command = connection.CreateCommand(); connection.Open(); MySqlDataReader Reader; command.CommandText = "SELECT * FROM users where username=@username AND password=@password"; command.Parameters.AddWithValue("@username", username.Text); command.Parameters.AddWithValue("@password", password.Text); Reader = command.ExecuteReader(); while (Reader.Read()) { if ((string)Reader["username"] != null && (string)Reader["password"] != null) { validusername = true; _Username = username.Text; statuslabel.Text = "Starting Application..."; } else { validusername = false; MessageBox.Show("Invalid Login!"); } } connection.Close(); if (validusername == true) { button1.Text = "Loggin In..."; button1.Enabled = false; //Call the find plugins routine, to search in our Plugins Folder Global.Plugins.FindPlugins(Application.StartupPath + @"\Plugins"); Cursor.Current = Cursors.Arrow; this.DialogResult = DialogResult.OK; } else { statuslabel.Text = "Username or Password invalid"; Cursor.Current = Cursors.Arrow; } } protected void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { using (StreamWriter w = File.AppendText("log.txt")) { Log("" + e.Exception, w); } //Prompt to Send Error to Development var SendError = new SendError(e.Exception.ToString()); SendError.ShowDialog(); //using (FileStream file = new FileStream(Application.StartupPath.ToString() + "\\log.txt", FileMode.OpenOrCreate, FileAccess.Write)) //{ // StreamWriter streamWriter = new StreamWriter(file); //streamWriter.WriteLine((((System.DateTime.Now + " - ") + "Intellicast - ")) + e.Exception + "\r\n"); //streamWriter.WriteLine("\n"); //streamWriter.Close(); //} } public static void Log(string logMessage, TextWriter w) { w.Write("\r\nIntelliDispatch : "); w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString()); w.WriteLine(" :"); w.WriteLine(" :{0}", logMessage); w.WriteLine("-------------------------------"); } } }