private void dgItems_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { _Item = senderGrid.Rows[e.RowIndex].DataBoundItem as BankData.Bank; if (_Item != null) { EditItem(); LoadAuditItem(_Item); } } }
private void LoadAuditItem(BankData.Bank dataItem) { _AuditData = _Context.BankAuditSet.Include(a => a.User).Where(a => a.BankId == dataItem.id).OrderByDescending(a => a.AuditTimeStamp).ToList(); BindAuditGrid(); }
private void btnSave_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(tbName.Text)) { Controller.HandleError("Name is required", "Validation Error"); return; } var user = _Context.tblUsers.Single(a => a.id == userid); if (_Item == null) { _Item = new BankData.Bank(); _Context.BankSet.Add(_Item); } var auditTimeStamp = DateTime.Now; if (_Item.Name != tbName.Text) { _Context.BankAuditSet.Add(new BankData.BankAudit() { Bank = _Item, User = user, UserId = user.id, FieldName = "Name", OldValue = _Item.Name, NewValue = tbName.Text, AuditTimeStamp = auditTimeStamp }); _Item.Name = tbName.Text; } if (_Item.BranchName != tbBranchName.Text) { _Context.BankAuditSet.Add(new BankData.BankAudit() { Bank = _Item, User = user, UserId = user.id, FieldName = "BranchName", OldValue = _Item.BranchName, NewValue = tbBranchName.Text, AuditTimeStamp = auditTimeStamp }); _Item.BranchName = tbBranchName.Text; } if (_Item.BranchCode != tbBranchCode.Text) { _Context.BankAuditSet.Add(new BankData.BankAudit() { Bank = _Item, User = user, UserId = user.id, FieldName = "BranchCode", OldValue = _Item.BranchCode, NewValue = tbBranchCode.Text, AuditTimeStamp = auditTimeStamp }); _Item.BranchCode = tbBranchCode.Text; } if (_Item.IsActive != cbActive.Checked) { _Context.BankAuditSet.Add(new BankData.BankAudit() { Bank = _Item, User = user, UserId = user.id, FieldName = "IsActive", OldValue = _Item.IsActive.ToString(), NewValue = cbActive.Checked.ToString(), AuditTimeStamp = auditTimeStamp }); _Item.IsActive = cbActive.Checked; } try { bool isNew = _Item.id == 0; _Context.SaveChanges(); if (isNew) { _Data.Insert(0, _Item); } BindDataGrid(); GotoReadOnly(); } catch (DbUpdateException) { Controller.HandleError("Possible duplicate record detected", "Database Error"); } catch (Exception ex2) { Controller.HandleError(ex2.Message); } }
private void btnNew_Click(object sender, EventArgs e) { _Item = null; GotoEditable(); }