示例#1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string   username = txtusersname.Text;
            string   password = txtpass.Text;
            string   name     = txtname.Text;
            DateTime DOB      = dtpDOB.Value;
            string   position = cbbPosition.Text;
            string   gender   = cbbGender.Text;

            if (username != "" && password != "" && name != "" && DOB != null && position != "" && gender != "")
            {
                //check duppicated
                SqlConnection cnn  = new SqlConnection(cnn_str);
                SqlCommand    cmd1 = new SqlCommand();
                cmd1.Connection  = cnn;
                cmd1.CommandText = "Check_Staff";
                cmd1.CommandType = CommandType.StoredProcedure;
                SqlParameter pa = new SqlParameter("@username", username);
                cmd1.Parameters.Add(pa);
                da = new SqlDataAdapter();
                da.SelectCommand = cmd1;
                da.Fill(ds, "tblStaff");
                //save to Database
                if (ds.Tables["tblStaff"].Rows.Count <= 0)
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection  = cnn;
                    cmd.CommandText = "Sign_up";
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter pa1 = new SqlParameter("@username", username);
                    SqlParameter pa2 = new SqlParameter("@password", password);
                    SqlParameter pa3 = new SqlParameter("@name", name);
                    SqlParameter pa4 = new SqlParameter("@DOB", DOB);
                    SqlParameter pa5 = new SqlParameter("@position", position);
                    SqlParameter pa6 = new SqlParameter("@gender", gender);
                    cmd.Parameters.Add(pa1);
                    cmd.Parameters.Add(pa2);
                    cmd.Parameters.Add(pa3);
                    cmd.Parameters.Add(pa4);
                    cmd.Parameters.Add(pa5);
                    cmd.Parameters.Add(pa6);
                    da.SelectCommand = cmd;
                    SqlCommandBuilder sql = new SqlCommandBuilder();
                    da.Update(ds, "tblStaff");
                    da.Fill(ds, "tblStaff");
                    MessageBox.Show("Tạo tài khoản thành công");
                    this.Hide();
                    Staff_Management staff_Management = new Staff_Management();
                    staff_Management.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Username này đã tồn tại!");
                }
            }
            else
            {
                MessageBox.Show("Bạn chưa nhập đủ thông tin");
            }
        }
示例#2
0
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Hide();
            Staff_Management staff_Management = new Staff_Management();

            staff_Management.ShowDialog();
        }
示例#3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string   username = txtUsername.Text;
            string   name     = txtName.Text;
            DateTime DOB      = dtpDOB.Value;
            string   position = cbbPosition.Text;
            string   gender   = cbbGender.Text;

            if (username != "")
            {
                SqlConnection cnn  = new SqlConnection(cnn_str);
                SqlCommand    cmd1 = new SqlCommand();
                cmd1.Connection  = cnn;
                cmd1.CommandText = "Check_Staff";
                cmd1.CommandType = CommandType.StoredProcedure;
                SqlParameter pa = new SqlParameter("@username", username);
                cmd1.Parameters.Add(pa);
                da = new SqlDataAdapter();
                da.SelectCommand = cmd1;
                da.Fill(ds, "tblStaff_Update");
                if (ds.Tables["tblStaff_Update"].Rows.Count > 0)
                {
                    string     sql = "DELETE FROM Staff WHERE Username = @username";
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection  = cnn;
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.Text;
                    SqlParameter pa1 = new SqlParameter("@username", username);
                    cmd.Parameters.Add(pa1);
                    da.SelectCommand = cmd;
                    SqlCommandBuilder sqls = new SqlCommandBuilder();
                    da.Update(ds, "tblStaff_Update");
                    da.Fill(ds, "tblStaff_Update");
                    MessageBox.Show("Xóa thành công");
                    this.Hide();
                    Staff_Management staff_Management = new Staff_Management();
                    staff_Management.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Username này không tồn tại");
                }
            }
            else
            {
                MessageBox.Show("Chưa nhập Username");
            }
        }
示例#4
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            string userName = txtUsername.Text;
            string passWord = txtPass.Text;
            string newPass  = txtNewPass.Text;

            if (userName != "" && passWord != "" && newPass != "" && passWord != newPass)
            {
                SqlConnection cnn = new SqlConnection(cnn_str);
                SqlCommand    cmd = new SqlCommand();
                cmd.Connection  = cnn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Logins";
                SqlParameter pa  = new SqlParameter("@username", userName);
                SqlParameter pa2 = new SqlParameter("@password", passWord);
                cmd.Parameters.Add(pa);
                cmd.Parameters.Add(pa2);
                da = new SqlDataAdapter(cmd);
                da.Fill(ds, "tblUsername");
                if (ds.Tables["tblUsername"].Rows.Count > 0)
                {
                    string     sql  = "UPDATE Staff SET Passwords = @newpass WHERE Username = @username";
                    SqlCommand cmd1 = new SqlCommand();
                    cmd1.Connection  = cnn;
                    cmd1.CommandText = sql;
                    cmd1.CommandType = CommandType.Text;
                    SqlParameter pa1 = new SqlParameter("@newpass", newPass);
                    SqlParameter pa3 = new SqlParameter("@username", userName);
                    cmd1.Parameters.Add(pa1);
                    cmd1.Parameters.Add(pa3);
                    da.SelectCommand = cmd1;
                    SqlCommandBuilder sqls = new SqlCommandBuilder();
                    da.Update(ds, "tblUsername");
                    da.Fill(ds, "tblUsername");
                    MessageBox.Show("Thay đổi thành công");
                    this.Hide();
                    Staff_Management staff_Management = new Staff_Management();
                    staff_Management.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Tài khoản và mật khẩu này không tồn tại");
                }
            }
        }