示例#1
0
        /// <summary>
        /// Update list of plans for current month
        /// </summary>
        private void updateMonthPlans()
        {
            DateTime start = new DateTime(DateTime.Now.Date.Year, DateTime.Now.Month, 1);
            DateTime end = start.AddMonths(1).AddDays(-1);
            double   monthIncome = 0, monthSpending = 0;
            bool     datePassed    = true;
            bool     noDatesPassed = true;

            dgvPlans.Rows.Clear();
            foreach (MoneyDataKeeper.ActivePlannedTransactionEntry entry in keeper.GetActivePlannedTransactions(start, end).OrderBy(o => (o.Date)))
            {
                Image  image;
                Color  textColor   = Color.Black;
                Color  backColor   = Color.White;
                String typeToolTip = String.Empty;

                if (keeper.IsPlannedTransactionImplemented(entry.PlannedTransaction, entry.Date))
                {
                    image       = entry.PlannedTransaction.TransactionTypeRow.IsIncome ? Properties.Resources.coins : Properties.Resources.basket;
                    typeToolTip = Resources.Labels.PlanImplementedToolTip;
                    textColor   = Color.DarkGreen;
                    backColor   = ControlPaint.LightLight(Color.LightGreen);
                }
                else if (entry.Date >= DateTime.Now.Date)
                {
                    image       = entry.PlannedTransaction.TransactionTypeRow.IsIncome ? Properties.Resources.coins_add : Properties.Resources.basket_add;
                    typeToolTip = Resources.Labels.PlanNotImplementedYetToolTip;
                    //textColor = Color.DarkBlue;
                    //backColor = ControlPaint.LightLight(Color.LightBlue);
                }
                else
                {
                    image       = entry.PlannedTransaction.TransactionTypeRow.IsIncome ? Properties.Resources.coins_delete : Properties.Resources.basket_delete;
                    typeToolTip = Resources.Labels.PlanNotImplementedToolTip;
                    if (!entry.PlannedTransaction.IsAggregated)
                    {
                        textColor = Color.DarkRed;
                        backColor = ControlPaint.LightLight(Color.LightCoral);
                    }
                }

                if (entry.PlannedTransaction.TransactionTypeRow.IsIncome)
                {
                    monthIncome += entry.PlannedTransaction.Amount * entry.PlannedTransaction.CurrenciesRow.ExchangeRate;
                }
                else
                {
                    monthSpending += entry.PlannedTransaction.Amount * entry.PlannedTransaction.CurrenciesRow.ExchangeRate;
                }

                int j = dgvPlans.Rows.Add(entry.Date.Equals(DateTime.MaxValue) ? String.Empty : entry.Date.ToShortDateString(), image, entry.AmountWithCurrency, entry.PlannedTransaction.Title);

                //dgvPlans.Rows[j].DefaultCellStyle.ForeColor = textColor;
                dgvPlans.Rows[j].DefaultCellStyle.BackColor          = backColor;
                dgvPlans.Rows[j].DefaultCellStyle.SelectionForeColor = textColor;
                //dgvPlans.Rows[j].DefaultCellStyle.SelectionBackColor = textColor;

                dgvPlans.Rows[j].Tag = entry.PlannedTransaction;

                dgvPlans.Rows[j].Cells[dgvcPlansDate.Name].ToolTipText            = entry.FullTitle;
                dgvPlans.Rows[j].Cells[dgvcPlansTransactionType.Name].ToolTipText = typeToolTip;
                dgvPlans.Rows[j].Cells[dgvcPlansAmount.Name].ToolTipText          = entry.FullTitle;
                dgvPlans.Rows[j].Cells[dgvcPlansTitle.Name].ToolTipText           = entry.FullTitle;

                // put divider between past and future dates in plan list
                if ((datePassed) && (entry.Date > DateTime.Now))
                {
                    if (j > 0)
                    {
                        dgvPlans.Rows[j - 1].DividerHeight++;
                    }
                    datePassed = false;
                }

                // put divider between plans without date
                if ((noDatesPassed) && (entry.Date.Equals(DateTime.MaxValue)))
                {
                    if (j > 0)
                    {
                        dgvPlans.Rows[j - 1].DividerHeight++;
                    }
                    noDatesPassed = false;
                }
            }
            dgvcPlansDate.AutoSizeMode   = DataGridViewAutoSizeColumnMode.AllCells;
            dgvcPlansAmount.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
        }