//------------------------------------------------------------------------------------------- public void OFXPreview_Click(object sender, EventArgs e) { ClearError(); using (WeavverEntityContainer data = new WeavverEntityContainer()) { Accounting_OFXSettings ofxSettings = (from x in data.Accounting_OFXSettings where x.AccountId == new Guid(OFXAccounts.SelectedValue) select x).FirstOrDefault(); if (ofxSettings != null) { Accounting_Accounts acct = (from x in data.Accounting_Accounts where x.Id == new Guid(OFXAccounts.SelectedValue) select x).FirstOrDefault(); List <Accounting_OFXLedgerItem> items = ofxSettings.GetRemoteLedgerItems(DateTime.Parse(OFXStartDate.Text), DateTime.Parse(OFXEndDate.Text)); Session["Import_Transactions"] = items; List <Accounting_LedgerItems> LedgerItemsData = new List <Accounting_LedgerItems>(); foreach (var item in items) { LedgerItemsData.Add(item.LedgerItem); } var sortedItems = LedgerItemsData.OrderByDescending(x => x.PostAt); TransactionsDetected.DataSource = sortedItems; TransactionsDetected.DataBind(); LedgerItems.Visible = true; // totals var credits = items.Where(x => x.LedgerItem.Amount > 0).Sum(x => x.LedgerItem.Amount); var debits = items.Where(x => x.LedgerItem.Amount < 0).Sum(x => x.LedgerItem.Amount); DetectedTotal.Text = items.Count.ToString(); if (credits.HasValue) { TotalCredits.Text = String.Format("{0,10:C}", credits.Value); } if (debits.HasValue) { TotalDebits.Text = String.Format("{0,10:C}", debits.Value); } } } }
//------------------------------------------------------------------------------------------- protected void OFXImport_Click(object sender, EventArgs e) { List <Accounting_OFXLedgerItem> PreviewLedgerItems = (List <Accounting_OFXLedgerItem>)Session["Import_Transactions"]; using (WeavverEntityContainer data = new WeavverEntityContainer()) { for (int i = 0; i < TransactionsDetected.Items.Count; i++) { Guid rowId = new Guid(TransactionsDetected.Items[i].Cells[0].Text); CheckBox importRow = (CheckBox)FindControlRecursive(TransactionsDetected.Items[i].Cells[1], "ImportRow"); if (importRow == null || !importRow.Checked) { continue; } // Load from safe server side dataset var item = (from y in PreviewLedgerItems where y.LedgerItem.Id == rowId select y).First(); TextBox memoField = (TextBox)FindControlRecursive(TransactionsDetected.Items[i].Cells[5], "Memo"); if (memoField != null && item.LedgerItem.Memo != memoField.Text) { item.LedgerItem.Memo = memoField.Text; } data.Accounting_LedgerItems.AddObject(item.LedgerItem); } ClearError(); decimal successCount = data.SaveChanges(); ShowError("Imported " + successCount.ToString() + " row(s)."); } List <Accounting_LedgerItems> LedgerItems = new List <Accounting_LedgerItems>(); foreach (var item in PreviewLedgerItems) { LedgerItems.Add(item.LedgerItem); } var sortedItems = LedgerItems.OrderByDescending(x => x.PostAt); TransactionsDetected.DataSource = sortedItems; TransactionsDetected.DataBind(); }