private void FillGrid() { if (textRows.errorProvider1.GetError(textRows) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return; } long userNum = 0; if (comboUser.SelectedIndex > 0) { userNum = _listUserods[comboUser.SelectedIndex - 1].UserNum; } SecurityLog[] logList = null; DateTime datePreviousFrom = PIn.Date(textDateEditedFrom.Text); DateTime datePreviousTo = DateTime.Today; if (textDateEditedTo.Text != "") { datePreviousTo = PIn.Date(textDateEditedTo.Text); } try { if (comboPermission.SelectedIndex == 0) { logList = SecurityLogs.Refresh(PIn.Date(textDateFrom.Text), PIn.Date(textDateTo.Text), Permissions.None, PatNum, userNum, datePreviousFrom, datePreviousTo, checkIncludeArchived.Checked, PIn.Int(textRows.Text)); } else { logList = SecurityLogs.Refresh(PIn.Date(textDateFrom.Text), PIn.Date(textDateTo.Text), (Permissions)Enum.Parse(typeof(Permissions), comboPermission.SelectedItem.ToString()), PatNum, userNum, datePreviousFrom, datePreviousTo, checkIncludeArchived.Checked, PIn.Int(textRows.Text)); } } catch (Exception ex) { FriendlyException.Show(Lan.g(this, "There was a problem refreshing the Audit Trail with the current filters."), ex); logList = new SecurityLog[0]; } grid.BeginUpdate(); grid.Columns.Clear(); grid.Columns.Add(new ODGridColumn(Lan.g("TableAudit", "Date"), 70, GridSortingStrategy.DateParse)); grid.Columns.Add(new ODGridColumn(Lan.g("TableAudit", "Time"), 60, GridSortingStrategy.DateParse)); grid.Columns.Add(new ODGridColumn(Lan.g("TableAudit", "Patient"), 100)); grid.Columns.Add(new ODGridColumn(Lan.g("TableAudit", "User"), 70)); grid.Columns.Add(new ODGridColumn(Lan.g("TableAudit", "Permission"), 190)); grid.Columns.Add(new ODGridColumn(Lan.g("TableAudit", "Computer"), 70)); grid.Columns.Add(new ODGridColumn(Lan.g("TableAudit", "Log Text"), 279)); grid.Columns.Add(new ODGridColumn(Lan.g("TableAudit", "Last Edit"), 100)); grid.Rows.Clear(); ODGridRow row; foreach (SecurityLog logCur in logList) { row = new ODGridRow(); row.Cells.Add(logCur.LogDateTime.ToShortDateString()); row.Cells.Add(logCur.LogDateTime.ToShortTimeString()); row.Cells.Add(logCur.PatientName); //user might be null due to old bugs. row.Cells.Add(Userods.GetUser(logCur.UserNum)?.UserName ?? "unknown"); if (logCur.PermType == Permissions.ChartModule) { row.Cells.Add("ChartModuleViewed"); } else if (logCur.PermType == Permissions.FamilyModule) { row.Cells.Add("FamilyModuleViewed"); } else if (logCur.PermType == Permissions.AccountModule) { row.Cells.Add("AccountModuleViewed"); } else if (logCur.PermType == Permissions.ImagesModule) { row.Cells.Add("ImagesModuleViewed"); } else if (logCur.PermType == Permissions.TPModule) { row.Cells.Add("TreatmentPlanModuleViewed"); } else { row.Cells.Add(logCur.PermType.ToString()); } row.Cells.Add(logCur.CompName); if (logCur.PermType != Permissions.UserQuery) { row.Cells.Add(logCur.LogText); } else { //Only display the first snipet of very long queries. User can double click to view. row.Cells.Add(logCur.LogText.Left(200, true)); row.Tag = (Action)(() => { MsgBoxCopyPaste formText = new MsgBoxCopyPaste(logCur.LogText); formText.NormalizeContent(); formText.Show(); }); } if (logCur.DateTPrevious.Year < 1880) { row.Cells.Add(""); } else { row.Cells.Add(logCur.DateTPrevious.ToString()); } //Get the hash for the audit log entry from the database and rehash to compare if (logCur.LogHash != SecurityLogHashes.GetHashString(logCur)) { row.ColorText = Color.Red; //Bad hash or no hash entry at all. This prevents users from deleting the entire hash table to make the audit trail look valid and encrypted. //historical entries will show as red. } grid.Rows.Add(row); } grid.EndUpdate(); grid.ScrollToEnd(); }
private void FillGrid(bool isPrinting = false, bool isResizing = false) { if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" || textDateTo.errorProvider1.GetError(textDateTo) != "") { return; } ODGrid gridToFill = isPrinting?gridMainPrint:gridMain; long firstVisibleTransNum = 0; if (!isPrinting && gridToFill.VisibleRows.Count > 0) //don't scroll into view if printing { firstVisibleTransNum = (long)gridToFill.VisibleRows[0].Tag; } long selectedTransNum = 0; if (!isPrinting && gridToFill.GetSelectedIndex() > -1) //no need to reselect an index if printing { selectedTransNum = gridToFill.SelectedTag <long>(); } //Resize grid to fit, important for later resizing gridToFill.BeginUpdate(); gridToFill.Title = _acctCur.Description + " (" + Lan.g("enumAccountType", _acctCur.AcctType.ToString()) + ")"; FillColumns(isPrinting, isResizing); DateTime dateFrom = PIn.Date(textDateFrom.Text); DateTime dateTo = string.IsNullOrEmpty(textDateTo.Text)?DateTime.MaxValue:PIn.Date(textDateTo.Text); double filterAmt = string.IsNullOrEmpty(textAmt.errorProvider1.GetError(textAmt))?PIn.Double(textAmt.Text):0; if (!isResizing || _listJEntries == null || _dictTransUsers == null) { _listJEntries = JournalEntries.GetForAccount(_acctCur.AccountNum); _dictTransUsers = Transactions.GetManyTrans(_listJEntries.Select(x => x.TransactionNum).ToList()) .ToDictionary(x => x.TransactionNum, x => x.UserNum); } gridToFill.ListGridRows.Clear(); GridRow row; decimal bal = 0; int firstVisibleRowIndex = -1; int selectedIndex = -1; foreach (JournalEntry jeCur in _listJEntries) { if (jeCur.DateDisplayed > dateTo) { break; } if (new[] { AccountType.Income, AccountType.Expense }.Contains(_acctCur.AcctType) && jeCur.DateDisplayed < dateFrom) { continue; //for income and expense accounts, previous balances are not included. Only the current timespan. } //DebitIsPos=true for checking acct, bal+=DebitAmt-CreditAmt bal += (Accounts.DebitIsPos(_acctCur.AcctType)?1:-1) * ((decimal)jeCur.DebitAmt - (decimal)jeCur.CreditAmt); if (new[] { AccountType.Asset, AccountType.Liability, AccountType.Equity }.Contains(_acctCur.AcctType) && jeCur.DateDisplayed < dateFrom) { continue; //for asset, liability, and equity accounts, older entries do affect the current balance. } if (filterAmt != 0 && filterAmt != jeCur.CreditAmt && filterAmt != jeCur.DebitAmt) { continue; } if (textFindText.Text != "" && new[] { jeCur.Memo, jeCur.CheckNumber, jeCur.Splits }.All(x => !x.ToUpper().Contains(textFindText.Text.ToUpper()))) { continue; } row = new GridRow(); row.Cells.Add(jeCur.CheckNumber); row.Cells.Add(jeCur.DateDisplayed.ToShortDateString()); row.Cells.Add(jeCur.Memo); row.Cells.Add(jeCur.Splits); row.Cells.Add(jeCur.DebitAmt == 0?"":jeCur.DebitAmt.ToString("n")); row.Cells.Add(jeCur.CreditAmt == 0?"":jeCur.CreditAmt.ToString("n")); row.Cells.Add(bal.ToString("n")); long userNum; row.Cells.Add(Userods.GetName(_dictTransUsers.TryGetValue(jeCur.TransactionNum, out userNum)?userNum:0)); row.Cells.Add(Userods.GetName(jeCur.SecUserNumEdit)); row.Cells.Add(jeCur.ReconcileNum == 0?"":"X"); row.Tag = jeCur.TransactionNum; gridToFill.ListGridRows.Add(row); if (firstVisibleTransNum > 0 && jeCur.TransactionNum == firstVisibleTransNum) { firstVisibleRowIndex = gridToFill.ListGridRows.Count - 1; } if (selectedTransNum > 0 && jeCur.TransactionNum == selectedTransNum) { selectedIndex = gridToFill.ListGridRows.Count - 1; } } gridToFill.EndUpdate(); if (selectedIndex > -1) { gridToFill.SetSelected(selectedIndex, true); } if (firstVisibleRowIndex > -1) { gridToFill.ScrollToIndex(firstVisibleRowIndex); } else { gridToFill.ScrollToEnd(); } }