private void gvDanhMucChucNang_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { if (gvDanhMucChucNang.FocusedRowHandle > -1) { try { ChucNangDTO itemDTO = new ChucNangDTO(); ChucNangBUS itemBUS = new ChucNangBUS(); itemDTO.MaChucNang = gvDanhMucChucNang.GetFocusedRowCellValue("MaChucNang").ToString(); itemDTO.TenChucNang = gvDanhMucChucNang.GetFocusedRowCellValue("TenChucNang").ToString(); itemDTO.IdPhanHe = int.Parse(gvDanhMucChucNang.GetFocusedRowCellValue("IdPhanHe").ToString()); itemDTO.TenForm = gvDanhMucChucNang.GetFocusedRowCellValue("TenForm").ToString(); itemDTO.Id = int.Parse(gvDanhMucChucNang.GetFocusedRowCellValue("Id").ToString()); if (this.flagThem && gvDanhMucChucNang.FocusedRowHandle == gvDanhMucChucNang.RowCount - 2) { if (itemDTO.MaChucNang.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.LayDanhSachChucNang(); } }
public void Sua(ChucNangDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Update SysDanhMucChucNang Set MaChucNang = ?, TenChucNang = ?, IdPhanHe = ? Where Id = ?"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaChucNang", OleDbType.WChar).Value = itemDTO.MaChucNang; cmd.Parameters.Add("@TenChucNang", OleDbType.WChar).Value = itemDTO.TenChucNang; cmd.Parameters.Add("@IdPhanHe", OleDbType.Numeric).Value = itemDTO.IdPhanHe; cmd.Parameters.Add("@Id", OleDbType.Numeric).Value = itemDTO.Id; cmd.ExecuteNonQuery(); cn.Close(); }
public void Them(ChucNangDTO itemDTO) { OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Insert into SysDanhMucChucNang (MaChucNang, TenChucNang, IdPhanHe, TenForm) values (?, ?, ?, ?)"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); cmd.Parameters.Add("@MaChucNang", OleDbType.WChar).Value = itemDTO.MaChucNang; cmd.Parameters.Add("@TenChucNang", OleDbType.WChar).Value = itemDTO.TenChucNang; cmd.Parameters.Add("@IdPhanHe", OleDbType.Numeric).Value = itemDTO.IdPhanHe; cmd.Parameters.Add("@TenForm", OleDbType.WChar).Value = itemDTO.TenForm; cmd.ExecuteNonQuery(); cn.Close(); }
public BindingList<ChucNangDTO> LayDanhSach() { BindingList<ChucNangDTO> danhSach = new BindingList<ChucNangDTO>(); OleDbConnection cn; cn = DataProvider.KetNoi(); string strSQL; strSQL = "Select * From SysDanhMucChucNang"; OleDbCommand cmd = new OleDbCommand(strSQL, cn); OleDbDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { ChucNangDTO itemDTO = new ChucNangDTO(); itemDTO.Id = (int)dr["Id"]; itemDTO.MaChucNang = (string)dr["MaChucNang"]; itemDTO.TenChucNang = (string)dr["TenChucNang"]; itemDTO.IdPhanHe = (int)dr["IdPhanHe"]; itemDTO.TenForm = (string)dr["TenForm"]; danhSach.Add(itemDTO); } return danhSach; }
public void Them(ChucNangDTO itemDTO) { ChucNangDAO itemDAO = new ChucNangDAO(); itemDAO.Them(itemDTO); }
public void Sua(ChucNangDTO itemDTO) { ChucNangDAO itemDAO = new ChucNangDAO(); itemDAO.Sua(itemDTO); }