Beispiel #1
0
        private void BackBt_Click(object sender, EventArgs e)
        {
            this.Hide();
            Admin_form a = new Admin_form();

            a.Show();
        }
Beispiel #2
0
        private void SignIn_bt_Click(object sender, EventArgs e)
        {
            if (usernametxt.Text == "" || passwordtxt.Text == "")
            {
                MessageBox.Show("Please enter all information", "Sign in error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (customerRadiobox.Checked == false && driverRadiobox.Checked == false && cookRadiobox.Checked == false && checkerRadiobox.Checked == false && adminRadiobox.Checked == false)
            {
                MessageBox.Show("Please enter all information", "Sign in error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                try
                {
                    username = usernametxt.Text;
                    user.con.Open();
                    if (user.con.State == System.Data.ConnectionState.Open) //to avoid database connection errors
                    {
                        string query = null;
                        if (sqlTable == "Admin")
                        {
                            query = "select top 1 * from " + sqlTable + " where Name = '" + usernametxt.Text + "' and Password = '******'";
                        }
                        else
                        {
                            query = "select top 1 * from " + sqlTable + " where Username = '******' and Password = '******'";
                        }
                        SqlCommand    cmd    = new SqlCommand(query, user.con);
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            MessageBox.Show("sign in successful", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ParentForm.Hide();
                            if (sqlTable == "Customer")
                            {
                                customerForm cf = new customerForm();
                                cf.Show();
                                customerUsername = usernametxt.Text;
                                //the customer's options goes here
                            }
                            else if (sqlTable == "Driver")
                            {
                                DriverUsername = usernametxt.Text;
                                driverForm df = new driverForm();
                                df.Show();

                                //the driver's options goes here
                            }
                            else if (sqlTable == "Cooks")
                            {
                                CookForm cf = new CookForm();
                                cf.Show();
                            }

                            else if (sqlTable == "Checker")
                            {
                                //Checker's options goes here
                                checker_username = usernametxt.Text;
                                checker_form ch = new checker_form();
                                ch.Show();
                            }
                            else if (sqlTable == "Admin")
                            {
                                //admin's options goes here
                                Admin_form af = new Admin_form();
                                af.Show();
                            }
                        }
                        else
                        {
                            MessageBox.Show("please enter username and password again", "username or password incorrect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Can not open connection to database", "Database connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.ToString(), "Data connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    user.con.Close();
                }
            }
        }