Ejemplo n.º 1
0
        public bool UpdateNhanVien(NhanVien_ET nhanVien)
        {
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("SP_NhanVien_Update", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", nhanVien.ID);
                cmd.Parameters.AddWithValue("@hoten", nhanVien.HoTen);
                cmd.Parameters.AddWithValue("@gioitinh", nhanVien.GioiTinh);
                cmd.Parameters.AddWithValue("@diachi", nhanVien.DiaChi);
                cmd.Parameters.AddWithValue("@sdt", nhanVien.SDT);
                cmd.Parameters.AddWithValue("@ngaysinh", nhanVien.NgaySinh);

                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 2
0
        public bool DeleteNhanVien(NhanVien_ET nhanVien)
        {
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("SP_NhanVien_Delete", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", nhanVien.ID);

                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 3
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            //Dialog xác nhận xóa hay ko
            DialogResult res = MessageBox.Show("Bạn có muốn xóa không?", "Xóa nhân viên", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res == DialogResult.Yes)
            {
                try
                {
                    id_NhanVien = Int32.Parse(txtID_NhanVien.Text);
                    hoTenNV     = txtTenNV.Text;
                    //kiểm tra radio button
                    if (rabNam.Checked)
                    {
                        gioiTinh = "Nam";
                    }
                    if (rabNu.Checked)
                    {
                        gioiTinh = "Nữ";
                    }
                    diaChi   = txtDiaChi.Text;
                    sdt      = txtSDT.Text;
                    ngaySinh = dtpNgaySinh.Value;//get ngày sinh

                    NhanVien_ET nhanVien = new NhanVien_ET(id_NhanVien, hoTenNV, gioiTinh, diaChi, sdt, ngaySinh);
                    if (bus_NhanVien.DeleteNhanVien(nhanVien) == true)
                    {
                        MessageBox.Show("Xóa nhân viên thành công!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        showButton(false);
                        clearText();
                        dtgvNhanVien.DataSource = bus_NhanVien.GetAllNhanVien();
                    }
                    else
                    {
                        MessageBox.Show("Xóa thất bại!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Đã xảy ra lỗi: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 4
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (lenh == ADD)
            {
                try
                {
                    // id_NhanVien = Int32.Parse(txtID_NhanVien.Text);
                    hoTenNV = txtTenNV.Text;
                    if (rabNam.Checked)
                    {
                        gioiTinh = "Nam";
                    }
                    if (rabNu.Checked)
                    {
                        gioiTinh = "Nữ";
                    }
                    diaChi   = txtDiaChi.Text;
                    sdt      = txtSDT.Text;
                    ngaySinh = dtpNgaySinh.Value;

                    NhanVien_ET nhanVien = new NhanVien_ET(hoTenNV, gioiTinh, diaChi, sdt, ngaySinh);
                    if (bus_NhanVien.AddNhanVien(nhanVien) == true)
                    {
                        MessageBox.Show("Thêm nhân viên thành công!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        showButton(false);
                        clearText();
                        dtgvNhanVien.DataSource = bus_NhanVien.GetAllNhanVien();
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Đã xảy ra lỗi: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (lenh == EDIT)
            {
                try
                {
                    id_NhanVien = Int32.Parse(txtID_NhanVien.Text);
                    hoTenNV     = txtTenNV.Text;
                    if (rabNam.Checked)
                    {
                        gioiTinh = "Nam";
                    }
                    if (rabNu.Checked)
                    {
                        gioiTinh = "Nữ";
                    }
                    diaChi   = txtDiaChi.Text;
                    sdt      = txtSDT.Text;
                    ngaySinh = dtpNgaySinh.Value;

                    NhanVien_ET nhanVien = new NhanVien_ET(id_NhanVien, hoTenNV, gioiTinh, diaChi, sdt, ngaySinh);
                    if (bus_NhanVien.UpdateNhanVien(nhanVien) == true)
                    {
                        MessageBox.Show("Cập nhật nhân viên thành công!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        showButton(false);
                        clearText();
                        dtgvNhanVien.DataSource = bus_NhanVien.GetAllNhanVien();
                    }
                    else
                    {
                        MessageBox.Show("Cập nhật thất bại!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Đã xảy ra lỗi: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 5
0
 public bool DeleteNhanVien(NhanVien_ET nhanVien)
 {
     return(dal_NhanVien.DeleteNhanVien(nhanVien));
 }
Ejemplo n.º 6
0
 public bool UpdateNhanVien(NhanVien_ET nhanVien)
 {
     return(dal_NhanVien.UpdateNhanVien(nhanVien));
 }
Ejemplo n.º 7
0
 public bool AddNhanVien(NhanVien_ET nhanVien)
 {
     return(dal_NhanVien.AddNhanVien(nhanVien));
 }