Example #1
0
        public Result <TblTTNVCoBan> addNhanVien(TblTTNVCoBan instance, TblTTCaNhan instanceCanhan)
        {
            var result = new Result <TblTTNVCoBan>();
            var temp   = connect.TblTTNVCoBans.Where(x => x.MaNV == instance.MaNV).FirstOrDefault();

            if (temp == null)
            {
                try
                {
                    connect.TblTTNVCoBans.Add(instance);
                    connect.TblTTCaNhans.Add(instanceCanhan);
                    connect.SaveChanges();
                    result.Success = true;
                    result.Message = "Thành công!";
                    result.Data    = instance;
                }
                catch (Exception e)
                {
                    result.Success = false;
                    result.Message = "Đã xảy ra lỗi khi thêm bản ghi! ";
                    result.Data    = instance;
                }
                return(result);
            }
            else
            {
                result.Success = false;
                result.Message = "Đã tồn tại bản ghi";
                result.Data    = instance;
                return(result);
            }
        }
Example #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            TblTTNVCoBan nvcb = new TblTTNVCoBan();

            nvcb.MaNV       = txtMaNV.Text;
            nvcb.HoTen      = txtTenNV.Text;
            nvcb.GioiTinh   = cbbGioiTinh.Text;
            nvcb.MaBoPhan   = cbbBophan.SelectedValue.ToString();
            nvcb.MaPhong    = cbbPhongBan.SelectedValue.ToString();
            nvcb.BiDanh     = txtBiDanh.Text;
            nvcb.NgaySinh   = dtimeNgaySinh.Value;
            nvcb.TTHonNhan  = cbbTTHonNhan.SelectedText;
            nvcb.CMTND      = txtCMND.Text;
            nvcb.NgayCap    = dtimeNgayCap.Value;
            nvcb.NoiCap     = txtNoiCap.Text;
            nvcb.ChucVu     = txtChucVu.Text;
            nvcb.ChucDanh   = txtChucDanh.Text;
            nvcb.LoaiHD     = "";
            nvcb.NgayKy     = dtimeNgayKiHD.Value;
            nvcb.NgayHetHan = dtimeNgayHHHD.Value;
            nvcb.Anh        = "";
            nvcb.GhiChu     = txtGhiChuCoBan.Text;
            TblTTCaNhan nvcn = new TblTTCaNhan();

            nvcn.MaNV       = txtMaNV.Text;
            nvcn.NoiSinh    = txtNoiSinh.Text;
            nvcn.NguyenQuan = txtQueQuan.Text;
            nvcn.QuocTich   = txtQuoctich.Text;
            nvcn.DanToc     = txtDanToc.Text;
            nvcn.SDT        = txtSDT.Text;
            nvcn.TrinhDoNN  = txtTrinhDoNN.Text;
            nvcn.HocVan     = txtHocVan.Text;
            nvcn.GhiChu     = txtGhiChu.Text;
            try
            {
                contr.addNhanVien(nvcb, nvcn);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi thêm mới nhân viên", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }