private void DisplayEntries() { Diagnostics.StartTimer("ViewJournal.Refresh"); List<short> typeIDs = new List<short>(); DateTime startDate, endDate; typeIDs.Add((short)cmbType.SelectedValue); string nameProfile = ""; if (!txtName.Text.Equals("")) { nameProfile = "%" + txtName.Text + "%"; } Cursor = Cursors.WaitCursor; try { if (_allowRefresh) { long ownerID = 0; if (cmbOwner.SelectedValue != null && !chkIngoreOwner.Checked) { CharCorp data = (CharCorp)cmbOwner.SelectedValue; ownerID = data.corp ? data.characterObj.CorpID : data.characterObj.CharID; } int walletID = 0; if (cmbWallet.SelectedValue != null && !chkIgnoreWallet.Checked) { walletID = (int)cmbWallet.SelectedValue; } _accessParams = new List<FinanceAccessParams>(); if (ownerID == 0) { foreach (long id in _possibleOwners) { _accessParams.Add(new FinanceAccessParams(id)); } } else { List<short> wallets = new List<short>(); if (walletID != 0) { wallets.Add((short)walletID); } _accessParams.Add(new FinanceAccessParams(ownerID, wallets)); } startDate = dtpStartDate.Value.ToUniversalTime(); endDate = dtpEndDate.Value.ToUniversalTime(); //ListSortDirection sortDirection = ListSortDirection.Descending; //DataGridViewColumn sortColumn = journalDataGridView.SortedColumn; //if (journalDataGridView.SortOrder == SortOrder.Ascending) sortDirection = ListSortDirection.Ascending; List<SortInfo> sortinfo = journalDataGridView.GridSortInfo; Diagnostics.StartTimer("ViewJournal.Refresh.Load"); _entries = Journal.LoadEntries(_accessParams, typeIDs, startDate, endDate, nameProfile); Diagnostics.StopTimer("ViewJournal.Refresh.Load"); _journalBindingSource.DataSource = _entries; //journalDataGridView.AutoResizeColumns(); //journalDataGridView.AutoResizeRows(); //if (sortColumn != null) //{ // journalDataGridView.Sort(sortColumn, sortDirection); //} //else //{ // journalDataGridView.Sort(DateColumn, ListSortDirection.Descending); //} if (sortinfo.Count == 0) { DataGridViewColumn column = journalDataGridView.Columns["DateColumn"]; sortinfo.Add(new SortInfo(column.Index, column.DataPropertyName)); } journalDataGridView.GridSortInfo = sortinfo; Text = "Viewing " + _journalBindingSource.Count + " entries"; Diagnostics.StopTimer("ViewJournal.Refresh"); Diagnostics.StopTimer("ViewJournal.Load"); Diagnostics.StopTimer("ViewJournal.Load.Part4"); Diagnostics.DisplayDiag( "Time to refresh: " + Diagnostics.GetRunningTime("ViewJournal.Refresh").ToString() + "\r\nData load time: " + Diagnostics.GetRunningTime("ViewJournal.Refresh.Load").ToString() + "\r\n\tDatabase access time: " + Diagnostics.GetRunningTime("Journal.LoadEntries.Database").ToString() + "\r\n\tJournal list build time: " + Diagnostics.GetRunningTime("Journal.LoadEntries.BuildList").ToString()); Diagnostics.StartTimer("ViewJournal.Load"); Diagnostics.StartTimer("ViewJournal.Load.Part4"); } } finally { Cursor = Cursors.Default; } }
private void ViewJournal_Load(object sender, EventArgs e) { try { Diagnostics.ResetAllTimers(); Diagnostics.StartTimer("ViewJournal.Load"); Diagnostics.StartTimer("ViewJournal.Load.Part1"); _entries = new JournalList(); _journalBindingSource = new BindingSource(); _journalBindingSource.DataSource = _entries; DataGridViewCellStyle style = new DataGridViewCellStyle(AmountColumn.DefaultCellStyle); style.Format = IskAmount.FormatString(); AmountColumn.DefaultCellStyle = style; DataGridViewCellStyle style2 = new DataGridViewCellStyle(BalanceColumn.DefaultCellStyle); style2.Format = IskAmount.FormatString(); BalanceColumn.DefaultCellStyle = style2; journalDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; journalDataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; journalDataGridView.DataSource = _journalBindingSource; IDColumn.DataPropertyName = "Id"; DateColumn.DataPropertyName = "Date"; TypeColumn.DataPropertyName = "Type"; OwnerIsSenderColumn.DataPropertyName = "OwnerIsSender"; Owner1Column.DataPropertyName = "Sender"; OwnerID1Column.DataPropertyName = "SenderID"; Owner2Column.DataPropertyName = "Reciever"; OwnerID2Column.DataPropertyName = "RecieverID"; ArgIDColumn.DataPropertyName = "ArgID"; ArgNameColumn.DataPropertyName = "ArgName"; AmountColumn.DataPropertyName = "Amount"; BalanceColumn.DataPropertyName = "Balance"; ReasonColumn.DataPropertyName = "Reason"; Owner1CorpColumn.DataPropertyName = "SenderCorp"; Owner2CorpColumn.DataPropertyName = "RecieverCorp"; Owner1WalletColumn.DataPropertyName = "SenderWallet"; Owner2WalletColumn.DataPropertyName = "RecieverWallet"; UserAccount.Settings.GetColumnWidths(this.Name, journalDataGridView); dtpEndDate.Value = DateTime.Now; dtpStartDate.Value = DateTime.Now.AddDays(-2); dtpEndDate.KeyDown += new KeyEventHandler(dtpEndDate_KeyDown); dtpEndDate.Leave += new EventHandler(dtpEndDate_Leave); dtpStartDate.KeyDown += new KeyEventHandler(dtpStartDate_KeyDown); dtpStartDate.Leave += new EventHandler(dtpStartDate_Leave); Diagnostics.StopTimer("ViewJournal.Load.Part1"); Diagnostics.StartTimer("ViewJournal.Load.Part2"); List<CharCorpOption> charcorps = UserAccount.CurrentGroup.GetCharCorpOptions(APIDataType.Journal); _possibleOwners = new List<long>(); foreach (CharCorpOption chop in charcorps) { _possibleOwners.Add(chop.Corp ? chop.CharacterObj.CorpID : chop.CharacterObj.CharID); } _accessParams = new List<FinanceAccessParams>(); foreach (long id in _possibleOwners) { _accessParams.Add(new FinanceAccessParams(id)); } cmbOwner.DisplayMember = "Name"; cmbOwner.ValueMember = "Data"; charcorps.Sort(); cmbOwner.DataSource = charcorps; cmbOwner.SelectedValue = 0; cmbOwner.Enabled = false; Diagnostics.StopTimer("ViewJournal.Load.Part2"); Diagnostics.StartTimer("ViewJournal.Load.Part3"); EMMADataSet.JournalRefTypesDataTable types = JournalRefTypes.GetTypesByJournal(_accessParams); EMMADataSet.JournalRefTypesRow newType = types.NewJournalRefTypesRow(); newType.ID = 0; newType.RefName = "All Types"; types.AddJournalRefTypesRow(newType); BindingSource typesSource = new BindingSource(); typesSource.DataSource = types; typesSource.Sort = "RefName"; cmbType.DisplayMember = "RefName"; cmbType.ValueMember = "ID"; cmbType.DataSource = typesSource; cmbType.SelectedValue = 0; Diagnostics.StopTimer("ViewJournal.Load.Part3"); cmbType.SelectedIndexChanged += new EventHandler(cmbType_SelectedIndexChanged); cmbOwner.SelectedIndexChanged += new EventHandler(cmbOwner_SelectedIndexChanged); chkIngoreOwner.Checked = true; chkIngoreOwner.CheckedChanged += new EventHandler(chkIngoreOwner_CheckedChanged); cmbWallet.SelectedIndexChanged += new EventHandler(cmbWallet_SelectedIndexChanged); DisplayWallets(); chkIgnoreWallet.CheckedChanged += new EventHandler(chkIgnoreWallet_CheckedChanged); txtName.KeyDown += new KeyEventHandler(txtName_KeyDown); txtName.Leave += new EventHandler(txtName_Leave); Diagnostics.StartTimer("ViewJournal.Load.Part4"); this.FormClosing += new FormClosingEventHandler(ViewJournal_FormClosing); DisplayEntries(); Diagnostics.StopTimer("ViewJournal.Load.Part4"); Diagnostics.StopTimer("ViewJournal.Load"); Diagnostics.DisplayDiag( "Total form load time: " + Diagnostics.GetRunningTime("ViewJournal.Load").ToString() + "\r\nSplit time 1: " + Diagnostics.GetRunningTime("ViewJournal.Load.Part1").ToString() + "\r\nSplit time 2: " + Diagnostics.GetRunningTime("ViewJournal.Load.Part2").ToString() + "\r\nSplit time 3: " + Diagnostics.GetRunningTime("ViewJournal.Load.Part3").ToString() + "\r\nSplit time 4: " + Diagnostics.GetRunningTime("ViewJournal.Load.Part4").ToString()); } catch (Exception ex) { // Creating new EMMAexception will cause error to be logged. EMMAException emmaex = ex as EMMAException; if (emmaex == null) { emmaex = new EMMAException(ExceptionSeverity.Critical, "Error setting up journal form", ex); } MessageBox.Show("Problem setting up journal view.\r\nCheck " + Globals.AppDataDir + "Logging\\ExceptionLog.txt" + " for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static JournalList LoadEntries(List<FinanceAccessParams> accessParams, List<short> typeIDs, DateTime startDate, DateTime endDate, string nameProfile) { JournalList retVal = new JournalList(); EMMADataSet.JournalDataTable table = LoadEntriesData(accessParams, typeIDs, startDate, endDate, nameProfile); Diagnostics.StartTimer("Journal.LoadEntries.BuildList"); foreach (EMMADataSet.JournalRow row in table) { // We need to build the journal rows differently depending on who the owner is... long sOwner = 0, rOwner = 0; foreach (FinanceAccessParams access in accessParams) { if ((access.OwnerID == row.SenderID && sOwner == 0) || access.OwnerID == row.SCorpID) { sOwner = access.OwnerID; } if ((access.OwnerID == row.RecieverID && rOwner == 0) || access.OwnerID == row.RCorpID) { rOwner = access.OwnerID; } } if (rOwner != 0) { retVal.Add(new JournalEntry(row, rOwner)); } if (sOwner != 0) { retVal.Add(new JournalEntry(row, sOwner)); } } Diagnostics.StopTimer("Journal.LoadEntries.BuildList"); return retVal; }