Example #1
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (textBoxUsername.Text == "")
            {
                userNameRequiredLabel.Show();
            }
            else
            {
                userNameRequiredLabel.Hide();
            }
            if (textBoxPassword.Text == "")
            {
                passwordRequiredLabel.Show();
            }
            else
            {
                passwordRequiredLabel.Hide();
            }
            if (textBoxUsername.Text != "" && textBoxPassword.Text != "")
            {
                String     query   = "SELECT * FROM Users WHERE Name='" + textBoxUsername.Text + "' AND Password='******'";
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                string        type   = "";
                int           count  = 0;
                while (reader.Read())
                {
                    count++;
                    type = reader["Type"].ToString();
                }
                connection.Close();
                if (count == 1)
                {
                    textBoxUsername.Text = "";
                    textBoxPassword.Text = "";
                    this.Hide();
                    switch (type.ToUpper())
                    {
                    case "MIS MANAGER":
                        MISManagerForm mm = new MISManagerForm();
                        mm.SetDesktopLocation(0, 0);
                        mm.BringToFront();
                        mm.Show();
                        break;

                    case "SALES MANAGER":
                        SalesManagerForm sm = new SalesManagerForm();
                        sm.SetDesktopLocation(0, 0);
                        sm.BringToFront();
                        sm.Show();
                        break;

                    case "ORDER CLERKS":
                        OrderClerksForm oc = new OrderClerksForm();
                        oc.SetDesktopLocation(0, 0);
                        oc.BringToFront();
                        oc.Show();
                        break;

                    case "ACCOUNTANT":
                        AccountantForm a = new AccountantForm();
                        a.SetDesktopLocation(0, 0);
                        a.BringToFront();
                        a.Show();
                        break;

                    case "INVENTORY CONTROLLER":
                        InventoryControllerForm ic = new InventoryControllerForm();
                        ic.SetDesktopLocation(0, 0);
                        ic.BringToFront();
                        ic.Show();
                        break;
                    }
                }
            }
        }
Example #2
0
        public static Employee SearchUser(int username, string password)
        {
            if (File.Exists(EmployeePath))
            {
                StreamReader sReader = new StreamReader(EmployeePath);


                bool found = false;

                string line = sReader.ReadLine();
                while (line != null)
                {
                    string[] fields = line.Split(',');

                    if (fields[0] == username.ToString())
                    {
                        if (Convert.ToString(fields[6]) == "MIS Manager")
                        {
                            MessageBox.Show("Login Successful! Welcome MIS Manager!", "MIS Manager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            found = true;
                            MISManagerForm M1 = new MISManagerForm();
                            M1.ShowDialog();
                            break;
                        }
                        if (Convert.ToString(fields[6]) == "Sales Manager")
                        {
                            MessageBox.Show("Login Successful.... Welcome Sales Manager!", "Sales Manager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                            SalesManagerForm S1 = new SalesManagerForm();
                            S1.ShowDialog();
                            break;
                        }
                        if (Convert.ToString(fields[6]) == "Inventory Controller")
                        {
                            MessageBox.Show("Login Successful.... Welcome to inventory Controller!", "Inventory Controller", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            found = true;
                            InventoryCollectorForm I1 = new InventoryCollectorForm();
                            I1.ShowDialog();
                            break;
                        }
                        if (Convert.ToString(fields[6]) == "Order Clerk")
                        {
                            MessageBox.Show("Login Successful.... Welcome to Order Clerk!", "Order Clerks", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            found = true;
                            OrdersClerkForm O1 = new OrdersClerkForm();
                            O1.ShowDialog();
                            break;
                        }
                    }

                    line = sReader.ReadLine();
                }
                sReader.Close();

                if (!found)
                {
                    MessageBox.Show("Check the file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            else
            {
                MessageBox.Show("file does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(null);
        }