static void UpdateDbWithDt_VI(DataTable dt) { try { foreach (DataRow dr in dt.Rows) { var nr = new TxCore_CiVi { DtPosted = (DateTime)dr["Date"], Details = dr["Details"] is System.DBNull ? null : (string)dr["Details"], Credit = dr["Credit"] is System.DBNull ? null : (decimal?)(double)dr["Credit"], Debit = dr["Debit"] is System.DBNull ? null : (decimal?)(double)dr["Debit"], CreatedAt = _now }; if (_db.TxCore_CiVi.Any(r => r.DtPosted == nr.DtPosted && r.Details == nr.Details && r.Credit == nr.Credit && r.Debit == nr.Debit)) { Trace.WriteLine(string.Format("The row {0} is already in DB.", dr.ToString())); } else { _db.TxCore_CiVi.Add(nr); } } //var sr = DbSaveLib.TrySaveReport(_db); //Trace.WriteLine(string.Format("{0}.", sr)); } catch (Exception ex) { ex.Pop(); } }
public static List <TxCore_CiVi> DataTableFromOfx(string file) { Debug.WriteLine(file); var lst = new List <TxCore_CiVi>(); try { foreach (var ln in File.ReadAllLines(file).Where(r => r.StartsWith("<STMTTRN>"))) { var amnt1 = ln.IndexOf("<TRNAMT>") + 8; var amnt2 = ln.IndexOf("<FITID>"); var dtls1 = ln.IndexOf("<NAME>"); var dtls2 = ln.IndexOf("</STMTTRN>"); var strAmt = ln.Substring(amnt1, amnt2 - amnt1); var ff = new TxCore_CiVi { DtPosted = DateTime.ParseExact(ln.Substring(ln.IndexOf("<DTPOSTED>") + 10, 8), "yyyyMMdd", CultureInfo.InvariantCulture), FitId = ln.Substring(amnt2 + 7, dtls1 - amnt2 - 7), Details = ln.Substring(dtls1 + 6, dtls2 - dtls1 - 6) }; if (ln.Contains("<TRNTYPE>DEBIT<")) { ff.Debit = -decimal.Parse(strAmt); } else { ff.Credit = decimal.Parse(strAmt); } lst.Add(ff); } } catch (Exception ex) { Debug.WriteLine("\n *** ERROR @ {0} in {1}.{2}():\n {3}\n", DateTime.Now.ToString("MMM yyyy HH:mm"), MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message); throw; } return(lst); }