Esempio n. 1
0
        public static bool Delete(AccountCL b)
        {
            try
            {

                SqlCommand cmd = new SqlCommand("Delete Accounts where EmployeeID = @empID", cn);
                cmd.Parameters.AddWithValue("@empID", b.EmployeeID);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Esempio n. 2
0
        public static bool Insert(AccountCL b)
        {
            try
            {

                SqlCommand cmd = new SqlCommand("Insert into Accounts(Username, Password, EmployeeID) " +
                "values(@user, @pass, @empID)", cn);
                cmd.Parameters.AddWithValue("@user", b.Username);
                cmd.Parameters.AddWithValue("@pass", b.Password);
                cmd.Parameters.AddWithValue("@empID", b.EmployeeID);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Esempio n. 3
0
        private void button9_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please enter value for Lastname!");
                return;
            }

            if (textBox2.Text == "")
            {
                MessageBox.Show("Please enter value for Firstname!");
                return;
            }

            if (comboBox1.SelectedIndex < 0)
            {
                MessageBox.Show("Please select value for Rank!");
                return;
            }

            if (textBox6.Text == "")
            {
                MessageBox.Show("Please enter value for Account Name!");
                return;
            }

            if (textBox6.Text.Length > 50)
            {
                MessageBox.Show("Account Name too long!");
                return;
            }

            if (textBox7.Text == "")
            {
                MessageBox.Show("Please enter value for Password!");
                return;
            }

            if (textBox7.Text.Length > 30)
            {
                MessageBox.Show("Password too long!");
                return;
            }

            string last = textBox1.Text;
            string first = textBox2.Text;
            string phone = textBox3.Text;
            string add = textBox4.Text;
            string tit = comboBox1.SelectedItem.ToString();

            EmployeeCL em = new EmployeeCL(last, first, phone, add, tit);
            string user = textBox6.Text;
            string pass = textBox7.Text;

            bool check = AccountDA.checkAcc(user);
            if (check == true)
            {
                MessageBox.Show("Username is existed. Please try other Username!");
                return;
            }

            if (comboBox1.SelectedIndex == 1)
            {
                DialogResult result1 = MessageBox.Show("Are you sure to create new adminitrator??", "Confirm", MessageBoxButtons.YesNo);
                if (result1 == DialogResult.Yes)
                {
                    EmployeeDA.Insert(em);
                    int empID = SelectDA.GetMax("EmployeeID", "Employees");
                    AccountCL ac = new AccountCL(user, pass, empID);
                    AccountDA.Insert(ac);
                }
                else { }
            }
            else
            {
                DialogResult result2 = MessageBox.Show("Are you sure to create new employee??", "Confirm", MessageBoxButtons.YesNo);
                if (result2 == DialogResult.Yes)
                {
                    EmployeeDA.Insert(em);
                    int empID = SelectDA.GetMax("EmployeeID", "Employees");
                    AccountCL ac = new AccountCL(user, pass, empID);
                    AccountDA.Insert(ac);
                }
                else { }
            }
            InitializeMemberData();
        }
Esempio n. 4
0
        private void button3_Click(object sender, EventArgs e)
        {
            dataGridView1.Enabled = true;

            if (!isSelected())
            {
                MessageBox.Show("Please select a employee to delete!");
                return;
            }

            EmployeeCL emp = new EmployeeCL();
            emp.EmployeeID = int.Parse(dataGridView1.SelectedRows[0].Cells["EmployeeID"].Value.ToString());

            AccountCL acc = new AccountCL();
            acc.EmployeeID = emp.EmployeeID;
            DialogResult result = MessageBox.Show("Do you really want to delete this employee and its account!", "Confirm", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                DeleteDA.DeleteAllEmp(acc.EmployeeID);
                DeleteDA.DeleteChung(acc.EmployeeID, "EmployeeID", "Orders");
                AccountDA.Delete(acc);
                EmployeeDA.Delete(emp);
            }
            else { }
            InitializeMemberData();
        }