private void btnOut_Click(object sender, EventArgs e)
        {
            this.Hide();
            Frm_SignIn sin = new Frm_SignIn();

            sin.Show();
        }
示例#2
0
        // btn Sign Up
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            Frm_SignIn login = new Frm_SignIn();

            login.Show();
            this.Hide();
        }
        //--------------------------------------------------------------------------------
        // btn Out
        private void btnOut_Click(object sender, EventArgs e)
        {
            Frm_SignIn sin = new Frm_SignIn();

            sin.Show();
            this.Hide();
            Visible = false;
        }
 // btn ĐÓNG
 private void btnDong_Click(object sender, EventArgs e)
 {
     DialogResult = MessageBox.Show(" Do you want to Sign In?", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (DialogResult == DialogResult.No)
     {
         this.Close();
     }
     else
     {
         this.Hide();
         Frm_SignIn sin = new Frm_SignIn();
         sin.Show();
     }
 }
        public void Del()
        {
            lbXuatTenDangNhap.Text = string.Empty;
            string ma = txtTimKiem.Text;

            //try
            //{
            CloseConnect();
            OpenConnect();
            // Xóa trong SQL
            string        sql = "DELETE FROM [KTPM].[dbo].[Info_Emp] WHERE ID_Emp= '" + ma + "';";
            SqlCommand    cmd = new SqlCommand(sql, sqlcon);
            SqlDataReader myReader;
            string        sql_detail = "DELETE FROM [KTPM].[dbo].[Info_Secret] WHERE ID_Emp= '" + ma + "';";
            SqlCommand    cmd_detail = new SqlCommand(sql_detail, sqlcon);
            SqlDataReader myReader_detail;

            string     sqlMa     = "SELECT COUNT (*) FROM [KTPM].[dbo].[Info_Emp] WHERE ID_Emp= '" + ma + "';";
            SqlCommand cmdMa     = new SqlCommand(sqlMa, sqlcon);
            int        x         = (int)cmdMa.ExecuteScalar(); // Tồn tại mã NV trong Bảng Info_Emp
            string     sqlorder  = "SELECT COUNT (*) FROM [KTPM].[dbo].[Orders] WHERE ID_Emp= '" + ma + "';";
            SqlCommand cmdorder  = new SqlCommand(sqlorder, sqlcon);
            int        y         = (int)cmdorder.ExecuteScalar(); // Tồn tại mã NV trong bảng Orders
            string     secret    = "SELECT COUNT (*) FROM [KTPM].[dbo].[Orders] WHERE ID_Emp= '" + ma + "';";
            SqlCommand cmdsecret = new SqlCommand(secret, sqlcon);
            int        z         = (int)cmdsecret.ExecuteScalar(); // Tồn tại mã NV trong bảng Info_Secret

            if (x == 1)
            {
                if (y == 1)
                {
                    if (z == 1)
                    {
                        //if (listView1.Items.Count <= 0)
                        //	return;
                        //for (int i = 0; i < listView1.Items.Count; i++)
                        //{
                        //	if (txtTimKiem.Text == listView1.Items[i].SubItems[0].Text)
                        //		MessageBox.Show("You can not delete yourself", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //	else
                        //		MessageBox.Show("This employee have already exist in Database \n Can not delete information !", "SORRY", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        //}
                        if (txtTimKiem.Text == label14.Text)
                        {
                            DelFlag = true;
                            MessageBox.Show("You can not delete yourself", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        else
                        {
                            DelFlag = true;
                            MessageBox.Show("This employee have already exist in Database \n Can not delete information !", "SORRY", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else // không tồn tại mã NV trong bảng Secret thì không cho xóa và yêu cầu đăng ký tài khoản
                    {
                        DelFlag = true;
                        MessageBox.Show("You have no permission \n Please sign up to countinue ! ", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        Frm_SignIn sin = new Frm_SignIn();
                        sin.Show();
                        this.Hide();
                    }
                }
                else // nếu mã NV không tồn tại trong bảng Orders
                {
                    if (z == 1) // tồn tại trong bảng Secret thì XÓA sạch tại bảng Emp và Secret
                    {
                        foreach (ListViewItem item in listView1.SelectedItems)
                        {
                            listView1.Items.Remove(item);
                            myReader = cmd.ExecuteReader();
                            while (myReader.Read())
                            {
                            }
                            myReader_detail = cmd_detail.ExecuteReader();
                            while (myReader_detail.Read())
                            {
                            }
                            lbXuatTenDangNhap.Text = " DELETE SUCCESSFUL " + ma;
                            ma = string.Empty;
                        }
                    }
                    else // XÓA sạch tại bảng Emp
                    {
                        foreach (ListViewItem item in listView1.SelectedItems)
                        {
                            listView1.Items.Remove(item);
                            myReader = cmd.ExecuteReader();
                            while (myReader.Read())
                            {
                            }
                            lbXuatTenDangNhap.Text = " DELETE SUCCESSFUL " + ma;
                            ma = string.Empty;
                        }
                    }
                }
            }
            else // không tồn tại mã NV trong bảng NV
            {
                DelFlag = false;
                MessageBox.Show(" This ID does not exist! \n Please try again", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            //}
            //catch (Exception)
            //{
            //	lbXuatTenDangNhap.Text = " DELETE " + ma + " FAIL ! ";
            //}
            //finally
            //{
            //	CloseConnect();
            //}
        }