public void btnLuu_Click(object sender, EventArgs e) { BoPhanDTO bophanmoi = new BoPhanDTO(); bophanmoi.TenBoPhan = Convert.ToString(txtTenBoPhan.Text); bophanmoi.GhiChu = Convert.ToString(txtGhiChu.Text); if (chkConQuanLy.Checked == true) { bophanmoi.ConQuanLy = true; } else { bophanmoi.ConQuanLy = false; } int test = BoPhanBUS.ThemBoPhan(bophanmoi); if (test == 0) { Log_BUS.ThemNhatKy("Bộ phận", "Thêm bộ phận"); MessageBox.Show("Thêm bộ phận thành công"); if (eventThemXongBoPhanEvent != null) { eventThemXongBoPhanEvent(); } } else { MessageBox.Show("Nội dung nhập không hợp lệ"); } }
private void BtnSuaBoPhan_Click(object sender, EventArgs e) { if (txtMaBoPhan.Text != "") { BoPhanDTO bp = new BoPhanDTO(); bp.MaBP = int.Parse(txtMaBoPhan.Text); bp.TenBP = txtTenBoPhan.Text; bp = BoPhanBUL.SuaBoPhan(bp); if (bp != null) { BoPhanDTO boPhan = lstBoPhan.SingleOrDefault(i => i.MaBP == bp.MaBP); boPhan.TenBP = bp.TenBP; ReloadDataGridView(); MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Bạn chưa chọn bộ phận nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public DataTable LoadBoPhanFromNhanVienBoPhan(BoPhanDTO boPhanDTO) { string sql = BoPhanDAO.Instance.LoadBoPhanFromNhanVienBoPhan(boPhanDTO); DataTable dt = Core.GetData(sql); return(dt); }
public static List <BoPhanDTO> LayToanBoBoPhan() { List <BoPhanDTO> lst = new List <BoPhanDTO>(); DataProvider p = new DataProvider(); p.Connect(); SqlDataReader r = p.GetReader("sp_LayTatCaBoPhan", CommandType.StoredProcedure); BoPhanDTO bp; while (r.Read()) { bp = new BoPhanDTO(); bp.MaBoPhan = Convert.ToInt32(r[0]); bp.TenBoPhan = r[1].ToString(); bp.GhiChu = r[2].ToString(); bp.ConQuanLy = Convert.ToBoolean(r[3]); lst.Add(bp); } p.Disconnect(); return(lst); }
public static bool SuaBoPhan(BoPhanDTO BoPhanSua) { DataProvider p = new DataProvider(); p.Connect(); SqlParameter p0 = new SqlParameter("@MaBoPhan", SqlDbType.Int) { Value = BoPhanSua.MaBoPhan }; SqlParameter p1 = new SqlParameter("@TenBoPhan", SqlDbType.NVarChar, 255) { Value = BoPhanSua.TenBoPhan }; SqlParameter p2 = new SqlParameter("@GhiChu", SqlDbType.NVarChar, 255) { Value = BoPhanSua.GhiChu }; SqlParameter p3 = new SqlParameter("@ConQuanLy", SqlDbType.Bit) { Value = BoPhanSua.ConQuanLy }; int n = p.ExecuteNonQuery("sp_SuaBoPhan", CommandType.StoredProcedure, p0, p1, p2, p3); p.Disconnect(); if (n == 0) { return(false); } return(true); }
private void btnCapNhat_Click(object sender, EventArgs e) { BoPhanDTO boPhan = new BoPhanDTO(); boPhan.TenBoPhan = txtBoPhan.Text.Trim(); boPhan.BoPhanID = BoPhanID; if (kt == 1) { if (txtBoPhan.Text == "") { MessageBox.Show("Bạn chưa nhập tên bộ phận"); } else { if (BoPhanBUS.Instance.ThemBoPhan(boPhan) == -1) { MessageBox.Show("Lỗi khi thêm mới"); } else { Load_DL(); } } } else { BoPhanBUS.Instance.UpdateBoPhan(boPhan); Load_DL(); } Reset(); }
public void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { int[] l = GridView1.GetSelectedRows(); var index = l[0]; switch (MessageBox.Show("Bạn có chắc chắn muốn xóa bộ phận này không?", "Hỏi Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { case DialogResult.Yes: BoPhanDTO bophan = default(BoPhanDTO); bophan = ((List <BoPhanDTO>)gridBoPhan.DataSource)[index]; bool test = BoPhanBUS.XoaKhoHang(bophan); if (test == true) { Log_BUS.ThemNhatKy("Bộ phận", "Xóa bộ phận"); LoadGridBoPhan(); MessageBox.Show("Xóa thành công"); } else { MessageBox.Show("Xóa không thành công"); } break; case DialogResult.No: return; } }
public bool UpdateBoPhan(BoPhanDTO dtoBoPhan) { string strQuery = "Update BOPHAN Set "; strQuery += "TENBOPHAN = N'" + dtoBoPhan.TenBoPhan + "' "; strQuery += "Where MABOPHAN = N'" + dtoBoPhan.MaBP + "'"; return(dp.ExecuteNonQuery(strQuery)); }
public bool InsertBoPhan(BoPhanDTO dtoBoPhan) { string strQuery = "Insert Into BOPHAN Values("; strQuery += "N'" + dtoBoPhan.MaBP + "',"; strQuery += "N'" + dtoBoPhan.TenBoPhan + "', 1)"; return(dp.ExecuteNonQuery(strQuery)); }
private void btnThem_Click_1(object sender, EventArgs e) { BoPhanDTO BoPhanDTO = new BoPhanDTO() { ConQuanLy = true }; ThemBoPhan frm = new ThemBoPhan(true, BoPhanDTO); frm.ShowDialog(); hienThi(); }
public ThemBoPhan(bool _isAddNew1, BoPhanDTO BoPhanDTO) { InitializeComponent(); _isAddNew = _isAddNew1; txtMa.Text = BoPhanDTO.MaBP; txtTen.Text = BoPhanDTO.TenBP; txtGhiChu.Text = BoPhanDTO.ghichu; ckbConQuanLy.Checked = BoPhanDTO.ConQuanLy; if (!_isAddNew) { txtMa.Enabled = false; } }
public static BoPhanDTO SuaBoPhan(BoPhanDTO boPhanDTO) { try { QuanLyNhanSuEntities db = DataProvider.dbContext; BOPHAN boPhan = db.BOPHANs.SingleOrDefault(i => i.MaBP == boPhanDTO.MaBP); boPhan.TenBP = boPhanDTO.TenBP; db.SaveChanges(); return(boPhanDTO); } catch { return(null); } }
public string UpdateBoPhan(BoPhanDTO dtoBoPhan) { string strError = ""; if (dtoBoPhan.TenBoPhan.Trim().Equals("") == true) { strError = "Tên bộ phận không được rỗng."; } if (strError == "") { bool boolResult = dalBoPhan.UpdateBoPhan(dtoBoPhan); return("ok"); } else { return(strError); } }
private void btnXoa_Click(object sender, EventArgs e) { BoPhanDTO boPhanDTO = new BoPhanDTO(); boPhanDTO.BoPhanID = BoPhanID; DataTable dtNVBP = BoPhanBUS.Instance.LoadBoPhanFromNhanVienBoPhan(boPhanDTO); if (dtNVBP.Rows.Count > 0) { MessageBox.Show("Bạn phải xóa bản ghi trong NhanVienBoPhan"); } else { BoPhanBUS.Instance.DeleteBoPhan(boPhanDTO); Load_DL(); } Reset(); }
public static BoPhanDTO ThemBoPhan(BoPhanDTO boPhanDTO) { try { BOPHAN boPhan = new BOPHAN(); boPhan.TenBP = boPhanDTO.TenBP; QuanLyNhanSuEntities db = DataProvider.dbContext; boPhan = db.BOPHANs.Add(boPhan); db.SaveChanges(); boPhanDTO.MaBP = boPhan.MaBP; boPhanDTO.TenBP = boPhan.TenBP; boPhanDTO.SoLuong = 0; return(boPhanDTO); } catch { return(null); } }
public static bool XoaBoPhan(BoPhanDTO bophanxoa) { DataProvider p = new DataProvider(); p.Connect(); SqlParameter p0 = new SqlParameter("@MaBoPhan", SqlDbType.Int) { Value = bophanxoa.MaBoPhan }; int n = p.ExecuteNonQuery("sp_XoaBoPhan", CommandType.StoredProcedure, p0); p.Disconnect(); if (n == 0) { return(false); } return(true); }
private void btnSua_Click(object sender, EventArgs e) { _currentRowIndex = gridView1.FocusedRowHandle; if (_currentRowIndex < 0) { return; } BoPhanDTO BoPhanDTO = new BoPhanDTO() { MaBP = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["MaBP"]).ToString(), TenBP = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["TenBP"]).ToString(), ghichu = gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["GhiChu"]).ToString(), ConQuanLy = bool.Parse(gridView1.GetRowCellValue(_currentRowIndex, gridView1.Columns["ConQuanLy"]).ToString()), }; ThemBoPhan frm = new ThemBoPhan(false, BoPhanDTO); frm.ShowDialog(); hienThi(); }
private void BtnXoaBoPhan_Click(object sender, EventArgs e) { if (txtMaBoPhan.Text != "") { if (BoPhanBUL.XoaBoPhan(int.Parse(txtMaBoPhan.Text)) == true) { BoPhanDTO bp = lstBoPhan.SingleOrDefault(i => i.MaBP == int.Parse(txtMaBoPhan.Text)); lstBoPhan.Remove(bp); ReloadDataGridView(); MessageBox.Show("Xóa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Xóa thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Bạn chưa chọn bộ phận nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void BtnThemBoPhan_Click(object sender, EventArgs e) { if (txtTenBoPhan.Text != "") { BoPhanDTO bp = new BoPhanDTO(); bp.TenBP = txtTenBoPhan.Text; bp = BoPhanBUL.ThemBoPhan(bp); if (bp != null) { lstBoPhan.Add(bp); ReloadDataGridView(); MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Bạn chưa chọn bộ phận nào!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public int ThemBoPhan(BoPhanDTO boPhanDTO) { return(Core.RunSql(BoPhanDAO.Instance.ThemBoPhan(boPhanDTO))); }
public static BoPhanDTO SuaBoPhan(BoPhanDTO bp) { return(BoPhanDAL.SuaBoPhan(bp)); }
public static BoPhanDTO ThemBoPhan(BoPhanDTO bp) { return(BoPhanDAL.ThemBoPhan(bp)); }
public void UpdateBoPhan(BoPhanDTO boPhanDTO) { Core.RunSql(BoPhanDAO.Instance.UpdateBoPhan(boPhanDTO)); }
public void DeleteBoPhan(BoPhanDTO boPhanDTO) { Core.RunSql(BoPhanDAO.Instance.DeleteBoPhan(boPhanDTO)); }