public void Them(PhanHeDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Insert into SysDanhMucPhanHe (MaPhanHe,TenPhanHe) values (?, ?)"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaPhanHe", OleDbType.WChar).Value = itemDTO.MaPhanHe; cmd.Parameters.Add("@TenPhanHe", OleDbType.WChar).Value = itemDTO.TenPhanHe; cmd.ExecuteNonQuery(); cn.Close(); }
public void Sua(PhanHeDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Update SysDanhMucPhanHe Set MaPhanHe = ?, TenPhanHe = ? Where Id = ?"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaPhanHe", OleDbType.WChar).Value = itemDTO.MaPhanHe; cmd.Parameters.Add("@TenPhanHe", OleDbType.WChar).Value = itemDTO.TenPhanHe; cmd.Parameters.Add("@Id", OleDbType.Numeric).Value = itemDTO.Id; cmd.ExecuteNonQuery(); cn.Close(); }
private void gvDanhMucPhanHe_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { if (gvDanhMucPhanHe.FocusedRowHandle > -1) { try { PhanHeDTO itemDTO = new PhanHeDTO(); PhanHeBUS itemBUS = new PhanHeBUS(); itemDTO.MaPhanHe = gvDanhMucPhanHe.GetFocusedRowCellValue("MaPhanHe").ToString(); itemDTO.TenPhanHe = gvDanhMucPhanHe.GetFocusedRowCellValue("TenPhanHe").ToString(); itemDTO.Id = int.Parse(gvDanhMucPhanHe.GetFocusedRowCellValue("Id").ToString()); if (this.flagThem && gvDanhMucPhanHe.FocusedRowHandle == gvDanhMucPhanHe.RowCount - 2) { if (itemDTO.MaPhanHe.Length > 0) { DialogResult hopThoai = MessageBox.Show("Bạn chắc chắn muốn thêm mới?", "Thêm mới", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (hopThoai == DialogResult.Yes) { itemBUS.Them(itemDTO); this.flagThem = false; } } else { MessageBox.Show("Bạn chưa nhập mã!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { DialogResult hopThoai = MessageBox.Show("Bạn chắc chắn muốn cập nhật?", "Cập nhật", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (hopThoai == DialogResult.Yes) { itemBUS.Sua(itemDTO); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } this.LayDanhSachPhanHe(); } }
public BindingList<PhanHeDTO> LayDanhSach() { BindingList<PhanHeDTO> danhSach = new BindingList<PhanHeDTO>(); OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Select * From SysDanhMucPhanHe"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); OleDbDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { PhanHeDTO itemDTO = new PhanHeDTO(); itemDTO.Id = (int)dr["Id"]; itemDTO.MaPhanHe = (string)dr["MaPhanHe"]; itemDTO.TenPhanHe = (string)dr["TenPhanHe"]; danhSach.Add(itemDTO); } return danhSach; }
public void Them(PhanHeDTO itemDTO) { PhanHeDAO itemDAO = new PhanHeDAO(); itemDAO.Them(itemDTO); }
public void Sua(PhanHeDTO itemDTO) { PhanHeDAO itemDAO = new PhanHeDAO(); itemDAO.Sua(itemDTO); }