示例#1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            ET_NhanVien et_NhanVien = null;

            try
            {
                mtbSoDienThoai.TextMaskFormat = mtbCMND.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;

                if (txtMaQL.Text.Length <= 0)
                {
                    et_NhanVien = new ET_NhanVien(txtMaNV.Text, txtTenNV.Text, mtbCMND.Text, mtbSoDienThoai.Text, txtDiaChi.Text);
                }
                else
                {
                    et_NhanVien = new ET_NhanVien(txtMaNV.Text, txtTenNV.Text, mtbCMND.Text, mtbSoDienThoai.Text, txtDiaChi.Text, cboMaGH.SelectedValue.ToString(), txtMaQL.Text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Kiểu dữ liệu bạn nhập bị sai.Vui lòng nhập lại");
                return;
            }

            if (bus_NhanVien.ThemNhanVien(et_NhanVien))
            {
                dgvNhanVien.DataSource = bus_NhanVien.GetData();
                MessageBox.Show("Bạn Đã thêm thành công.");
            }
            else
            {
                MessageBox.Show("Bạn thêm không thành công.");
            }
        }
示例#2
0
 public bool SuaNhanVien(ET_NhanVien et_NhanVien)
 {
     try
     {
         openDB();
         SqlCommand cmd = null;
         //parameter
         if (et_NhanVien.MaQL == null) //Không có MaQL
         {
             //cmd
             cmd = HandleCMD.proc("sp_SuaQuanLy", _con);
             addParameter(cmd, et_NhanVien, properties); // add parameter.
         }
         else //Có MaQL.
         {
             cmd = HandleCMD.proc("sp_SuaNhanVien", _con);
             addParameter(cmd, et_NhanVien, properties_QL); // add parameter.
         }
         if (cmdExecuted(cmd))
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
     finally
     {
         closeDB();
     }
     return(false);
 }
示例#3
0
        //-----------------------------------------------------------------------------
        //Them,Xoa, Sua
        public bool ThemNhanVien(ET_NhanVien et_NhanVien)
        {
            try
            {
                openDB();
                //cmd
                SqlCommand cmd = null;
                if (et_NhanVien.MaQL == null) //Không có MaQL
                {
                    //cmd
                    cmd = HandleCMD.proc("sp_ThemQuanLy", _con);
                    addParameter(cmd, et_NhanVien, properties); // add parameter.
                }
                else //Có MaQL.
                {
                    cmd = HandleCMD.proc("sp_ThemNhanVien", _con);
                    addParameter(cmd, et_NhanVien, properties_QL); // add parameter.
                }
                if (cmdExecuted(cmd))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error " + ex.Message);
                return(false);
            }
            finally
            {
                closeDB();
            }

            return(false);
        }
示例#4
0
        //----------------------------------------------------------------------------
        //Ham Bo tro
        public void addParameter(SqlCommand cmd, ET_NhanVien nhanvien, String[] strNameParametor)
        { //MaNV, TenNV, CMND, SDT, DC, MaGH
            ArrayList list = nhanvien.getAllPropertie();

            foreach (string item in strNameParametor)
            {
                SqlParameter pt = new SqlParameter(item, list[Array.IndexOf(strNameParametor, item)]);
                cmd.Parameters.Add(pt);
            }
        }
示例#5
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            ET_NhanVien et_NhanVien = null;

            try
            {
                mtbSoDienThoai.TextMaskFormat = mtbCMND.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;

                if (txtMaQL.Text.Length <= 0)//khong co MaQL
                {
                    et_NhanVien = new ET_NhanVien(txtMaNV.Text, txtTenNV.Text, mtbCMND.Text, mtbSoDienThoai.Text, txtDiaChi.Text);
                }
                else //Co MaQL
                {
                    et_NhanVien = new ET_NhanVien(txtMaNV.Text, txtTenNV.Text, mtbCMND.Text, mtbSoDienThoai.Text, txtDiaChi.Text, cboMaGH.SelectedValue.ToString(), txtMaQL.Text);
                }
            }
            catch (InvalidCastException ex)
            {
                MessageBox.Show("Kiểu dữ liệu bạn nhập bị sai.Vui lòng nhập lại");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu bạn hiện đang trống");
                return;
            }

            DialogResult r = MessageBox.Show("Bạn có muốn sữa dữ liệu này không", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (r == DialogResult.No)
            {
                MessageBox.Show("Bạn đã hủy sữa");
                return;
            }

            if (bus_NhanVien.SuaNhanVien(et_NhanVien))
            {
                dgvNhanVien.DataSource = bus_NhanVien.GetData();
                MessageBox.Show("Bạn Đã sữa thành công.");
            }
            else
            {
                MessageBox.Show("Bạn sữa không thành công.");
            }
        }
示例#6
0
        private void dgvNhanVien_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow item = dgvNhanVien.SelectedRows[0];

            if (item == null)
            {
                return;
            }
            if (item.Index >= dgvNhanVien.RowCount - 1)
            {
                MessageBox.Show("Không tìm thấy dữ liệu bạn chọn.Vui lòng chọn lại");
                return;
            }
            ET_NhanVien et_NhanVien = null;

            et_NhanVien           = new ET_NhanVien(item.Cells[0].Value.ToString(), item.Cells[1].Value.ToString(), item.Cells[2].Value.ToString(), item.Cells[3].Value.ToString(), item.Cells[4].Value.ToString(), item.Cells[5].Value.ToString(), item.Cells[6].Value.ToString());
            txtMaNV.Text          = et_NhanVien.MaNV;
            txtTenNV.Text         = et_NhanVien.TenNV;
            mtbCMND.Text          = et_NhanVien.CMND;
            mtbSoDienThoai.Text   = et_NhanVien.SDT;
            txtDiaChi.Text        = et_NhanVien.DC;
            cboMaGH.SelectedValue = et_NhanVien.MaGH;
            txtMaQL.Text          = et_NhanVien.MaQL;
        }
示例#7
0
 public bool SuaNhanVien(ET_NhanVien et_NhanVien)
 {
     return(DAL_NhanVien.SuaNhanVien(et_NhanVien));
 }
示例#8
0
 //---------------------------------------------------------------------------
 //Them, Xoa, Sua
 public bool ThemNhanVien(ET_NhanVien et_NhanVien)
 {
     return(DAL_NhanVien.ThemNhanVien(et_NhanVien));
 }