1using System;2using System.Collections.Generic;3using System.ComponentModel;4using System.Data;5using System.Drawing;6using System.Linq;7using System.Text;8using System.Windows.Forms;9using MySql.Data.MySqlClient;10using System.IO;11using System.Drawing.Text;12using System.Runtime.InteropServices;13using System.Reflection;141516namespace IntelliDispatch17{18public partial class Login : Form19{20private string MyConString = IntelliDispatch.Global.MyConString;21PrivateFontCollection pfc = new PrivateFontCollection();2223public Login()24{25Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);2627InitializeComponent();2829//pfc.AddFontFile(Application.StartupPath+@"\fonts\mono1.ttf");30//label3.Font = new Font(pfc.Families[0], 35, FontStyle.Regular);3132database.SelectedIndex = database.FindStringExact("MasterDatabase");3334username.Text = "demo";35password.Text = "demo";3637Rectangle screen = Screen.PrimaryScreen.Bounds;3839if (screen.Width < 1024)40{41MessageBox.Show("Your screen resolution is below the recommended!");42}4344statuslabel.Text = "Ready";4546}4748private static string _Username = "";4950public static string LoginUsername51{52get { return _Username; }53set { _Username = value; }54}5556private void username_KeyDown(object sender, KeyEventArgs e)57{58if (e.KeyCode == Keys.Enter)59{60password.Focus();61}6263}6465private void password_KeyDown(object sender, KeyEventArgs e)66{67if (e.KeyCode == Keys.Enter)68{69button1.PerformClick();70}7172}73private void button1_Click(object sender, EventArgs e)74{75statuslabel.Text = "Validating Username & Password";76Cursor.Current = Cursors.WaitCursor;7778bool validusername = false;7980MySqlConnection connection = new MySqlConnection(MyConString);81MySqlCommand command = connection.CreateCommand();82connection.Open();83MySqlDataReader Reader;8485command.CommandText = "SELECT * FROM users where username=@username AND password=@password";86command.Parameters.AddWithValue("@username", username.Text);87command.Parameters.AddWithValue("@password", password.Text);8889Reader = command.ExecuteReader();9091while (Reader.Read())92{93if ((string)Reader["username"] != null && (string)Reader["password"] != null)94{95validusername = true;96_Username = username.Text;97statuslabel.Text = "Starting Application...";9899}100else101{102validusername = false;103MessageBox.Show("Invalid Login!");104105}106}107connection.Close();108109110111if (validusername == true)112{113114button1.Text = "Loggin In...";115button1.Enabled = false;116//Call the find plugins routine, to search in our Plugins Folder117Global.Plugins.FindPlugins(Application.StartupPath + @"\Plugins");118Cursor.Current = Cursors.Arrow;119this.DialogResult = DialogResult.OK;120}121else122{123statuslabel.Text = "Username or Password invalid";124Cursor.Current = Cursors.Arrow;125126}127128129130131}132133protected void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)134{135136using (StreamWriter w = File.AppendText("log.txt"))137{138Log("" + e.Exception, w);139}140141//Prompt to Send Error to Development142143var SendError = new SendError(e.Exception.ToString());144SendError.ShowDialog();145146//using (FileStream file = new FileStream(Application.StartupPath.ToString() + "\\log.txt", FileMode.OpenOrCreate, FileAccess.Write))147//{148// StreamWriter streamWriter = new StreamWriter(file);149//streamWriter.WriteLine((((System.DateTime.Now + " - ") + "Intellicast - ")) + e.Exception + "\r\n");150//streamWriter.WriteLine("\n");151//streamWriter.Close();152//}153}154155public static void Log(string logMessage, TextWriter w)156{157w.Write("\r\nIntelliDispatch : ");158w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),159DateTime.Now.ToLongDateString());160w.WriteLine(" :");161w.WriteLine(" :{0}", logMessage);162w.WriteLine("-------------------------------");163}164}165}