/* public BindingList<ChucDanhDTO> LayDanhSachCombobox() { BindingList<ChucDanhDTO> danhSach = new BindingList<ChucDanhDTO>(); OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Select * From DanhMucChucDanh"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); OleDbDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { ChucDanhDTO itemDTO = new ChucDanhDTO(); itemDTO.Id = (int)dr["Id"]; itemDTO.MaChucDanh = (string)dr["MaChucDanh"]; itemDTO.TenChucDanh = (string)dr["TenChucDanh"]; itemDTO.GhiChu = (string)dr["GhiChu"]; danhSach.Add(itemDTO); } return danhSach; } */ public void Them(ChucDanhDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Insert into SysDanhMucChucDanh (MaChucDanh,TenChucDanh,GhiChu) values (?, ?, ?)"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaChucDanh", OleDbType.WChar).Value = itemDTO.MaChucDanh; cmd.Parameters.Add("@TenChucDanh", OleDbType.WChar).Value = itemDTO.TenChucDanh; cmd.Parameters.Add("@GhiChu", OleDbType.WChar).Value = itemDTO.GhiChu; cmd.ExecuteNonQuery(); cn.Close(); }
public void Sua(ChucDanhDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Update SysDanhMucChucDanh Set MaChucDanh = ?, TenChucDanh = ?, GhiChu = ? Where Id = ?"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaChucDanh", OleDbType.WChar).Value = itemDTO.MaChucDanh; cmd.Parameters.Add("@TenChucDanh", OleDbType.WChar).Value = itemDTO.TenChucDanh; cmd.Parameters.Add("@GhiChu", OleDbType.WChar).Value = itemDTO.GhiChu; cmd.Parameters.Add("@Id", OleDbType.Numeric).Value = itemDTO.Id; cmd.ExecuteNonQuery(); cn.Close(); }
private void gvDanhMucChuDanh_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { if (gvDanhMucChuDanh.FocusedRowHandle > -1) { try { ChucDanhDTO itemDTO = new ChucDanhDTO(); ChucDanhBUS itemBUS = new ChucDanhBUS(); itemDTO.MaChucDanh = gvDanhMucChuDanh.GetFocusedRowCellValue("MaChucDanh").ToString(); itemDTO.TenChucDanh = gvDanhMucChuDanh.GetFocusedRowCellValue("TenChucDanh").ToString(); itemDTO.GhiChu = gvDanhMucChuDanh.GetFocusedRowCellValue("GhiChu").ToString(); itemDTO.Id = int.Parse(gvDanhMucChuDanh.GetFocusedRowCellValue("Id").ToString()); if (this.flagThem && gvDanhMucChuDanh.FocusedRowHandle == gvDanhMucChuDanh.RowCount - 2) { if (itemDTO.MaChucDanh.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.LayDanhSachChucDanh(); } }
public BindingList<ChucDanhDTO> LayDanhSach() { BindingList<ChucDanhDTO> danhSach = new BindingList<ChucDanhDTO>(); OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Select * From SysDanhMucChucDanh"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); OleDbDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { ChucDanhDTO itemDTO = new ChucDanhDTO(); itemDTO.Id = (int)dr["Id"]; itemDTO.MaChucDanh = (string)dr["MaChucDanh"]; itemDTO.TenChucDanh = (string)dr["TenChucDanh"]; itemDTO.GhiChu = (string)dr["GhiChu"]; danhSach.Add(itemDTO); } return danhSach; }
public void Them(ChucDanhDTO itemDTO) { ChucDanhDAO itemDAO = new ChucDanhDAO(); itemDAO.Them(itemDTO); }
public void Sua(ChucDanhDTO itemDTO) { ChucDanhDAO itemDAO = new ChucDanhDAO(); itemDAO.Sua(itemDTO); }