private void btnLoad_Click(object sender, EventArgs e) { bool trans = false; TransRec tr = new TransRec(); taBankTrans.Fill(DSEzra.BankTrans); int counter = 0; if (txtFileName.Text.Trim().Length > 0) { string line = string.Empty; StreamReader file = new StreamReader(txtFileName.Text); while ((line = file.ReadLine()) != null) { txtDisplay.AppendText(line + "\n"); if (line.Contains("<STMTTRN>")) { trans = true; continue; } if (trans) { counter += ParseLine(line, tr); } if (line.Contains("</STMTTRN>")) { trans = false; tr.Clear(); } } taBankTrans.Update(DSEzra); taCKCUChecking.Update(DSEzra); MessageBox.Show(counter.ToString() + " Records added"); } else { MessageBox.Show("You must select a file before loading"); } }
private int ParseLine(string lineIn, TransRec tr) { string[] line = lineIn.Split('>'); int counter = 0; switch (line[0].Substring(1)) { case "TRNTYPE": { tr.TransType = line[1]; break; } case "DTPOSTED": { tr.TransDate = DateTime.ParseExact(line[1].Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture); break; } case "TRNAMT": { decimal tmpOut = 0; decimal.TryParse(line[1], out tmpOut); tr.TransAmount = tmpOut; break; } case "FITID": { tr.TransFitId = line[1].TrimEnd(); break; } case "CHECKNUM": { tr.TransChkNum = line[1]; break; } case "NAME": { tr.TransName = line[1]; break; } case "MEMO": { tr.TransMemo = line[1]; break; } case "/STMTTRN": { EzraDataSet.BankTransDataTable dt = new EzraDataSet.BankTransDataTable(); taBankTrans.FillByBankId(dt, tr.TransFitId); int result = dt.Count; ////int result = bndsBankTrans.Find("tranBankID", tr.TransFitId); if (result == 0) { EzraDataSet.BankTransRow btRow = DSEzra.BankTrans.NewBankTransRow(); btRow.tranType = tr.TransType; btRow.tranDate = tr.TransDate; btRow.tranAmt = tr.TransAmount; btRow.tranBankID = tr.TransFitId; btRow.tranCheckNo = tr.TransChkNum; btRow.tranName = tr.TransName; btRow.tranMemo = tr.TransMemo; DSEzra.BankTrans.Rows.Add(btRow); EzraDataSet.CKCUCheckingRow chkRow = DSEzra.CKCUChecking.NewCKCUCheckingRow(); chkRow.ChkDate = tr.TransDate; if (tr.TransAmount > 0) { chkRow.ChkDep = tr.TransAmount; } else { chkRow.ChkPymt = Math.Abs(tr.TransAmount); } chkRow.ChkNo = tr.TransChkNum; chkRow.ChkMemo = tr.TransMemo; chkRow.ChkBanTransNo = tr.TransFitId; DSEzra.CKCUChecking.Rows.Add(chkRow); taBankTrans.Update(DSEzra); taCKCUChecking.Update(DSEzra); counter++; } break; } default: { MessageBox.Show("Could not parse " + line[0] + " - " + line[1]); break; } } return(counter); }