示例#1
0
 private void GridCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
 {
     if (!isManualEditCommit)
     {
         isManualEditCommit = true;
         DataGridRow row       = e.Row;
         DataRowView row_items = (DataRowView)row.Item;
         if (e.Column.Header.ToString() == "Category")
         {
             ComboBox           cb           = e.EditingElement as ComboBox;
             string             t            = Convert.ToString(cb.SelectedItem);
             InvestmentCategory new_category = new InvestmentCategory();
             new_category.Category = t;
             new_category.Keyword  = row_items.Row.ItemArray[1].ToString().Replace("'", "''");
             new_category.UpdateDefinition(new_category.Keyword, row_items.Row.ItemArray[1] != DBNull.Value && !string.IsNullOrWhiteSpace(t));
             FillDataGrid(null);
         }
         else
         {
             DataGridInvestments.CommitEdit();
             DataGridInvestments.CommitEdit();
         }
         isManualEditCommit = false;
     }
 }
示例#2
0
        public void FillDataGrid(string date, string asset = null)
        {
            //filling datagrid investments
            string   selected_person    = "";
            DateTime date_selected_to   = new DateTime();
            DateTime date_selected_from = new DateTime();

            Dispatcher.Invoke(() =>
            {
                selected_person = HoldersItems.Where(r => r.IsChecked == true).Select(x => x.HolderName).First();
                if (date == null)
                {
                    date_selected_to   = Convert.ToDateTime(date_month_to.SelectedDate);
                    date_selected_from = Convert.ToDateTime(date_month_to.SelectedDate).AddMonths(-3);
                }
                else
                {
                    DateTime.TryParseExact(date, "MMM yy", new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.None, out date_selected_to);
                    date_selected_from = Convert.ToDateTime(date_month_from.SelectedDate);
                }
            });
            DataTable dt_investments  = BrokerageAsset.GetMonthInvestments(selected_person, date_selected_to);
            DataTable dt_transactions = BrokerageTransaction.GetHistoricalTransactions(asset, selected_person, date_selected_from, date_selected_to.AddMonths(1).AddDays(-1));

            if (dt_transactions.Rows.Count > 0)
            {
                dt_transactions = dt_transactions.AsEnumerable().OrderByDescending(r => r["date"]).CopyToDataTable();
            }
            Dispatcher.Invoke(() =>
            {
                if (dt_investments.Rows.Count > 0)
                {
                    date_grid.Text = "Date: " + dt_investments.Rows[0].Field <DateTime>("date").ToShortDateString();
                }
                else
                {
                    date_grid.Text = "";
                }
                DataGridInvestments.CommitEdit();
                DataGridInvestments.CommitEdit();
                DataGridInvestments.DataContext = dt_investments;

                DataGridTransactions.CommitEdit();
                DataGridTransactions.CommitEdit();
                DataGridTransactions.DataContext = dt_transactions;
            });
        }