private void frmTextNhanVien_Load(object sender, EventArgs e) { lbTieuDe.Text = Lb_TitleName; //Load Dữ Liệu Thêm Nhân Viên if (KieuForm == 1) { txtHo.Text = "Nguyễn Quang"; txtTen.Text = "Hải"; txtEmail.Text = "*****@*****.**"; txtMatKhau.Text = "123"; txtNhapLai.Text = "123"; cbx_CaLamViec.SelectedIndex = 0; cbx_ChucVu.SelectedIndex = 0; cbx_GioiTinh.SelectedIndex = 0; } //Load Dữ Liệu Nhân Viên Cần Sửa if (KieuForm == 2) { NhanVien_WCFClient nv_wcf = new NhanVien_WCFClient(); NhanVien_Ent nv_ent = nv_wcf.GetNhanVien_by_ID(Id_NhanVien); txtHo.Text = nv_ent.Ho.Trim(); txtTen.Text = nv_ent.Ten.Trim(); txtEmail.Text = nv_ent.Email.Trim(); cbx_GioiTinh.Text = nv_ent.GioiTinh; cbx_ChucVu.Text = nv_ent.ChucVu; cbx_CaLamViec.Text = nv_ent.CaLamViec; dtp_NgaySinh.Value = nv_ent.NgaySinh; old_email = txtEmail.Text.Trim(); } }
public List <NhanVien_Ent> SapXepCaLamViec(int caLamViec) { List <NhanVien_Ent> nv_ents = new List <NhanVien_Ent>(); IQueryable nhanViens = db.NhanViens.Where(n => n.ca_lam_viec == caLamViec); if (nhanViens != null) { foreach (NhanVien nv in nhanViens) { NhanVien_Ent nv_ent = new NhanVien_Ent(); nv_ent.Id_nhanvien = nv.id_NhanVien; nv_ent.Ho = nv.ho.Trim(); nv_ent.Ten = nv.ten.Trim(); //Get Gioi Tinh if (nv.gioi_tinh == 0) { nv_ent.GioiTinh = "Nữ"; } else { nv_ent.GioiTinh = "Nam"; } nv_ent.NgaySinh = (DateTime)nv.ngay_sinh; //Get Chuc Vu if (nv.chuc_vu == 1) { nv_ent.ChucVu = "Quản Lý"; } else { nv_ent.ChucVu = "Nhân Viên"; } //Get Ca Lam Viec if (nv.ca_lam_viec == 1) { nv_ent.CaLamViec = "Sáng"; } if (nv.ca_lam_viec == 2) { nv_ent.CaLamViec = "Chiều"; } if (nv.ca_lam_viec == 3) { nv_ent.CaLamViec = "Tối"; } nv_ent.Email = nv.email.Trim(); nv_ents.Add(nv_ent); } } return(nv_ents); }
public bool CapNhatNhanVien(NhanVien_Ent nv_ent, string old_email) { NhanVien nv = db.NhanViens.Where(n => n.email.Equals(old_email)).SingleOrDefault(); if (nv == null) { return(false); } try { nv.ho = nv_ent.Ho; nv.ten = nv_ent.Ten; if (nv_ent.GioiTinh == "nam") { nv.gioi_tinh = 1; } if (nv_ent.GioiTinh == "nu") { nv.gioi_tinh = 0; } nv.ngay_sinh = nv_ent.NgaySinh; if (nv_ent.ChucVu == "nhanvien") { nv.chuc_vu = 2; } if (nv_ent.ChucVu == "quanly") { nv.chuc_vu = 1; } if (nv_ent.CaLamViec == "sang") { nv.ca_lam_viec = 1; } if (nv_ent.CaLamViec == "chieu") { nv.ca_lam_viec = 2; } if (nv_ent.CaLamViec == "toi") { nv.ca_lam_viec = 3; } nv.email = nv_ent.Email; db.SubmitChanges(); } catch (Exception) { return(false); } return(true); }
public List <NhanVien_Ent> GetNhanViens() { List <NhanVien_Ent> nv_ents = new List <NhanVien_Ent>(); foreach (NhanVien nv in db.NhanViens.Select(n => n)) { NhanVien_Ent nv_ent = new NhanVien_Ent(); nv_ent.Id_nhanvien = nv.id_NhanVien; nv_ent.Ho = nv.ho.Trim(); nv_ent.Ten = nv.ten.Trim(); //Get Gioi Tinh if (nv.gioi_tinh == 0) { nv_ent.GioiTinh = "Nữ"; } else { nv_ent.GioiTinh = "Nam"; } nv_ent.NgaySinh = (DateTime)nv.ngay_sinh; //Get Chuc Vu if (nv.chuc_vu == 1) { nv_ent.ChucVu = "Quản Lý"; } else { nv_ent.ChucVu = "Nhân Viên"; } //Get Ca Lam Viec if (nv.ca_lam_viec == 1) { nv_ent.CaLamViec = "Sáng"; } if (nv.ca_lam_viec == 2) { nv_ent.CaLamViec = "Chiều"; } if (nv.ca_lam_viec == 3) { nv_ent.CaLamViec = "Tối"; } nv_ent.Email = nv.email.Trim(); nv_ents.Add(nv_ent); } return(nv_ents); }
//Lấy Thông Tin Nhân Viên theo ID public NhanVien_Ent GetNhanVien_by_ID(int id) { NhanVien_Ent nv_ent = new NhanVien_Ent(); NhanVien nv = db.NhanViens.Where(n => n.id_NhanVien == id).SingleOrDefault(); if (nv != null) { nv_ent.Id_nhanvien = id; nv_ent.Ho = nv.ho.Trim(); nv_ent.Ten = nv.ten.Trim(); //Get Gioi Tinh if (nv.gioi_tinh == 0) { nv_ent.GioiTinh = "Nữ"; } else { nv_ent.GioiTinh = "Nam"; } nv_ent.NgaySinh = (DateTime)nv.ngay_sinh; //Get Chuc Vu if (nv.chuc_vu == 1) { nv_ent.ChucVu = "Quản Lý"; } else { nv_ent.ChucVu = "Nhân Viên"; } //Get Ca Lam Viec if (nv.ca_lam_viec == 1) { nv_ent.CaLamViec = "Sáng"; } if (nv.ca_lam_viec == 2) { nv_ent.CaLamViec = "Chiều"; } if (nv.ca_lam_viec == 3) { nv_ent.CaLamViec = "Tối"; } nv_ent.Email = nv.email.Trim(); } return(nv_ent); }
public bool ThemNhanVien(NhanVien_Ent nv_ent, string matKhau) { NhanVien nv; NhanVien NVTestEmail = db.NhanViens.Where(n => n.email.Equals(nv_ent.Email)).SingleOrDefault(); if (NVTestEmail != null) { return(false); } try { nv = new NhanVien(); nv.ho = nv_ent.Ho; nv.ten = nv_ent.Ten; if (nv_ent.GioiTinh == "nam") { nv.gioi_tinh = 1; } if (nv_ent.GioiTinh == "nu") { nv.gioi_tinh = 0; } nv.ngay_sinh = nv_ent.NgaySinh; if (nv_ent.ChucVu == "nhanvien") { nv.chuc_vu = 2; } if (nv_ent.ChucVu == "quanly") { nv.chuc_vu = 1; } if (nv_ent.CaLamViec == "sang") { nv.ca_lam_viec = 1; } if (nv_ent.CaLamViec == "chieu") { nv.ca_lam_viec = 2; } if (nv_ent.CaLamViec == "toi") { nv.ca_lam_viec = 3; } nv.email = nv_ent.Email; nv.mat_khau = matKhau; db.NhanViens.InsertOnSubmit(nv); db.SubmitChanges(); } catch (Exception) { return(false); } return(true); }
private void Luu_Sua() { if (!CheckNull()) { MessageBox.Show("Chưa Nhập Đủ Thông Tin", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } NhanVien_WCFClient nv_wcf = new NhanVien_WCFClient(); NhanVien_Ent nv_ent = new NhanVien_Ent(); nv_ent.Ho = txtHo.Text.Trim(); nv_ent.Ten = txtTen.Text.Trim(); //Nam if (cbx_GioiTinh.SelectedIndex == 0) { nv_ent.GioiTinh = "nam"; } //Nữ if (cbx_GioiTinh.SelectedIndex == 1) { nv_ent.GioiTinh = "nu"; } nv_ent.NgaySinh = dtp_NgaySinh.Value; //Quản Lý if (cbx_ChucVu.SelectedIndex == 0) { nv_ent.ChucVu = "quanly"; } //Nhân Viên if (cbx_ChucVu.SelectedIndex == 1) { nv_ent.ChucVu = "nhanvien"; } //Sáng if (cbx_CaLamViec.SelectedIndex == 0) { nv_ent.CaLamViec = "sang"; } //Chiều if (cbx_CaLamViec.SelectedIndex == 1) { nv_ent.CaLamViec = "chieu"; } //Tối if (cbx_CaLamViec.SelectedIndex == 2) { nv_ent.CaLamViec = "toi"; } nv_ent.Email = txtEmail.Text.Trim(); //Xử Lý Update if (nv_wcf.CapNhatNhanVien(nv_ent, old_email)) { DialogResult ds = MessageBox.Show("Lưu Thành Công, Tiếp Tục ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ds == DialogResult.Yes) { return; } else { this.Close(); } } else { DialogResult ds = MessageBox.Show("Lưu Thất Bại, Thử Lại ?", "LỖI", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (ds == DialogResult.Yes) { return; } else { this.Close(); } } }
private void Luu_Them() { if (!CheckNull()) { MessageBox.Show("Chưa Nhập Đủ Thông Tin", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!txtMatKhau.Text.Trim().Equals(txtNhapLai.Text.Trim())) { MessageBox.Show("Mật Khẩu Không Giống Nhau", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } NhanVien_WCFClient nv_wcf = new NhanVien_WCFClient(); NhanVien_Ent nv_ent = new NhanVien_Ent(); nv_ent.Ho = txtHo.Text.Trim(); nv_ent.Ten = txtTen.Text.Trim(); if (cbx_GioiTinh.SelectedIndex == 0) { nv_ent.GioiTinh = "nam"; } if (cbx_GioiTinh.SelectedIndex == 1) { nv_ent.GioiTinh = "nu"; } nv_ent.NgaySinh = dtp_NgaySinh.Value; if (cbx_ChucVu.SelectedIndex == 0) { nv_ent.ChucVu = "quanly"; } if (cbx_ChucVu.SelectedIndex == 1) { nv_ent.ChucVu = "nhanvien"; } if (cbx_CaLamViec.SelectedIndex == 0) { nv_ent.CaLamViec = "sang"; } if (cbx_CaLamViec.SelectedIndex == 1) { nv_ent.CaLamViec = "chieu"; } if (cbx_CaLamViec.SelectedIndex == 2) { nv_ent.CaLamViec = "toi"; } nv_ent.Email = txtEmail.Text.Trim(); string matKhau = maHoaMatKhau(txtNhapLai.Text.Trim()); if (nv_wcf.ThemNhanVien(nv_ent, matKhau)) { DialogResult ds = MessageBox.Show("Lưu Thành Công, Tiếp Tục ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ds == DialogResult.Yes) { Clear_TextBox(); return; } else { this.Close(); } } else { DialogResult ds = MessageBox.Show("Lưu Thất Bại, Thử Lại ?", "LỖI", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (ds == DialogResult.Yes) { return; } else { this.Close(); } } }