Beispiel #1
0
        public int insert(NhanVien_obj nv)
        {
            int ret = 0;
            //gv = new GiaoVienObj();
            string sql             = @"insert into NHANVIEN(ID, hoten , ngaysinh , gioitinh , quequan , diachi , soCMND , dienthoai , email ,CV_ID ,PB_ID)
                                         values(@ID,@hoten,@ngaysinh , @gioitinh , @quequan,@diachi,@soCMND , @dienthoai ,@email,@CV_ID ,@PB_ID)";
            List <SqlParameter> li = new List <SqlParameter>();
            SqlParameter        a;

            a       = new SqlParameter("ID", SqlDbType.VarChar);
            a.Value = nv.IDNV;
            li.Add(a);
            a       = new SqlParameter("hoten", SqlDbType.NVarChar);
            a.Value = nv.hotenNV;
            li.Add(a);
            a       = new SqlParameter("ngaysinh", SqlDbType.Date);
            a.Value = nv.ngaysinhNV;
            li.Add(a);
            a       = new SqlParameter("gioitinh", SqlDbType.Bit);
            a.Value = nv.gioitinhNV;
            li.Add(a);
            a       = new SqlParameter("quequan", SqlDbType.NVarChar);
            a.Value = nv.quequanNV;
            li.Add(a);
            a       = new SqlParameter("diachi", SqlDbType.NVarChar);
            a.Value = nv.diachiNV;
            li.Add(a);
            a       = new SqlParameter("soCMND", SqlDbType.VarChar);
            a.Value = nv.soCMNDNV;
            li.Add(a);
            a       = new SqlParameter("dienthoai", SqlDbType.VarChar);
            a.Value = nv.dienthoaiNV;
            li.Add(a);
            a       = new SqlParameter("email", SqlDbType.NVarChar);
            a.Value = nv.emailNV;
            li.Add(a);
            a       = new SqlParameter("CV_ID", SqlDbType.VarChar);
            a.Value = nv.CV_IDNV;
            li.Add(a);
            a       = new SqlParameter("PB_ID", SqlDbType.NVarChar);
            a.Value = nv.PB_IDNV;
            li.Add(a);



            if (doIt == null)
            {
                doIt = new connection();
            }
            if (doIt.isOpen() < 0)
            {
                ret = doIt.connect();
            }
            if (ret < 0)
            {
                return(-2);
            }
            ret = doIt.doSql(sql, li.ToArray());
            return(ret);
        }
Beispiel #2
0
        private void btCapNhat_Click(object sender, EventArgs e)
        {
            if (isEmpty())
            {
                return;
            }
            NhanVien_obj nv = new NhanVien_obj();

            nv.IDNV        = txtID.Text;
            nv.hotenNV     = txthoten.Text;
            nv.ngaysinhNV  = dtpngaysinh.Value;
            nv.emailNV     = txtemail.Text;
            nv.dienthoaiNV = txtdienthoai.Text;
            nv.quequanNV   = txtquequan.Text;
            nv.diachiNV    = txtdiachi.Text;
            nv.soCMNDNV    = txtsoCMND.Text;
            nv.CV_IDNV     = cmbChucVu.SelectedValue.ToString();
            nv.PB_IDNV     = cmbPhongBan.SelectedValue.ToString();

            NhanVienBus bus = new NhanVienBus();
            int         ret;

            ret = bus.update(nv);
            bus.close();
            if (ret < 0)
            {
                MessageBox.Show("Không sửa được dữ liệu ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            txtdiachi.Enabled    = false;
            txtdienthoai.Enabled = false;
            txtemail.Enabled     = false;
            txthoten.Enabled     = false;
            txtquequan.Enabled   = false;
            txtsoCMND.Enabled    = false;
            dtpngaysinh.Enabled  = false;
            cmbChucVu.Enabled    = false;
            cmbPhongBan.Enabled  = false;
            btnthemnv.Enabled    = true;
            btnsuanv.Enabled     = true;
            btnxoanv.Enabled     = true;
            btCapNhat.Enabled    = false;
            btnHuy.Enabled       = false;
            dvgnhanvien.Enabled  = true;
        }
Beispiel #3
0
        public int update(NhanVien_obj nv)
        {
            int    ret             = 0;// kiem tra , neu tra ve 0 thi thuc hien dc , nho hon 0 thi ko thuc hien dc
            string sql             = @"update NHANVIEN
                        set quequan=@quequan,
                        hoten=@hoten,
                        ngaysinh=@ngaysinh,
	                    diachi=@diachi,
	                    soCMND=@soCMND,
	                    dienthoai=@dienthoai,
	                    email=@email,
	                    CV_ID=@CV_ID,
	                    PB_ID=@PB_ID
                        where ID=@ID";
            List <SqlParameter> li = new List <SqlParameter>();
            SqlParameter        a;

            a       = new SqlParameter("ID", SqlDbType.VarChar);
            a.Value = nv.IDNV;
            li.Add(a);
            a       = new SqlParameter("CV_ID", SqlDbType.VarChar);
            a.Value = nv.CV_IDNV;
            li.Add(a);
            a       = new SqlParameter("PB_ID", SqlDbType.VarChar);
            a.Value = nv.PB_IDNV;
            li.Add(a);
            a       = new SqlParameter("hoten", SqlDbType.NVarChar);
            a.Value = nv.hotenNV;
            li.Add(a);
            a       = new SqlParameter("ngaysinh", SqlDbType.Date);
            a.Value = nv.ngaysinhNV;
            li.Add(a);
            a       = new SqlParameter("diachi", SqlDbType.VarChar);
            a.Value = nv.diachiNV;
            li.Add(a);
            a       = new SqlParameter("email", SqlDbType.VarChar);
            a.Value = nv.emailNV;
            li.Add(a);
            a       = new SqlParameter("dienthoai", SqlDbType.VarChar);
            a.Value = nv.dienthoaiNV;
            li.Add(a);
            a       = new SqlParameter("soCMND", SqlDbType.VarChar);
            a.Value = nv.soCMNDNV;
            li.Add(a);

            a       = new SqlParameter("quequan", SqlDbType.VarChar);
            a.Value = nv.quequanNV;
            li.Add(a);



            if (doIt == null)
            {
                doIt = new connection();
            }
            if (doIt.isOpen() < 0)
            {
                ret = doIt.connect();
            }

            if (ret < 0)
            {
                return(-1);
            }
            ret = doIt.doSql(sql, li.ToArray());
            return(ret);
        }
Beispiel #4
0
        private void btLuu_Click(object sender, EventArgs e)
        {
            if (isEmpty())
            {
                return;
            }
            nv = new NhanVien_obj();
            //try
            //{
            if (datetimeNgaySinh.Value < DateTime.Today)
            {
                nv.ngaysinhNV = datetimeNgaySinh.Value;
                nv.IDNV       = txtID.Text;
                nv.hotenNV    = txtHoten.Text;



                if (rdbNam.Checked == true)
                {
                    nv.gioitinhNV = true;
                }
                else if (rdbNu.Checked == true)
                {
                    nv.gioitinhNV = false;
                }
                nv.quequanNV   = txtQuequan.Text;
                nv.diachiNV    = txtDiachi.Text;
                nv.emailNV     = txtEmail.Text;
                nv.dienthoaiNV = txtDienthoai.Text;
                nv.soCMNDNV    = txtCMND.Text;
                nv.PB_IDNV     = cmbTenPhongBan.SelectedValue.ToString();
                nv.CV_IDNV     = cmbChucVu.SelectedValue.ToString();


                NhanVienBus bus = new NhanVienBus();
                int         ret;
                ret = bus.insert(nv);
                bus.close();
                if (ret < 0)
                {
                    MessageBox.Show("Dữ liệu không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                    //this.Hide();
                    //FormNhanVien nv = new FormNhanVien();
                    //nv.Show();
                }
                else
                {
                    MessageBox.Show("Thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (MessageBox.Show("Bạn có muốn tiếp tục thêm mới?", "?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        txtID.Clear();
                        txtHoten.Clear();
                        txtEmail.Clear();
                        txtDienthoai.Clear();
                        txtDiachi.Clear();
                        txtCMND.Clear();
                        txtQuequan.Clear();
                        cmbChucVu.Text      = "";
                        cmbTenPhongBan.Text = "";
                        return;
                    }
                    this.Hide();
                    FormNhanVien nv = new FormNhanVien();
                    nv.Show();
                }
            }
            else
            {
                MessageBox.Show("Nhập sai ngày!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("Dữ liệu không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}
        }