public bool Insert_Staff(System_DTO account, Staff_DTO staff) { string query = "exec USP_AddStaff @username , @password , @role , @displayname , @sex , @birthday , @address , @phone , @email , @image"; int x = (int)Connect.Instance.ExecuteOutPut(query, new object[] { account.Username, account.Password, account.Id_type, staff.Name, staff.Sex, staff.Birthday, staff.Address, staff.Phone, staff.Email, staff.Image }); return(x == 2); }
private void fProfile_Load(object sender, EventArgs e) { txt_username.Text = this.Username; Staff_DTO staff_info = Staff_DAO.Instance.Get_Info(this.Username); txt_name.Text = staff_info.Name; txt_address.Text = staff_info.Address; txt_email.Text = staff_info.Email; this.email_old = staff_info.Email; txt_phone.Text = staff_info.Phone; if (staff_info.Sex == true) { cb_sex.SelectedItem = "Men"; } else { cb_sex.SelectedItem = "Woman"; } dtp_birthday.Value = staff_info.Birthday; if (staff_info.Image != null && staff_info.Image.Length > 0) { this.image_byte = staff_info.Image; MemoryStream stream = new MemoryStream(staff_info.Image); pib_profile.Image = Image.FromStream(stream); } }
//@Description: // Chỉnh sửa thông tin cá nhân của nhân viên //@Prameter: // Staff_DTO staff ---------------- Nhận vào 1 thông tin của nhân viên cần sửa. //@Proc: // exec USP_EditStaff @username , @displayname , @sex , @birthday , @address , @phone , @email , @image //@Return: // Boolean ----------- Trả về thành công hay thất bại public bool Edit_Info_Staff(Staff_DTO staff) { string query = "exec USP_EditStaff @username , @displayname , @sex , @birthday , @address , @phone , @email , @image"; // #record trả về số lượng dòng đã được update hay insert. int record = Connect.Instance.ExecuteNonQuery(query, new object[] { staff.Username, staff.Name, staff.Sex, staff.Birthday, staff.Address, staff.Phone, staff.Email, staff.Image }); return(record == 1); }
private void fShow_profile_Load(object sender, EventArgs e) { if (this.username == null) { MessageBox.Show("Erorr! Not receive"); this.Hide(); } else { Staff_DTO staff_info = Staff_BUS.Instance.Get_Info(this.username); lb_name.Text = staff_info.Name; txt_name.Text = staff_info.Name; if (staff_info.Sex == true) { cb_sex.SelectedIndex = 1; } else { cb_sex.SelectedIndex = 0; } dtp_birthday.Value = staff_info.Birthday; txt_address.Text = staff_info.Address; txt_phone.Text = staff_info.Phone; txt_mail.Text = staff_info.Email; MemoryStream stream = new MemoryStream(staff_info.Image); ptb_avatar.Image = Image.FromStream(stream); if (this.Type == 1) { txt_name.Enabled = true; } if (this.Type == 2) { txt_name.Enabled = false; cb_sex.Enabled = false; dtp_birthday.Enabled = false; txt_address.Enabled = false; txt_phone.Enabled = false; txt_mail.Enabled = false; btn_upload.Enabled = false; btn_ok.Hide(); } } lb_reservation.Text = BUS.Analytic_BUS.Instance.CountReservationByStaff(this.username).ToString() + " Reservation"; lb_room.Text = BUS.Analytic_BUS.Instance.CountRoomOfStaff(this.username).ToString() + " Room"; lb_checkout.Text = BUS.Analytic_BUS.Instance.CountCheckOutByStaff(this.username).ToString() + " Checkout"; if (BUS.System_BUS.Instance.Get_Account(this.username).Ban_account == false) { lb_rank.Text = "Good"; } else { lb_rank.Text = "Ban Account"; } }
public bool Edit_Info_Staff(Staff_DTO staff) { try { return(Staff_DAO.Instance.Edit_Info_Staff(staff)); } catch { throw new Exception("Error!"); } }
public List <Staff_DTO> GetListStaffSearch(string keyword) { string query = "exec USP_SearchStaff @keyword"; DataTable List_staff = Connect.Instance.ExecuteQuery(query, new object[] { keyword }); List <Staff_DTO> list_staff = new List <Staff_DTO>(); foreach (DataRow item in List_staff.Rows) { Staff_DTO staff = new Staff_DTO(item); list_staff.Add(staff); } return(list_staff); }
public bool Insert_Staff(System_DTO account, Staff_DTO staff) { try { MD5 md5 = MD5.Create(); string password_md5 = Function_Other.Instance.GetMd5Hash(md5, account.Password); account.Password = password_md5; return(Staff_DAO.Instance.Insert_Staff(account, staff)); } catch (System.Data.SqlClient.SqlException e) { throw new Exception("Error!"); } }
//@Description: // Lấy ra danh sách nhân viên trong hệ thống //@Prameter: // nope //@Proc: // exec USP_GetListStaff //@Return: // List<Staff_DTO> ----------- Trả về danh sách nhân viên public List <Staff_DTO> List_Staff() { string query = "exec USP_GetListStaff"; DataTable List_staff = Connect.Instance.ExecuteQuery(query); List <Staff_DTO> list_staff = new List <Staff_DTO>(); foreach (DataRow item in List_staff.Rows) { Staff_DTO staff = new Staff_DTO(item); list_staff.Add(staff); } return(list_staff); }
private void btnEdit_Click(object sender, EventArgs e) { Staff_DTO staff = new Staff_DTO( idStaff.Text.ToString(), fName.Text.ToString(), lName.Text.ToString(), birthday.Text.ToString(), sex.Text.ToString(), placeOfBirth.Text.ToString(), address.Text.ToString(), iNumber.Text.ToString(), email.Text.ToString(), position.Text.ToString(), pNumber.Text.ToString()); Staff_BUS.EditStaff(staff); this.Close(); }
private void dgv_staff_CellClick(object sender, DataGridViewCellEventArgs e) { try { this.choose_username = dgv_staff.Rows[e.RowIndex].Cells[0].Value.ToString(); Staff_DTO staff = Staff_BUS.Instance.Get_Info(this.choose_username); MemoryStream stream = new MemoryStream(staff.Image); pictureBox1.Image = Image.FromStream(stream); lb_name.Text = staff.Name; lb_position.Text = Staff_BUS.Instance.Get_Role(this.choose_username); } catch (Exception ex) { MessageBox.Show("Selected Error!"); } }
//@Note: // Khi truy vấn query sẽ sử dụng 3 hàm sau: (Có thể xem chi tiết trong file "DTO/Staff_DTO.cs" ) // 1, Select sử dụng ExecuteQuery // 2, Insert, Update, Delete sử dụng ExecuteNonQuery // 3, Đếm số lượng, tính giá trị max, min, giá trị trung bình cộng sử dụng ExecuteScalar //@Description: // Lấy ra danh sách nhân viên trong hệ thống //@Prameter: // nope //@Proc: // exec USP_GetProfile @username //@Return: // Staff_DTO ----------- Trả về thông tin của nhân viên public Staff_DTO Get_Info(string username) { // tạo chuỗi thực thi Strod Procdure string query = "exec USP_GetProfile @username"; //Đổ dữ liệu và 1 bảng có sẵn trong hệ thống tên là "DataTable" DataTable Staff_info = Connect.Instance.ExecuteQuery(query, new object[] { username }); Staff_DTO staff = null; // Đỗi tượng DataRow là từng dòng trong đối tượng DataTable // (Có thể bỏ vòng lặp này do số lượng dòng ta cấn truy xuất bằng 1 hoặc 0) foreach (DataRow item in Staff_info.Rows) { staff = new Staff_DTO(item); } return(staff); }
private void btnAdd_Click(object sender, EventArgs e) { string id = idStaff.Text; string firstname = fName.Text; string lastname = lName.Text; string birthday1 = birthday.Text; string sex1 = sex.Text; string pOB = placeOfBirth.Text; string add = address.Text; string identityNumber = iNumber.Text; string email1 = email.Text; string pos = position.Text; string phoneNumber = pNumber.Text; Staff_DTO staff = new Staff_DTO(id, firstname, lastname, birthday1, sex1, pOB, add, identityNumber, email1, pos, phoneNumber); Staff_BUS.AddStaff(staff); MessageBox.Show("Complete!", "Add staff", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Close(); }
//Add a staff public static void AddStaff(Staff_DTO staff) { SqlConnection connecter = sqlConnectionData.Connecter(); SqlCommand commander = new SqlCommand("AddStaff", connecter); commander.CommandType = CommandType.StoredProcedure; commander.Parameters.Add("@id", SqlDbType.Char, 10).Value = staff.IdStaff; commander.Parameters.Add("@firstname", SqlDbType.NVarChar, 100).Value = staff.FirstName; commander.Parameters.Add("@lastname", SqlDbType.NVarChar, 100).Value = staff.LastName; commander.Parameters.Add("@birthday", SqlDbType.Date).Value = staff.Birthday; commander.Parameters.Add("@sex", SqlDbType.NVarChar, 6).Value = staff.Sex; commander.Parameters.Add("@placeOfBirth", SqlDbType.NVarChar, 50).Value = staff.PlaceOfBirth; commander.Parameters.Add("@address1", SqlDbType.NVarChar, 100).Value = staff.Address; commander.Parameters.Add("@identityNumber", SqlDbType.Char, 20).Value = staff.IdentityNumber; commander.Parameters.Add("@email", SqlDbType.NVarChar, 100).Value = staff.Email; commander.Parameters.Add("@position", SqlDbType.NVarChar, 50).Value = staff.Position; commander.Parameters.Add("@phoneNumber", SqlDbType.NVarChar, 20).Value = staff.PhoneNumber; connecter.Open(); commander.ExecuteNonQuery(); connecter.Close(); }
//Edit info staff public static void EditStaff(Staff_DTO staff) { Staff_DAO.EditStaff(staff); }
//Add a staff public static void AddStaff(Staff_DTO staff) { Staff_DAO.AddStaff(staff); }
private void btn_add_Click(object sender, EventArgs e) { bool flat = true; if (txt_password.Text == "" || cb_role.SelectedIndex == -1 || txt_name.Text == "" || txt_phone.Text == "" || txt_address.Text == "" || txt_email.Text == "" || cb_sex.SelectedIndex == -1) { MessageBox.Show("Error!"); flat = false; return; } try { var addr = new System.Net.Mail.MailAddress(txt_email.Text); flat = true; } catch { MessageBox.Show("Email is not exists", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_phone.Text.Length != 11 && txt_phone.Text.Length != 10) { MessageBox.Show("Phone is not exist!", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } System_DTO account = new System_DTO(); account.Username = txt_username.Text; account.Password = txt_password.Text; account.Id_type = cb_role.SelectedIndex; Staff_DTO staff = new Staff_DTO(); staff.Username = txt_username.Text; staff.Name = txt_name.Text; if (cb_sex.SelectedIndex == 1) { staff.Sex = true; } else { staff.Sex = false; } staff.Birthday = dtp_birthday.Value; staff.Address = txt_address.Text; staff.Phone = txt_phone.Text; staff.Email = txt_email.Text; if (this.filename != null) { staff.Image = this.CovertImage(); } else { MessageBox.Show("You must upload image!"); return; } if (Staff_BUS.Instance.Check_Email(txt_email.Text) == false) { if (Staff_BUS.Instance.Insert_Staff(account, staff)) { MessageBox.Show("Add satff is success!"); this.Close(); } else { MessageBox.Show("Error!"); } } else { MessageBox.Show("Email was exists in system!"); return; } }
private void btn_edit_Click(object sender, EventArgs e) { Staff_DTO staff = new Staff_DTO(); staff.Username = txt_username.Text; staff.Name = txt_name.Text; if (cb_sex.SelectedIndex == 1) { staff.Sex = true; } else { staff.Sex = false; } staff.Birthday = dtp_birthday.Value; staff.Address = txt_address.Text; staff.Phone = txt_phone.Text; staff.Email = txt_email.Text; if (this.filename != null) { staff.Image = this.CovertImage(); } else { staff.Image = this.image_byte; } bool flat = true; if (txt_name.Text == "" || txt_phone.Text == "" || txt_address.Text == "" || txt_email.Text == "" || cb_sex.SelectedIndex == -1) { MessageBox.Show("Error!", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } try { var addr = new System.Net.Mail.MailAddress(txt_email.Text); flat = true; } catch { MessageBox.Show("Email is not exists", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_phone.Text.Length != 11 && txt_phone.Text.Length != 10) { MessageBox.Show("Phone is not exist!", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } double parsedValue1; if (!double.TryParse(txt_phone.Text, out parsedValue1)) { MessageBox.Show("Phone is number only field", "Error validate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); flat = false; return; } if (txt_email.Text == this.email_old) { if (Staff_BUS.Instance.Edit_Info_Staff(staff)) { MessageBox.Show("Edit satff is success!"); this.Close(); } else { MessageBox.Show("Error!"); } } else { if (Staff_BUS.Instance.Check_Email(txt_email.Text) == false) { if (Staff_BUS.Instance.Edit_Info_Staff(staff)) { MessageBox.Show("Edit satff is success!"); } else { MessageBox.Show("Error!"); } } else { MessageBox.Show("Email was exists in system!"); return; } } }