コード例 #1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtHoTenNV.Text == "" || txtemail.Text == "" || txtDiaChi.Text == "" || txtSdt.Text == "" || dtngaysinh.Text == "")
            {
                XtraMessageBox.Show("Hãy điền đầy đủ thông tin!");
            }
            else
            {
                NhanVien    nv    = new NhanVien();
                NhanvienDao nvdao = new NhanvienDao();
                nv.MaNV = txtMaNV.Text;

                string macv = db.ChucVus.Where(p => p.TenCV == cboQuyenHan.Text).Select(l => l.MaCV).SingleOrDefault();
                nv.MaCV  = macv;
                nv.TenNV = txtHoTenNV.Text;
                bool gioitinh = true;
                if (cboGioiTinh.Text != "Nam")
                {
                    gioitinh = false;
                }
                nv.GioiTinh   = gioitinh;
                nv.NgaySinh   = dtngaysinh.DateTime;;
                nv.MaNVQuanLi = txtMaNVQL.Text;
                nv.DiaChi     = txtDiaChi.Text;
                nv.Sdt        = txtSdt.Text;;
                nv.MatKhau    = "123456";
                nv.Email      = txtemail.Text;
                nv.Status     = true;
                nvdao.themnhanvien(nv);
                XtraMessageBox.Show("Thêm thành công");
                f.loadlaigridview();
                this.Close();
            }
        }
コード例 #2
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtHoTenNV.Text == "" || txtemail.Text == "" || txtDiaChi.Text == "" || txtSdt.Text == "" || dtngaysinh.Text == "")
                {
                    XtraMessageBox.Show("Bạn chưa điền đầy đủ thông tin!");
                }
                else
                {
                    NhanVien    nv    = new NhanVien();
                    NhanvienDao nvdao = new NhanvienDao();
                    nv.MaNV = txtMaNV.Text;

                    string macv = db.ChucVus.Where(p => p.TenCV == cboQuyenHan.Text).Select(l => l.MaCV).SingleOrDefault();
                    nv.MaCV  = macv;
                    nv.TenNV = txtHoTenNV.Text;
                    bool gioitinh = true;
                    if (cboGioiTinh.Text != "Nam")
                    {
                        gioitinh = false;
                    }
                    nv.GioiTinh   = gioitinh;
                    nv.NgaySinh   = dtngaysinh.DateTime;;
                    nv.MaNVQuanLi = txtMaNVQL.Text;
                    nv.DiaChi     = txtDiaChi.Text;
                    nv.Sdt        = txtSdt.Text;;
                    nv.MatKhau    = MahoaMD5.getMd5Hash("123456");
                    nv.Email      = txtemail.Text;
                    nv.Status     = true;
                    nvdao.themnhanvien(nv);
                    XtraMessageBox.Show("Thêm thành công");
                    f.loadlaigridview();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                string   loi      = ex.InnerException.ToString();
                string[] loichia  = loi.Split('\n');
                string[] loichinh = loichia[0].Split(':');
                XtraMessageBox.Show(loichinh[2]);
            }
        }