Commercial & open source. Find your way forward.Compare editions
OCS NETWORKS INC / OSS

IntelliDispatch OSS MIT License

The open-source edition. An MIT-licensed core, with optional paid, licensed plugins.

Code About this workspace LicenseRead-only source browser
Public files
Login.cs
5.2 KB · 165 linesModified Nov 6, 2026 UTC
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{18    public partial class Login : Form19    {20        private string MyConString = IntelliDispatch.Global.MyConString;21        PrivateFontCollection pfc = new PrivateFontCollection();2223        public Login()24        {25            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);2627            InitializeComponent();2829            //pfc.AddFontFile(Application.StartupPath+@"\fonts\mono1.ttf");30            //label3.Font = new Font(pfc.Families[0], 35, FontStyle.Regular);31            32            database.SelectedIndex = database.FindStringExact("MasterDatabase");3334            username.Text = "demo";35            password.Text = "demo";3637            Rectangle screen = Screen.PrimaryScreen.Bounds;38            39            if (screen.Width < 1024)40            {41                MessageBox.Show("Your screen resolution is below the recommended!");42            }4344            statuslabel.Text = "Ready";45            46        }4748        private static string _Username = "";4950        public static string LoginUsername51        {52            get { return _Username; }53            set { _Username = value; }54        }5556        private void username_KeyDown(object sender, KeyEventArgs e)57        {58            if (e.KeyCode == Keys.Enter)59            {60                password.Focus();61            }6263        }6465        private void password_KeyDown(object sender, KeyEventArgs e)66        {67            if (e.KeyCode == Keys.Enter)68            {69                button1.PerformClick();70            }7172        }73        private void button1_Click(object sender, EventArgs e)74        {75            statuslabel.Text = "Validating Username & Password";76            Cursor.Current = Cursors.WaitCursor;77            78            bool validusername = false;7980            MySqlConnection connection = new MySqlConnection(MyConString);81            MySqlCommand command = connection.CreateCommand();82            connection.Open();83            MySqlDataReader Reader;8485            command.CommandText = "SELECT * FROM users where username=@username AND password=@password";86            command.Parameters.AddWithValue("@username", username.Text);87            command.Parameters.AddWithValue("@password", password.Text);8889            Reader = command.ExecuteReader();9091            while (Reader.Read())92            {93                if ((string)Reader["username"] != null && (string)Reader["password"] != null)94                {95                    validusername = true;96                    _Username = username.Text;97                    statuslabel.Text = "Starting Application...";98                    99                }100                else101                {102                    validusername = false;103                    MessageBox.Show("Invalid Login!");104                    105                }106            }107            connection.Close();108109110111            if (validusername == true)112            {113                114                button1.Text = "Loggin In...";115                button1.Enabled = false;116                //Call the find plugins routine, to search in our Plugins Folder117                Global.Plugins.FindPlugins(Application.StartupPath + @"\Plugins");118                Cursor.Current = Cursors.Arrow;119                this.DialogResult = DialogResult.OK;120            }121            else122            {123                statuslabel.Text = "Username or Password invalid";124                Cursor.Current = Cursors.Arrow;125                126            }127128129130131        }132133        protected void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)134        {135136            using (StreamWriter w = File.AppendText("log.txt"))137            {138                Log("" + e.Exception, w);139            }140141            //Prompt to Send Error to Development142143            var SendError = new SendError(e.Exception.ToString());144            SendError.ShowDialog();145            146            //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        }154155        public static void Log(string logMessage, TextWriter w)156        {157            w.Write("\r\nIntelliDispatch : ");158            w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),159                DateTime.Now.ToLongDateString());160            w.WriteLine("  :");161            w.WriteLine("  :{0}", logMessage);162            w.WriteLine("-------------------------------");163        }164    }165}