public bool Insert(DTO.NhanVienDTO data) { string query = string.Format("EXEC dbo.INSERT_NHANVIEN '{0}', N'{1}', N'{2}', '{3}',{4}, N'{5}', '{6}', '{7}', N'{8}', '{9}'", data.MaNhanVien, data.HoNV, data.TenNV, data.NgaySinh, data.GioiTinh, data.DiaChi, data.DienThoai, data.Cmnd, data.QueQuan, data.NgayVaoLam); int result = DataProvider.Instance.ExecuteNonQuery(query); return(result > 0); }
public bool InsertData(DTO.NhanVienDTO nhanVien) { string query = string.Format("EXEC dbo.INSERT_NHANVIEN @USERNAME = '******', @MANV = '{1}', @HONV = N'{2}', @TENNV = N'{3}', @NGAYSINH = '{4}', @GIOITINH = {5},@DIENTHOAI = '{6}',@CMND = '{7}',@NGAYVAOLAM = '{8}'", nhanVien.UserName, nhanVien.MaNV, nhanVien.HoNV, nhanVien.TenNV, nhanVien.NgaySinh, nhanVien.GioiTinh, nhanVien.DienThoai, nhanVien.CmndNV, nhanVien.NgayVaoLam); int result = DataProvider.Instance.ExecuteNonQuery(query); return(result > 0); }
public void DTO2DB(DTO.NhanVienDTO dtoItem, ref NhanVien dbItem, int userId) { string TmpFile = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; // remark if (dtoItem.PhotoHasChanged) { dtoItem.Photo = fwFactory.CreateFilePointer(TmpFile, dtoItem.NewPhoto, dtoItem.Photo); } AutoMapper.Mapper.Map <DTO.NhanVienDTO, NhanVien>(dtoItem, dbItem); // remark image foreach (NguoiPhuThuoc dbNPT in dbItem.NguoiPhuThuoc.ToArray()) { if (!dtoItem.NguoiPhuThuocDTOs.Select(o => o.NguoiPhuThuocID).Contains(dbNPT.NguoiPhuThuocID)) { dbItem.NguoiPhuThuoc.Remove(dbNPT); } } foreach (DTO.NguoiPhuThuocDTO dtoNPT in dtoItem.NguoiPhuThuocDTOs) { NguoiPhuThuoc dbNPT; if (dtoNPT.NguoiPhuThuocID <= 0) { dbNPT = new NguoiPhuThuoc(); dbItem.NguoiPhuThuoc.Add(dbNPT); } else { dbNPT = dbItem.NguoiPhuThuoc.FirstOrDefault(o => o.NguoiPhuThuocID == dtoNPT.NguoiPhuThuocID); } if (dbNPT != null) { AutoMapper.Mapper.Map <DTO.NguoiPhuThuocDTO, NguoiPhuThuoc>(dtoNPT, dbNPT); } } }
//============================ private void LoadThongTinTaiKhoan() { BLL.NhanVienBLL nhanVienBLL = new BLL.NhanVienBLL(); DTO.NhanVienDTO nhanVien = nhanVienBLL.LoadThongTinTaiKhoan(this.UserName); txtHoNhanVien.Text = nhanVien.HoNV; txtTenNhanVien.Text = nhanVien.TenNV; dtpNgaySinhNhanVien.Text = nhanVien.NgaySinh; dtpNgayVaoLamNhanVien.Text = nhanVien.NgayVaoLam; if (nhanVien.GioiTinh == true) { rbNamNhanVien.Checked = true; } else { rbNuNhanVien.Checked = true; } txtUserName.Text = nhanVien.UserName; txtMaNV.Text = nhanVien.MaNV; txtCMNDNhanVien.Text = nhanVien.CmndNV; txtDienThoaiNhanVien.Text = nhanVien.DienThoai; txtUserName1.Text = nhanVien.UserName; }
private void LoadThongTinNhanVien() { BLL.NhanVienBLL nv = new BLL.NhanVienBLL(); nhanVien = nv.GetNhanVienByMaNV(this.maNV); txtCMNDNhanVien.Text = nhanVien.Cmnd; txtDiaChiNhanVien.Text = nhanVien.DiaChi; txtDienThoaiNhanVien.Text = nhanVien.DienThoai; txtHoNhanVien.Text = nhanVien.HoNV; txtTenNhanVien.Text = nhanVien.TenNV; txtQueQuanNhanVien.Text = nhanVien.QueQuan; txtMaNV.Text = this.maNV; dtpNgayVaoLamNhanVien.Text = nhanVien.NgayVaoLam; dtpNgaySinhNhanVien.Text = nhanVien.NgaySinh; txtTenTaiKhoan.Text = nhanVien.MaNhanVien; if (nhanVien.GioiTinh == true) { rbNamNhanVien.Checked = true; } else { rbNuNhanVien.Checked = true; } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { //throw new NotImplementedException(); DTO.NhanVienDTO dtoNhanVien = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.NhanVienDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (NhanVienMngEntities context = CreateContext()) { NhanVien dbItem = null; if (id == 0) { dbItem = new NhanVien(); context.NhanVien.Add(dbItem); } else { dbItem = context.NhanVien.FirstOrDefault(o => o.NhanVienID == id); } if (dbItem == null) { notification.Message = "Nhan vien not found!"; return(false); } else { dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; converter.DTO2DB(dtoNhanVien, ref dbItem, userId); context.SaveChanges(); // generate NHAN VIEN UD if (id <= 0) { using (DbContextTransaction scope = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SELECT * FROM NhanVien WITH (TABLOCKX, HOLDLOCK)"); try { dbItem.NhanVienUD = context.NhanVienMng_function_GenerateNhanVienUD().FirstOrDefault().ToString(); context.SaveChanges(); } catch (Exception ex) { throw ex; } finally { scope.Commit(); } } } dtoItem = GetData(dbItem.NhanVienID, out notification).Data; return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (fopen.FileName != "") { Excel.Application app = new Excel.Application(); Excel.Workbook wb = app.Workbooks.Open(fopen.FileName); Excel.Worksheet sheet = null; try { sheet = wb.Sheets[1]; Excel.Range range = sheet.UsedRange; int rows = range.Rows.Count; int col = 43; for (int i = 3; i <= rows; i++) { if (string.IsNullOrEmpty(range.Cells[i, col].Text.ToString()) != true) { if (string.IsNullOrEmpty(range.Cells[i, col + 1].Text.ToString()) != true) { if (string.IsNullOrEmpty(range.Cells[i, col + 6].Text.ToString()) != true) { if (string.IsNullOrEmpty(range.Cells[i, col + 7].Text.ToString()) != true) { if (string.IsNullOrEmpty(range.Cells[i, col + 20].Text.ToString()) != true && range.Cells[i, col + 20].Text.ToString() != "#NAME?" && range.Cells[i, col + 20].Text.ToString() != "#N/A") { if (string.IsNullOrEmpty(range.Cells[i, col + 21].Text.ToString()) != true) { if (string.IsNullOrEmpty(range.Cells[i, col + 23].Text.ToString()) != true && range.Cells[i, col + 23].Text.ToString() != "#NAME?" && range.Cells[i, col + 23].Text.ToString() != "#N/A") { DTO.NhanVienDTO nv = new DTO.NhanVienDTO(); manvLast = BUS.NhanVienBUS.GetLastNhanVien().Rows[0][0].ToString(); nv.MaNV = NextID(manvLast, "NV"); nv.HoTen = range.Cells[i, col].Text.ToString(); nv.NgayVaoLam = Convert.ToDateTime(range.Cells[i, col + 1].Text.ToString()); if (string.IsNullOrEmpty(range.Cells[i, col + 2].Text.ToString()) != true && range.Cells[i, col + 2].Text.ToString() != "#NAME?" && range.Cells[i, col + 2].Text.ToString() != "#N/A") { nv.MaPB = "'" + range.Cells[i, col + 2].Text.ToString() + "'"; } else { nv.MaPB = "NULL"; } nv.LuongCanBan = range.Cells[i, col + 24].Text.ToString(); if (string.IsNullOrEmpty(range.Cells[i, col + 3].Text.ToString()) != true) { nv.HinhAnh = range.Cells[i, col + 3].Text.ToString(); } else { nv.HinhAnh = ""; } if (string.IsNullOrEmpty(range.Cells[i, col + 4].Text.ToString()) != true && range.Cells[i, col + 4].Text.ToString() != "#NAME?" && range.Cells[i, col + 4].Text.ToString() != "#N/A") { nv.MaTT = Int16.Parse(range.Cells[i, col + 4].Text.ToString()); } else { nv.MaTT = 1; } DTO.ThongTinChiTietNhanVienDTO ttct = new DTO.ThongTinChiTietNhanVienDTO(); ttct.MaNV = nv.MaNV; if (string.IsNullOrEmpty(range.Cells[i, col + 5].Text.ToString()) != true && range.Cells[i, col + 5].Text.ToString() != "#NAME?" && range.Cells[i, col + 5].Text.ToString() != "#N/A") { ttct.MaGT = Convert.ToBoolean(Convert.ToInt16(range.Cells[i, col + 5].Text.ToString())); } else { ttct.MaGT = true; } ttct.CMND = range.Cells[i, col + 6].Text.ToString(); ttct.NgaySinh = Convert.ToDateTime(range.Cells[i, col + 7].Text.ToString()); if (string.IsNullOrEmpty(range.Cells[i, col + 8].Text.ToString()) != true) { ttct.NoiSinh = range.Cells[i, col + 8].Text.ToString(); } else { ttct.NoiSinh = ""; } if (string.IsNullOrEmpty(range.Cells[i, col + 9].Text.ToString()) != true) { ttct.DienThoai = range.Cells[i, col + 9].Text.ToString(); } else { ttct.DienThoai = ""; } if (string.IsNullOrEmpty(range.Cells[i, col + 10].Text.ToString()) != true) { ttct.SoNha = range.Cells[i, col + 10].Text.ToString(); } else { ttct.SoNha = ""; } if (string.IsNullOrEmpty(range.Cells[i, col + 11].Text.ToString()) != true) { ttct.Duong = range.Cells[i, col + 11].Text.ToString(); } else { ttct.Duong = ""; } if (string.IsNullOrEmpty(range.Cells[i, col + 12].Text.ToString()) != true) { ttct.PhuongXa = range.Cells[i, col + 12].Text.ToString(); } else { ttct.PhuongXa = ""; } if (string.IsNullOrEmpty(range.Cells[i, col + 13].Text.ToString()) != true && range.Cells[i, col + 13].Text.ToString() != "#NAME?" && range.Cells[i, col + 13].Text.ToString() != "#N/A") { ttct.QuanHuyen = "'" + range.Cells[i, col + 13].Text.ToString() + "'"; } else { ttct.QuanHuyen = "NULL"; } if (string.IsNullOrEmpty(range.Cells[i, col + 14].Text.ToString()) != true && range.Cells[i, col + 14].Text.ToString() != "#NAME?" && range.Cells[i, col + 14].Text.ToString() != "#N/A") { ttct.TinhTP = "'" + range.Cells[i, col + 14].Text.ToString() + "'"; } else { ttct.TinhTP = "NULL"; } if (string.IsNullOrEmpty(range.Cells[i, col + 15].Text.ToString()) != true && range.Cells[i, col + 15].Text.ToString() != "#NAME?" && range.Cells[i, col + 15].Text.ToString() != "#N/A") { ttct.QuocGia = "'" + range.Cells[i, col + 15].Text.ToString() + "'"; } else { ttct.QuocGia = "NULL"; } if (string.IsNullOrEmpty(range.Cells[i, col + 16].Text.ToString()) != true && range.Cells[i, col + 16].Text.ToString() != "#NAME?" && range.Cells[i, col + 16].Text.ToString() != "#N/A") { ttct.MaDT = "'" + range.Cells[i, col + 16].Text.ToString() + "'"; } else { ttct.MaDT = "NULL"; } if (string.IsNullOrEmpty(range.Cells[i, col + 17].Text.ToString()) != true && range.Cells[i, col + 17].Text.ToString() != "#NAME?" && range.Cells[i, col + 17].Text.ToString() != "#N/A") { ttct.MaTG = "'" + range.Cells[i, col + 17].Text.ToString() + "'"; } else { ttct.MaTG = "NULL"; } if (string.IsNullOrEmpty(range.Cells[i, col + 18].Text.ToString()) != true) { ttct.SoTheATM = range.Cells[i, col + 18].Text.ToString(); } else { ttct.SoTheATM = ""; } if (string.IsNullOrEmpty(range.Cells[i, col + 19].Text.ToString()) != true) { ttct.Email = range.Cells[i, col + 19].Text.ToString(); } else { ttct.Email = ""; } BUS.NguoiDungBUS.SetIsUpdated(Login.Account); BUS.NhanVienBUS.AddNhanVienMulti(nv, ttct); DTO.HopDongDTO hd = new DTO.HopDongDTO(); mahdLast = BUS.HopDongBUS.GetLastHopDong().Rows[0][0].ToString(); hd.MaHD = NextID(mahdLast, "HD"); hd.MaNV = nv.MaNV; hd.MaLoaiHD = Int16.Parse(range.Cells[i, col + 20].Text.ToString()); hd.NgayKyHD = Convert.ToDateTime(range.Cells[i, col + 21].Text.ToString()); if (string.IsNullOrEmpty(range.Cells[i, col + 22].Text.ToString()) != true) { hd.NgayHetHan = Convert.ToDateTime(range.Cells[i, col + 22].Text.ToString()); } else { switch (hd.MaLoaiHD.ToString()) { case "1": hd.NgayHetHan = Convert.ToDateTime("1/1/2500"); break; case "2": hd.NgayHetHan = Convert.ToDateTime(range.Cells[i, col + 21].Text.ToString()).AddYears(5).AddDays(-1); break; case "3": hd.NgayHetHan = Convert.ToDateTime(range.Cells[i, col + 21].Text.ToString()).AddYears(3).AddDays(-1); break; case "4": hd.NgayHetHan = Convert.ToDateTime(range.Cells[i, col + 21].Text.ToString()).AddYears(2).AddDays(-1); break; case "5": hd.NgayHetHan = Convert.ToDateTime(range.Cells[i, col + 21].Text.ToString()).AddYears(1).AddDays(-1); break; case "6": hd.NgayHetHan = Convert.ToDateTime(range.Cells[i, col + 21].Text.ToString()).AddMonths(3).AddDays(-1); break; } } hd.MaTTHD = Int16.Parse(range.Cells[i, col + 23].Text.ToString()); BUS.NguoiDungBUS.SetIsUpdated(Login.Account); BUS.HopDongBUS.AddHopDongMulti(hd); } else { string error = "Lỗi ở dòng " + i.ToString() + " cột Tình trạng hợp đồng."; listError.Add(error); } } else { string error = "Lỗi ở dòng " + i.ToString() + " cột Ngày ký hợp đồng."; listError.Add(error); } } else { string error = "Lỗi ở dòng " + i.ToString() + " cột Loại hợp đồng."; listError.Add(error); } } else { string error = "Lỗi ở dòng " + i.ToString() + " cột Ngày sinh."; listError.Add(error); } } else { string error = "Lỗi ở dòng " + i.ToString() + " cột CMND."; listError.Add(error); } } else { string error = "Lỗi ở dòng " + i.ToString() + " cột Ngày vào làm."; listError.Add(error); } } else { break; } } MessageBox.Show("Thêm nhân viên thành công!"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error); } finally { wb = null; app.Quit(); } } }
public bool Insert(string maNV, string hoNV, string tenNV, string ngaySinh, bool gioiTinh, string diaChi, string dienThoai, string cmnd, string queQuan, string ngayVaoLam) { DTO.NhanVienDTO nhanVien = new DTO.NhanVienDTO(maNV, hoNV, tenNV, ngaySinh, gioiTinh, diaChi, dienThoai, cmnd, queQuan, ngayVaoLam); return(DAL.NhanVienDAL.Instance.Insert(nhanVien)); }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (tbHoTen.Text != "") { if (tbCMND.Text.Length >= 9) { if (tbATM.Text.Length > 0) { if (tbLCB.Text != "") { if (tbEmail.Text != "") { if (IsMail(tbEmail.Text) == true) { if (dpNgaySinh.SelectedDate != null) { DTO.NhanVienDTO nv = new DTO.NhanVienDTO(); manvLast = BUS.NhanVienBUS.GetLastNhanVien().Rows[0][0].ToString(); nv.MaNV = NextID(manvLast, "NV"); nv.HoTen = tbHoTen.Text; nv.NgayVaoLam = Convert.ToDateTime(dpNVL.Text); //nv.MaCV = cbChucVu.SelectedValue.ToString(); nv.MaPB = cbPhongBan.SelectedValue.ToString(); nv.LuongCanBan = tbLCB.Text; if (cbHinhAnh.SelectedValue != null) { nv.HinhAnh = cbHinhAnh.SelectedValue.ToString(); } else { nv.HinhAnh = ""; } nv.MaTT = Int16.Parse(cbTinhTrang.SelectedValue.ToString()); DTO.ThongTinChiTietNhanVienDTO ttct = new DTO.ThongTinChiTietNhanVienDTO(); ttct.MaNV = nv.MaNV; ttct.MaGT = Convert.ToBoolean(cbGioiTinh.SelectedIndex); ttct.CMND = tbCMND.Text; ttct.NgaySinh = Convert.ToDateTime(dpNgaySinh.Text); ttct.NoiSinh = tbNoiSinh.Text; ttct.DienThoai = tbDienThoai.Text; ttct.SoNha = tbSoNha.Text; ttct.Duong = tbDuong.Text; ttct.PhuongXa = tbPhuongXa.Text; ttct.QuanHuyen = cbQuanHuyen.SelectedValue.ToString(); ttct.TinhTP = cbTinhTP.SelectedValue.ToString(); ttct.QuocGia = cbQuocGia.SelectedValue.ToString(); ttct.MaDT = cbDanToc.SelectedValue.ToString(); ttct.MaTG = cbTonGiao.SelectedValue.ToString(); ttct.SoTheATM = tbATM.Text; ttct.Email = tbEmail.Text; BUS.NguoiDungBUS.SetIsUpdated(Login.Account); BUS.NhanVienBUS.AddNhanVien(nv, ttct); DTO.HopDongDTO hd = new DTO.HopDongDTO(); mahdLast = BUS.HopDongBUS.GetLastHopDong().Rows[0][0].ToString(); hd.MaHD = NextID(mahdLast, "HD"); hd.MaNV = nv.MaNV; hd.MaLoaiHD = Int16.Parse(cbMaLoaiHD.SelectedValue.ToString()); hd.NgayKyHD = Convert.ToDateTime(dpNgayKyHD.Text); if (dpNgayHetHan.SelectedDate != null && dpNgayHetHan.Text != "") { hd.NgayHetHan = Convert.ToDateTime(dpNgayHetHan.Text); } else { hd.NgayHetHan = Convert.ToDateTime("1/1/2500"); } hd.MaTTHD = Int16.Parse(cbMaTTHD.SelectedValue.ToString()); BUS.NguoiDungBUS.SetIsUpdated(Login.Account); BUS.HopDongBUS.AddHopDong(hd); RefreshField(); } } else { dialogHostWarning.DataContext = "Chuỗi không đúng định dạng Email!"; dialogHostWarning.IsOpen = true; } } else { if (dpNgaySinh.SelectedDate != null) { DTO.NhanVienDTO nv = new DTO.NhanVienDTO(); manvLast = BUS.NhanVienBUS.GetLastNhanVien().Rows[0][0].ToString(); nv.MaNV = NextID(manvLast, "NV"); nv.HoTen = tbHoTen.Text; nv.NgayVaoLam = Convert.ToDateTime(dpNVL.Text); //nv.MaCV = cbChucVu.SelectedValue.ToString(); nv.MaPB = cbPhongBan.SelectedValue.ToString(); nv.LuongCanBan = tbLCB.Text; if (cbHinhAnh.SelectedValue != null) { nv.HinhAnh = cbHinhAnh.SelectedValue.ToString(); } else { nv.HinhAnh = ""; } nv.MaTT = Int16.Parse(cbTinhTrang.SelectedValue.ToString()); DTO.ThongTinChiTietNhanVienDTO ttct = new DTO.ThongTinChiTietNhanVienDTO(); ttct.MaNV = nv.MaNV; ttct.MaGT = Convert.ToBoolean(cbGioiTinh.SelectedIndex); ttct.CMND = tbCMND.Text; ttct.NgaySinh = Convert.ToDateTime(dpNgaySinh.Text); ttct.NoiSinh = tbNoiSinh.Text; ttct.DienThoai = tbDienThoai.Text; ttct.SoNha = tbSoNha.Text; ttct.Duong = tbDuong.Text; ttct.PhuongXa = tbPhuongXa.Text; ttct.QuanHuyen = cbQuanHuyen.SelectedValue.ToString(); ttct.TinhTP = cbTinhTP.SelectedValue.ToString(); ttct.QuocGia = cbQuocGia.SelectedValue.ToString(); ttct.MaDT = cbDanToc.SelectedValue.ToString(); ttct.MaTG = cbTonGiao.SelectedValue.ToString(); ttct.SoTheATM = tbATM.Text; ttct.Email = tbEmail.Text; BUS.NhanVienBUS.AddNhanVien(nv, ttct); DTO.HopDongDTO hd = new DTO.HopDongDTO(); mahdLast = BUS.HopDongBUS.GetLastHopDong().Rows[0][0].ToString(); hd.MaHD = NextID(mahdLast, "HD"); hd.MaNV = nv.MaNV; hd.MaLoaiHD = Int16.Parse(cbMaLoaiHD.SelectedValue.ToString()); hd.NgayKyHD = Convert.ToDateTime(dpNgayKyHD.Text); if (dpNgayHetHan.SelectedDate != null && dpNgayHetHan.Text != "") { hd.NgayHetHan = Convert.ToDateTime(dpNgayHetHan.Text); } else { hd.NgayHetHan = Convert.ToDateTime("1/1/2500"); } hd.MaTTHD = Int16.Parse(cbMaTTHD.SelectedValue.ToString()); BUS.HopDongBUS.AddHopDong(hd); RefreshField(); } else { dialogHostWarning.DataContext = "Hãy chọn Ngày Sinh!"; dialogHostWarning.IsOpen = true; } } } else { dialogHostWarning.DataContext = "Lương không được bỏ trống"; dialogHostWarning.IsOpen = true; } } } else { dialogHostWarning.DataContext = "CMND phải có 9 hoặc 12 số!"; dialogHostWarning.IsOpen = true; } } else { dialogHostWarning.DataContext = "Họ tên không được bỏ trống!"; dialogHostWarning.IsOpen = true; } }