Esempio n. 1
0
        ///<summary>Creates a list box under given textBox filled with filtered list of recommended emails based on textBox.Text values.
        ///Key is used to navigate list indirectly.</summary>
        private void RecommendedEmailHelper(ODtextBox textBox, Keys key)
        {
            if (_listHistoricContacts.Count == 0)           //No recommendations to show.
            {
                return;
            }
            //The passed in textBox's tag points to the grid of options.
            //The created grid's tag will point to the textBox.
            if (textBox.Tag == null)
            {
                textBox.Tag = new ODGrid()
                {
                    TranslationName = "",
                };
            }
            ODGrid gridContacts = (ODGrid)textBox.Tag;
            //textBox.Text could contain multiple email addresses.
            //We only want to grab the last few characters as the filter string.
            //[email protected],[email protected],emai => "emai" is the filter.
            //When there is no comma, will just use what is currently in the textbox.
            string emailFilter = textBox.Text.ToLower().Split(',').Last();

            if (emailFilter.Length < 2)          //Require at least 2 characters for now.
            {
                gridContacts.Hide();             //Even if not showing .Hide() won't harm anything.
                textBox.Tag = null;              //Reset tag so that initial logic runs again.
                return;
            }
            #region Key navigation and filtering
            switch (key)
            {
            case Keys.Enter:                    //Select currently highlighted recommendation.
                if (gridContacts.Rows.Count == 0)
                {
                    return;
                }
                CloseAndSetRecommendedContacts(gridContacts, true);
                return;

            case Keys.Up:                    //Navigate the recommendations from the textBox indirectly.
                if (gridContacts.Rows.Count == 0)
                {
                    return;
                }
                //gridContacts is multi select. We are navigating 1 row at a time so clear and set the selected index.
                int index = Math.Max(gridContacts.GetSelectedIndex() - 1, 0);
                gridContacts.SetSelected(false);
                gridContacts.SetSelected(new int[] { index }, true);
                gridContacts.ScrollToIndex(index);
                break;

            case Keys.Down:                    //Navigate the recommendations from the textBox indirectly.
                if (gridContacts.Rows.Count == 0)
                {
                    return;
                }
                //gridContacts is multi select. We are navigating 1 row at a time so clear and set the selected index.
                index = Math.Min(gridContacts.GetSelectedIndex() + 1, gridContacts.Rows.Count - 1);
                gridContacts.SetSelected(false);
                gridContacts.SetSelected(new int[] { index }, true);
                gridContacts.ScrollToIndex(index);
                break;

            default:
                #region Filter recommendations
                List <string> listFilteredContacts = _listHistoricContacts.FindAll(x => x.ToLower().Contains(emailFilter.ToLower()));
                if (listFilteredContacts.Count == 0)
                {
                    gridContacts.Hide();                         //No options to show so make sure and hide the list box
                    textBox.Tag = null;                          //Reset tag.
                    return;
                }
                listFilteredContacts.Sort();
                gridContacts.BeginUpdate();
                if (gridContacts.Columns.Count == 0)                       //First time loading.
                {
                    gridContacts.Columns.Add(new ODGridColumn());
                }
                gridContacts.Rows.Clear();
                foreach (string email in listFilteredContacts)
                {
                    ODGridRow row = new ODGridRow(email);
                    row.Tag = email;
                    gridContacts.Rows.Add(row);
                }
                gridContacts.EndUpdate();
                gridContacts.SetSelected(0, true);                       //Force a selection.
                #endregion
                break;
            }
            #endregion
            if (gridContacts.Tag != null)           //Already initialized
            {
                return;
            }
            //When the text box losses focus, we close/hide the grid.
            //TextBox_LostFocus event fires after the EmailAuto_Click event.
            textBox.Leave += TextBox_LostFocus;
            #region Grid Init
            gridContacts.HeaderHeight  = 0;
            gridContacts.SelectionMode = GridSelectionMode.MultiExtended;
            gridContacts.MouseClick   += EmailAuto_Click;
            gridContacts.Tag           = textBox;
            gridContacts.TitleHeight   = 0;
            gridContacts.Parent        = this;
            gridContacts.BringToFront();
            Point menuPosition = textBox.Location;
            menuPosition.X       += 10;
            menuPosition.Y       += textBox.Height - 1;
            gridContacts.Location = menuPosition;
            gridContacts.Width    = (int)(textBox.Width * 0.75);
            gridContacts.SetSelected(0, true);
            #endregion
            gridContacts.Show();
        }
Esempio n. 2
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();
            }
        }