private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[3] is DataGridViewImageButtonSaveColumn && e.RowIndex >= 0 && senderGrid.Columns[4] is DataGridViewImageButtonDeleteColumn) { switch (e.ColumnIndex) { case 3: TblBoPhan data = new TblBoPhan(); DataGridViewRow row = dataGridView1.Rows[e.RowIndex]; data.MaBophan = row.Cells[0].Value.ToString(); data.TenBoPhan = row.Cells[1].Value.ToString(); data.GhiChu = row.Cells[2].Value.ToString(); Add.AddBoPhan uc = new Add.AddBoPhan(data, "Cập nhật bộ phận", this); uc.ShowDialog(); break; case 4: TblBoPhan data2 = new TblBoPhan(); DataGridViewRow row2 = dataGridView1.Rows[e.RowIndex]; data2.MaBophan = row2.Cells[0].Value.ToString(); data2.TenBoPhan = row2.Cells[1].Value.ToString(); data2.GhiChu = row2.Cells[2].Value.ToString(); Delete.DeleteBoPhan uc2 = new Delete.DeleteBoPhan("Bộ phận này", data2, this); uc2.ShowDialog(); break; } } }
public DeleteBoPhan(string text, TblBoPhan bophan, Show.DanhSachBoPhan dsbp) { InitializeComponent(); this.bophan = bophan; this.dsbp = dsbp; init(); }
private void sửaBoPhanToolStrip_Click(object sender, EventArgs e) { TblBoPhan data = new TblBoPhan(); Add.AddBoPhan uc = new Add.AddBoPhan(null, "Cập nhật bộ phận", this.dsbp); uc.ShowDialog(); }
public Result <TblBoPhan> updateBoPhan(TblBoPhan instance) { //var a = AutoMapper.Mapper.Map<TblTTNVCoBan, NhanVienDTO>(instance); var result = new Result <TblBoPhan>(); var temp = connect.TblBoPhans.Where(x => x.MaBophan == instance.MaBophan).FirstOrDefault(); if (temp != null) { try { temp = instance; connect.TblBoPhans.Attach(temp); connect.Entry(temp).State = EntityState.Modified; connect.SaveChanges(); result.Success = true; result.Message = "Thành công!"; result.Data = instance; } catch (Exception e) { result.Success = false; result.Message = "Đã xảy ra lỗi khi thêm bản ghi! "; result.Data = instance; } return(result); } else { result.Success = false; result.Message = "Không tìm thấy bản ghi"; return(result); } }
public Result <TblBoPhan> addBoPhan(TblBoPhan instance) { var result = new Result <TblBoPhan>(); var temp = connect.TblBoPhans.Where(x => x.MaBophan == instance.MaBophan).FirstOrDefault(); if (temp == null) { try { connect.TblBoPhans.Add(instance); connect.SaveChanges(); result.Success = true; result.Message = "Thành công!"; result.Data = instance; } catch (Exception e) { result.Success = false; result.Message = "Đã xảy ra lỗi khi thêm bản ghi! "; result.Data = instance; } return(result); } else { result.Success = false; result.Message = "Đã tồn tại bản ghi"; result.Data = instance; return(result); } }
public AddBoPhan(TblBoPhan data, string title, Show.DanhSachBoPhan dsbp) { InitializeComponent(); btnSave.Enabled = false; this.Text = title; this.data = data; this.dsbp = dsbp; init(); }
private void btnSave_Click(object sender, EventArgs e) { TblBoPhan data = new TblBoPhan(); data.MaBophan = maBPTB.Text.ToString().Trim(); data.TenBoPhan = tenBPTB.Text.ToString().Trim(); data.GhiChu = ghiChu.Text.ToString().Trim(); if (mode == ADD) { Result <TblBoPhan> result = new BoPhanController().addBoPhan(data); if (result.Success) { this.Hide(); dsbp.getData(); MessageBox.Show(result.Message.ToString()); } else { MessageBox.Show(result.Message.ToString()); } } else if (mode == EDIT) { Result <TblBoPhan> result = new BoPhanController().updateBoPhan(data); if (result.Success) { this.Hide(); dsbp.getData(); MessageBox.Show(result.Message.ToString()); } else { MessageBox.Show(result.Message.ToString()); } } }