Beispiel #1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            int i = -1; string s = "";

            try
            {
                NhanVien ob = new NhanVien(txtMaNV.Text, txtHoTen.Text, da_tiNgaySinh.Value.ToString(), txtCMND.Text,
                                           radioBtnNam.Checked ? "Nam" : "Nữ", txtDC.Text, txtDT.Text, txtEmail.Text);
                i = nv.Insert(ob);
            }
            catch { s = "Dữ liệu đã nhập không phù hợp!\n Mời nhập lại!!"; }
            switch (i)
            {
            case -2:
                s = "Lỗi kết nối!!";
                break;

            case 1:
                s = "Thêm thành công!!";
                Frm_NhanVien_Load(sender, e);
                break;

            case 2:
                s = "Không thể thêm dữ liệu!!\n Mã nhân viên này đã tồn tại!!";
                break;

            case 0:
                s = "Lỗi!! Không thể thêm dữ liệu!!";
                break;
            }
            MessageBox.Show(s, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtTenNV.Text == "" || txtSDT.Text == "" || txtChucVu.Text == "" || txtEmail.Text == "" || txtdiachi.Text == "" || txtPhuTrach.Text == "")
            {
                MessageBox.Show("Dữ liệu nhập chưa đủ.");
                if (txtTenNV.Text == "")
                {
                    errorProvider1.SetError(txtTenNV, "Chưa điền tên.");
                }
                if (txtChucVu.Text == "")
                {
                    errorProvider1.SetError(txtChucVu, "Chưa điền thông tin.");
                }
                if (txtSDT.Text == "")
                {
                    errorProvider1.SetError(txtSDT, "Chưa điền thông tin.");
                }
                if (txtEmail.Text == "")
                {
                    errorProvider1.SetError(txtEmail, "Chưa điền tên.");
                }
                if (txtdiachi.Text == "")
                {
                    errorProvider1.SetError(txtdiachi, "Chưa điền thông tin.");
                }
                if (txtPhuTrach.Text == "")
                {
                    errorProvider1.SetError(txtPhuTrach, "Chưa điền thông tin.");
                }
            }
            else
            {
                NhanVien nhanvien = new NhanVien();

                if (chucnang == 1)
                {
                    nhanvien.TenNhanVien = txtTenNV.Text;
                    nhanvien.ChucVu      = txtChucVu.Text;
                    nhanvien.Sdt         = txtSDT.Text;
                    nhanvien.PhuTrach    = txtPhuTrach.Text;
                    nhanvien.DiaChi      = txtdiachi.Text;
                    nhanvien.Email       = txtEmail.Text;
                    nhanvien.NgaySinh    = (DateTime)dpkNgaySinh.Value;
                    if (bUS_nhanvien.Insert(nhanvien))
                    {
                        MessageBox.Show("Thêm dữ liệu thành công.", "Thông báo.");

                        //------------Ghi log
                        NhatKyHoatDong nhatKy = new NhatKyHoatDong();
                        nhatKy.NguoiDungId = Const.CurrentUser.NguoiDungId;
                        nhatKy.NoiDung     = "Thêm thành công nhân viên: " + txtTenNV.Text + " vào hệ thống";
                        nhatKy.ThaoTac     = "Tạo";
                        nhatKy.ThoiGian    = DateTime.Now;
                        nhatKy.ChucNang    = "Nhân viên";
                        Const.NhatKyHoatDong.Insert(nhatKy);
                        //-------------------
                    }
                    else
                    {
                        MessageBox.Show("Thêm dữ liệu lỗi.", "Thông báo.");
                    }
                }

                if (chucnang == 2)
                {
                    nhanvien.NhanVienId  = int.Parse(txtMaNV.Text);
                    nhanvien.TenNhanVien = txtTenNV.Text;
                    nhanvien.ChucVu      = txtChucVu.Text;
                    nhanvien.Sdt         = txtSDT.Text;
                    nhanvien.PhuTrach    = txtPhuTrach.Text;
                    nhanvien.DiaChi      = txtdiachi.Text;
                    nhanvien.Email       = txtEmail.Text;
                    nhanvien.NgaySinh    = (DateTime)dpkNgaySinh.Value;
                    if (bUS_nhanvien.Update(nhanvien))
                    {
                        MessageBox.Show("Cập nhật dữ liệu thành công.", "Thông báo.");
                        //------------Ghi log
                        NhatKyHoatDong nhatKy = new NhatKyHoatDong();
                        nhatKy.NguoiDungId = Const.CurrentUser.NguoiDungId;
                        nhatKy.NoiDung     = "Cập nhập thành công nhân viên: " + txtTenNV.Text + " vào hệ thống";
                        nhatKy.ThaoTac     = "Cập nhập";
                        nhatKy.ThoiGian    = DateTime.Now;
                        nhatKy.ChucNang    = "Nhân viên";
                        Const.NhatKyHoatDong.Insert(nhatKy);
                        //-------------------
                    }
                    else
                    {
                        MessageBox.Show("cập nhật dữ liệu lỗi.", "Thông báo.");
                    }
                }
                reset();
            }
        }