Esempio n. 1
0
        private void FillColumns(bool isPrinting, bool isResizing)
        {
            ODGrid        gridToFill      = isPrinting?gridMainPrint:gridMain;
            List <string> listColHeadings = new List <string>(new[] { "Chk #", "Date", "Memo", "Splits",
                                                                      "Debit" + (Accounts.DebitIsPos(_acctCur.AcctType)?"(+)":"(-)"),
                                                                      "Credit" + (Accounts.DebitIsPos(_acctCur.AcctType)?"(-)":"(+)"),
                                                                      "Balance", "Created By", "Last Edited By", "Clear" });
            Dictionary <string, Tuple <int, HorizontalAlignment> > dictColWidths = new Dictionary <string, Tuple <int, HorizontalAlignment> >();

            dictColWidths["Chk #"]          = Tuple.Create(60, HorizontalAlignment.Center);
            dictColWidths["Date"]           = Tuple.Create(75, HorizontalAlignment.Left);
            dictColWidths["Memo"]           = Tuple.Create((isPrinting?200:220), HorizontalAlignment.Left);
            dictColWidths["Splits"]         = Tuple.Create((isPrinting?200:220), HorizontalAlignment.Left);
            dictColWidths["Created By"]     = Tuple.Create(100, HorizontalAlignment.Left);
            dictColWidths["Last Edited By"] = Tuple.Create(100, HorizontalAlignment.Left);
            dictColWidths["Clear"]          = Tuple.Create(40, HorizontalAlignment.Center);
            //grid width minus scroll bar width if not printing minus width of all cols except Debit, Credit, and Balance and divide by 3
            //distribute the remaining grid width between the three cols: Debit, Credit, and Balance
            int colW = (gridToFill.Width - (isPrinting?0:19) - dictColWidths.Values.Sum(x => x.Item1)) / 3;

            dictColWidths["Debit" + (Accounts.DebitIsPos(_acctCur.AcctType)?"(+)":"(-)")]  = Tuple.Create(colW, HorizontalAlignment.Right);
            dictColWidths["Credit" + (Accounts.DebitIsPos(_acctCur.AcctType)?"(-)":"(+)")] = Tuple.Create(colW, HorizontalAlignment.Right);
            dictColWidths["Balance"] = Tuple.Create(colW, HorizontalAlignment.Right);
            if ((isPrinting || isResizing) && gridToFill.ListGridColumns != null && gridToFill.ListGridColumns.Count > 0)         //printing/resizing and cols already filled, adjust widths
            {
                Tuple <int, HorizontalAlignment> colCurTuple;
                gridToFill.ListGridColumns.ForEach(x => x.ColWidth = (dictColWidths.TryGetValue(x.Heading, out colCurTuple)?colCurTuple.Item1:x.ColWidth));
            }
            else              //if not printing/resizing or cols have not been filled, fill cols
            {
                gridToFill.ListGridColumns.Clear();
                listColHeadings.ForEach(x => gridToFill.ListGridColumns.Add(new GridColumn(Lan.g("TableJournal", x), dictColWidths[x].Item1, dictColWidths[x].Item2)));
            }
        }
 ///<summary>Need to set AccountPicked before calling this.</summary>
 private void FillAccount()
 {
     if (AccountPicked == null)
     {
         textAccount.Text = "";
         butChange.Text   = Lan.g(this, "Pick");
         labelDebit.Text  = Lan.g(this, "Debit");
         labelCredit.Text = Lan.g(this, "Credit");
         return;
     }
     //AccountCur=Accounts.ListShort[comboAccount.SelectedIndex];
     textAccount.Text = AccountPicked.Description;
     butChange.Text   = Lan.g(this, "Change");
     if (Accounts.DebitIsPos(AccountPicked.AcctType))
     {
         labelDebit.Text  = Lan.g(this, "Debit") + Lan.g(this, "(+)");
         labelCredit.Text = Lan.g(this, "Credit") + Lan.g(this, "(-)");
     }
     else
     {
         labelDebit.Text  = Lan.g(this, "Debit") + Lan.g(this, "(-)");
         labelCredit.Text = Lan.g(this, "Credit") + Lan.g(this, "(+)");
     }
 }
Esempio n. 3
0
        private void FillGrid()
        {
            if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" ||
                textDateTo.errorProvider1.GetError(textDateTo) != ""
                )
            {
                return;
            }
            DateTime dateFrom = PIn.PDate(textDateFrom.Text);
            DateTime dateTo;

            if (textDateTo.Text == "")
            {
                dateTo = DateTime.MaxValue;
            }
            else
            {
                dateTo = PIn.PDate(textDateTo.Text);
            }
            double filterAmt = 0;

            if (textAmt.errorProvider1.GetError(textAmt) == "")
            {
                filterAmt = PIn.PDouble(textAmt.Text);
            }
            JournalList = JournalEntries.GetForAccount(AccountCur.AccountNum);
            int scroll = gridMain.ScrollValue;

            gridMain.BeginUpdate();
            gridMain.Title = AccountCur.Description + " (" + Lan.g("enumAccountType", AccountCur.AcctType.ToString()) + ")";
            gridMain.Columns.Clear();
            string       str = "";
            ODGridColumn col = new ODGridColumn(Lan.g("TableJournal", "Chk #"), 60, HorizontalAlignment.Center);

            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableJournal", "Date"), 80);
            gridMain.Columns.Add(col);
            if (isPrinting)
            {
                col = new ODGridColumn(Lan.g("TableJournal", "Memo"), 200);
            }
            else
            {
                col = new ODGridColumn(Lan.g("TableJournal", "Memo"), 220);
            }
            gridMain.Columns.Add(col);
            if (isPrinting)
            {
                col = new ODGridColumn(Lan.g("TableJournal", "Splits"), 200);
            }
            else
            {
                col = new ODGridColumn(Lan.g("TableJournal", "Splits"), 220);
            }
            gridMain.Columns.Add(col);
            str = Lan.g("TableJournal", "Debit");
            if (Accounts.DebitIsPos(AccountCur.AcctType))
            {
                str += Lan.g("TableJournal", "(+)");
            }
            else
            {
                str += Lan.g("TableJournal", "(-)");
            }
            col = new ODGridColumn(str, 65, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            str = Lan.g("TableJournal", "Credit");
            if (Accounts.DebitIsPos(AccountCur.AcctType))
            {
                str += Lan.g("TableJournal", "(-)");
            }
            else
            {
                str += Lan.g("TableJournal", "(+)");
            }
            col = new ODGridColumn(str, 65, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableJournal", "Balance"), 65, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableJournal", "Clear"), 55, HorizontalAlignment.Center);
            gridMain.Columns.Add(col);
            gridMain.Rows.Clear();
            ODGridRow row;
            double    bal = 0;

            for (int i = 0; i < JournalList.Length; i++)
            {
                if (JournalList[i].DateDisplayed > dateTo)
                {
                    break;
                }
                if (AccountCur.AcctType == AccountType.Income ||
                    AccountCur.AcctType == AccountType.Expense)
                {
                    if (JournalList[i].DateDisplayed < dateFrom)
                    {
                        continue;
                        //for income and expense accounts, previous balances are not included. Only the current timespan.
                    }
                }
                if (JournalList[i].DebitAmt != 0)
                {
                    if (Accounts.DebitIsPos(AccountCur.AcctType))                     //this one is used for checking account
                    {
                        bal += JournalList[i].DebitAmt;
                    }
                    else
                    {
                        bal -= JournalList[i].DebitAmt;
                    }
                }
                if (JournalList[i].CreditAmt != 0)
                {
                    if (Accounts.DebitIsPos(AccountCur.AcctType))                     //this one is used for checking account
                    {
                        bal -= JournalList[i].CreditAmt;
                    }
                    else
                    {
                        bal += JournalList[i].CreditAmt;
                    }
                }
                if (AccountCur.AcctType == AccountType.Asset ||
                    AccountCur.AcctType == AccountType.Liability ||
                    AccountCur.AcctType == AccountType.Equity)
                {
                    if (JournalList[i].DateDisplayed < dateFrom)
                    {
                        continue;
                        //for asset, liability, and equity accounts, older entries do affect the current balance.
                    }
                }
                if (filterAmt != 0 && filterAmt != JournalList[i].CreditAmt && filterAmt != JournalList[i].DebitAmt)
                {
                    continue;
                }
                if (textFindText.Text != "" &&
                    !JournalList[i].Memo.ToUpper().Contains(textFindText.Text.ToUpper()) &&
                    !JournalList[i].CheckNumber.ToUpper().Contains(textFindText.Text.ToUpper()) &&
                    !JournalList[i].Splits.ToUpper().Contains(textFindText.Text.ToUpper()))
                {
                    continue;
                }
                row = new ODGridRow();
                row.Cells.Add(JournalList[i].CheckNumber);
                row.Cells.Add(JournalList[i].DateDisplayed.ToShortDateString());
                row.Cells.Add(JournalList[i].Memo);
                row.Cells.Add(JournalList[i].Splits);
                if (JournalList[i].DebitAmt == 0)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(JournalList[i].DebitAmt.ToString("n"));
                }
                if (JournalList[i].CreditAmt == 0)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(JournalList[i].CreditAmt.ToString("n"));
                }
                row.Cells.Add(bal.ToString("n"));
                if (JournalList[i].ReconcileNum == 0)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add("X");
                }
                row.Tag = JournalList[i].Copy();
                gridMain.Rows.Add(row);
            }
            gridMain.EndUpdate();
            gridMain.ScrollToEnd();
        }
Esempio n. 4
0
        private void FillGrid()
        {
            if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" || textDateTo.errorProvider1.GetError(textDateTo) != "")
            {
                return;
            }
            DateTime            dateFrom         = PIn.Date(textDateFrom.Text);
            DateTime            dateTo           = textDateTo.Text != ""?PIn.Date(textDateTo.Text):DateTime.MaxValue;
            double              filterAmt        = string.IsNullOrEmpty(textAmt.errorProvider1.GetError(textAmt))?PIn.Double(textAmt.Text):0;
            List <JournalEntry> listJEntries     = JournalEntries.GetForAccount(_acctCur.AccountNum);
            List <Transaction>  listTransactions = Transactions.GetManyTrans(listJEntries.Select(x => x.TransactionNum).ToList());

            //Resize grid to fit, important for later resizing
            gridMain.BeginUpdate();
            gridMain.Columns.Clear();
            gridMain.Rows.Clear();
            gridMain.Width          = isPrinting?1050:(this.Width - 16);//gridMain.Location.XPos=0 and the grid is form width - 16
            gridMain.HideScrollBars = isPrinting;
            gridMain.EndUpdate();
            gridMain.BeginUpdate();
            gridMain.Title = _acctCur.Description + " (" + Lan.g("enumAccountType", _acctCur.AcctType.ToString()) + ")";
            gridMain.Columns.Clear();
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Chk #"), 60, HorizontalAlignment.Center));
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Date"), 75));
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Memo"), isPrinting?200:220));
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Splits"), isPrinting?200:220));
            int colClearWidth = 40;          //because the "clear" column has not been added yet.
            int colUserWidth  = 100;         //because the user columns haven't been added yet.
            //if printing, total size=paper width-margins (1050), otherwise total size=gridWidth-scroll bar width of 19
            //divide remaining size, total size - grid col widths, into thirds for the debit, credit, and balance columns
            int colW = (gridMain.Width - (isPrinting?0:19) - gridMain.WidthAllColumns - colClearWidth - 2 * colUserWidth) / 3;

            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Debit" + (Accounts.DebitIsPos(_acctCur.AcctType)?"(+)":"(-)")), colW, HorizontalAlignment.Right));
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Credit" + (Accounts.DebitIsPos(_acctCur.AcctType)?"(-)":"(+)")), colW, HorizontalAlignment.Right));
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Balance"), colW, HorizontalAlignment.Right));
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Created By"), colUserWidth));
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Last Edited By"), colUserWidth));
            gridMain.Columns.Add(new ODGridColumn(Lan.g("TableJournal", "Clear"), colClearWidth, HorizontalAlignment.Center));
            gridMain.Rows.Clear();
            ODGridRow row;
            decimal   bal = 0;

            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 ODGridRow();
                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"));
                row.Cells.Add(Userods.GetName(listTransactions.FirstOrDefault(x => x.TransactionNum == jeCur.TransactionNum)?.UserNum ?? 0));
                row.Cells.Add(Userods.GetName(jeCur.SecUserNumEdit));
                row.Cells.Add(jeCur.ReconcileNum == 0?"":"X");
                row.Tag = jeCur.Copy();
                gridMain.Rows.Add(row);
            }
            gridMain.EndUpdate();
            gridMain.ScrollToEnd();
        }
Esempio n. 5
0
        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();
            }
        }