public ActionResult bangke(DateTime date, string customer_name, string sex, string phone, DateTime time_to_pick, DateTime time_to_pay, string pickup, string paypoints, int?so_cho, string form, string driver, float price, float vat, float sum, string note) { try { invoice _new = new invoice(); _new.date = date != null ? (DateTime?)Convert.ToDateTime(date) : null; _new.customer_name = customer_name ?? null; _new.sex = sex ?? null; _new.phone = phone ?? null; _new.time_to_pick = time_to_pick != null ? (DateTime?)Convert.ToDateTime(time_to_pick) : null; _new.time_to_pay = time_to_pay != null ? (DateTime?)Convert.ToDateTime(time_to_pay) : null; _new.pickup = pickup ?? null; _new.paypoints = paypoints ?? null; _new.so_cho = so_cho ?? null; _new.form = form ?? null; _new.driver = driver ?? null; _new.price = (Double?)price ?? null; _new.vat = (Double?)vat ?? null; _new.sum = (Double?)sum ?? null; _new.note = note ?? null; db.invoices.Add(_new); db.SaveChanges(); TempData["Updated"] = "Thêm dữ liệu thành công"; } catch (Exception ex) { TempData["Error"] = "Đã xảy ra lỗi khi thêm mới. " + ex.ToString(); } return(RedirectToAction("bangke")); }
private static Table Totals(invoice invoice) { Table totals = null; try { totals = new Table(2); totals.SetFontSize(10); totals.SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); totals.SetWidth(200); totals.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.RIGHT); totals.AddCell(new Cell(1, 2).SetMinHeight(20).SetBorder(border)); totals.AddTextCell(CreateCell("Summe Netto").SetBold().SetTextAlignment(iText.Layout.Properties.TextAlignment.LEFT)); totals.AddTextCell(CreateCell(invoice.DOCUMENT_TOTALS.Invoice_total_amount_without_VAT.Value + " €").SetBold().SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT)); totals.AddTextCell(CreateCell("Umsatzsteuer " + invoice.INVOICE_LINE.First().LINE_VAT_INFORMATION.Invoiced_item_VAT_rate.Value + "%").SetBold().SetTextAlignment(iText.Layout.Properties.TextAlignment.LEFT)); totals.AddTextCell(CreateCell(invoice.DOCUMENT_TOTALS.Invoice_total_VAT_amount.Value + " €").SetBold().SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT)); totals.AddTextCell(CreateCell("Rechnungsbetrag").SetBold().SetTextAlignment(iText.Layout.Properties.TextAlignment.LEFT)); totals.AddTextCell(CreateCell(invoice.DOCUMENT_TOTALS.Invoice_total_amount_with_VAT.Value + " €").SetBold().SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT)); } catch (Exception e) { return(null); } return(totals); }
public IHttpActionResult Postinvoice(invoice invoice) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (invoice.invoice_detail.Count > 0) { foreach (var key in invoice.invoice_detail) { db.invoice_detail.Add(key); } } if (invoice != null) { db.invoice.Add(invoice); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = invoice.invoiceNumber }, invoice)); } else { return(CreatedAtRoute("DefaultApi", new { }, "No Invoice information")); } }
// Создать инвойс private void CreateInvoice() { DeleteNew = true; Item = new invoice(); Item = da.InvoiceCreate(Item); edtNumber.Text = Item.InvoiceNumber.ToString(); }
public bool EditInvoices(invoice oData) { methodName = "EditInvoices"; traceID = 1; using (var uow = new UnitOfWork(AppConfig.Current.ContextName)) { traceID = 2; var oDBData = uow.Invoice.Get(oData.IdInvoice); if (oDBData != null) { using (var trans = uow.BeginTransaction()) { try { traceID = 3; oDBData.MapFrom(oData); uow.Invoice.Update(oDBData); uow.Save(); traceID = 4; trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw new AppException(500, methodName, traceID, ex); } } } } return(true); }
public bool RemoveInvoices(int id) { methodName = "RemoveInvoices"; traceID = 1; using (var uow = new UnitOfWork(AppConfig.Current.ContextName)) { using (var trans = uow.BeginTransaction()) { try { traceID = 2; invoice oDBInvoices = uow.Invoice.SingleOrDefault(m => m.IdInvoice == id); if (oDBInvoices != null) { traceID = 3; uow.Invoice.Remove(id); uow.Save(); } traceID = 5; trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw new AppException(500, methodName, traceID, ex); } } } return(true); }
public int AddInvoices(invoice oData) { methodName = "AddInvoices"; traceID = 1; using (var uow = new UnitOfWork(AppConfig.Current.ContextName)) { using (var trans = uow.BeginTransaction()) { try { traceID = 2; invoice oNewInvoices = new invoice(); oNewInvoices.MapFrom(oData); oNewInvoices = uow.Invoice.Add(oNewInvoices); uow.Save(); traceID = 3; oData.IdInvoice = oNewInvoices.IdInvoice; trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw new AppException(500, methodName, traceID, ex); } } } return(oData.IdInvoice); }
public async Task <IHttpActionResult> Putinvoice(int id, invoice invoice) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != invoice.id) { return(BadRequest()); } db.Entry(invoice).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!invoiceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// GET: Invoice/Edit/5 public ActionResult Edit(int id) { invoice a = ause.getInvoiceById(id); ause.updateInvoice(a); return(View(a)); }
public ActionResult update(invoice i) { ViewBag.i = new SelectList(new user().showall(), "us_id", "us_email"); i.in_id = (int)TempData["invoice_id"]; i.update(); return(RedirectToAction("show")); }
public static invoiceList FillDummyData() { invoiceList iList = new ServiceConnector.MobileBillInfo.invoiceList(); invoice[] arrInv = new invoice[6]; for (int i = 0; i < 6; i++) { invoice inv = new invoice(); inv.invoiceAmount = (double)LIB.Util.RandomNumber(200, 40); inv.invoiceDate = DateTime.Now.AddMonths(i * -1); inv.invoiceNumber = "13363104" + LIB.Util.RandomNumber(99, 10).ToString(); inv.invoiceOpen = false; inv.invoiceType = 1; inv.isPaid = true; inv.notInHobimList = false; inv.notReadyDisplay = false; inv.paymentLastDate = DateTime.Now.AddDays(i); inv.period = DateTime.Now.AddMonths(i * -1).Month.ToString().PadLeft(2, '0'); arrInv[i] = inv; } iList.invoicelist = arrInv; return(iList); }
// GET: Invoice/Delete/5 public ActionResult Delete(int id) { invoice b = ause.getInvoiceById(id); ause.deleteInvoice(b); return(RedirectToAction("Index")); }
private bool CreateInvoice(DbContextTransaction tran1, DbContextTransaction tran2, int iyear, int imonth) { try { DateTime dt = new DateTime(iyear, imonth, 1); var customers = db2.customer; foreach (customer cu in customers) { invoice ninv = new invoice() { customer_id = cu.id, date = dt.Date, cname = cu.name }; db.invoice.Add(ninv); db.SaveChanges(); } } catch (Exception e) { tran1.Rollback(); tran2.Rollback(); return(false); } return(true); }
private void DeleteToolStripMenuItem_Click(object sender, EventArgs e) { if (listView2.SelectedItems != null && (int)listView1.SelectedItems[0].Tag != 0) { using (igortransDBcontext db = new igortransDBcontext()) { int it = (int)listView1.SelectedItems[0].Tag; invoice selectedInvoice = db.invoices.Where(x => x.invoiceid == it).FirstOrDefault(); } if (SelectedInvoice.status != 2) { DialogResult res = MessageBox.Show(this, "Are you sure yoo want to delete this line ?", "Delete Invoice line", MessageBoxButtons.OK, MessageBoxIcon.Question); if (res == DialogResult.OK) { DeleteDetailsLine(); } } else { MessageBox.Show(this, "Unable to delete paid invoice", "Operation not allowed", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } }
private void buttonAdd_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(1)) { try { projectEntities project = new projectEntities(); invoice invoice = new invoice(); invoice.InvoiceID = Convert.ToInt32(textBoxInvoiceID.Text); invoice.TotalPrice = Convert.ToDouble(textBoxTotalPrice.Text); invoice.TypeOfPayment = Convert.ToString(comboBoxTypeOfPayment.SelectedItem); invoice.PaymentDate = paymentDate.Value.Date; invoice.IsPaid = Convert.ToString(comboBoxIsPaid.SelectedItem); project.invoices.Add(invoice); project.SaveChanges(); this.DisplayData(); MessageBox.Show("Recored Inserted.."); this.ClearTextBox(); } catch (Exception ex) { MessageBox.Show("Recored Is Not Inserted..\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.ClearTextBoxCO(); } } else { MessageBox.Show("Please Enter Values. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ShowInvoiceDetails(invoice invoice) { listView2.Items.Clear(); using (igortransDBcontext db = new igortransDBcontext()) { selectedInvoiceDetails = db.invdets.Where(x => x.invoiceid == invoice.invoiceid).ToList(); } if (selectedInvoiceDetails.Count != 0) { foreach (invdet invdet in selectedInvoiceDetails) { ListViewItem itm = new ListViewItem(); itm.Text = invdet.line.ToString(); itm.Tag = invdet.invdetid; itm.SubItems.Add(invdet.delivery_date.ToShortDateString()); itm.SubItems.Add(invdet.line_ref); itm.SubItems.Add(invdet.delivery_from); itm.SubItems.Add(invdet.delivery_to); itm.SubItems.Add(invdet.comments); itm.SubItems.Add(string.Format("{0:0,0.00}", invdet.line_total)); itm.SubItems.Add(invdet.@ref); listView2.Items.Add(itm); } } RecalcAsyncSingle(); }
public async Task <IActionResult> ReplaceInvoice(string taxcode, string ivno, string tmplatecode) { RootObject r = new RootObject(); string query = "{ \"supplierTaxCode\":\"" + taxcode + "\",\"invoiceNo\":\"" + ivno + "\",\"templateCode\":\"" + tmplatecode + "\",\"fileType\":\"ZIP\"}"; var response = CreateRequest.webRequest("https://demo-sinvoice.viettel.vn:8443/InvoiceAPI/InvoiceUtilsWS/getInvoiceRepresentationFile", query, Authen.AuthString, "POST", "application/json"); if (response != "") { r = JsonConvert.DeserializeObject <RootObject>(response); } toolgenpdf.unzipthaythe(r.fileToBytes, _env); invoice invoicetemp = new invoice(); XmlDocument doc = new XmlDocument(); string[] filePaths = Directory.GetFiles(_env.WebRootPath + "/THAYTHE/", "*.xml", SearchOption.AllDirectories); FileStream fs = new FileStream(filePaths[0], FileMode.Open, FileAccess.Read); doc.Load(fs); using (var stringWriter = new StringWriter()) using (var xmlTextWriter = XmlWriter.Create(stringWriter)) { doc.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); Serializer seri = new Serializer(); invoicetemp = seri.Deserialize <invoice>(stringWriter.GetStringBuilder().ToString()); } fs.Close(); return(PartialView("ReplaceInvoice", invoicetemp)); }
private static Table BuyerAdress(invoice invoice) { var adresseAndReturn = new Table(1); adresseAndReturn.UseAllAvailableWidth(); adresseAndReturn.SetBorder(border); var adresse = new Table(1); adresse.SetFontSize(8); adresse.UseAllAvailableWidth(); adresse.SetBorder(border); adresse.AddTextCell(CreateCell(invoice.BUYER.Buyer_trading_name)); adresse.AddTextCell(CreateCell(invoice.BUYER.Buyer_name)); adresse.AddTextCell(CreateCell(invoice.BUYER.BUYER_POSTAL_ADDRESS.Buyer_address_line_1)); adresse.AddTextCell(CreateCell(invoice.BUYER.BUYER_POSTAL_ADDRESS.Buyer_address_line_2)); adresse.AddTextCell(CreateCell(invoice.BUYER.BUYER_POSTAL_ADDRESS.Buyer_address_line_3)); adresse.AddTextCell(CreateCellM(new text[] { invoice.BUYER.BUYER_POSTAL_ADDRESS.Buyer_post_code, invoice.BUYER.BUYER_POSTAL_ADDRESS.Buyer_city }, " ")); adresseAndReturn.AddCell(ReturnAdress(invoice)); var c = new Cell(); c.SetBorder(border); c.Add(adresse); adresseAndReturn.AddCell(c); return(adresseAndReturn); }
public ActionResult Create(InvoiceVM model) { // Header var invoice = new invoice(); invoice.customerid = Int32.Parse(model.CustomerID); invoice.currencycode = model.Currency; invoice.adddate = DateTime.Now; invoice.editdate = DateTime.Now; // Detail List <invoicedetail> detailList = new List <invoicedetail>(); for (int i = 0; i < model.Detail.Count; i++) { var source = model.Detail[i]; var detail = new invoicedetail(); detail.itemcode = source.ItemCode; detail.price = source.Price; detail.quantity = source.Qty; detail.adddate = DateTime.Now; detail.editdate = DateTime.Now; detailList.Add(detail); } // Assign detail to header invoice.invoicedetail = detailList; db.invoice.Add(invoice); db.SaveChanges(); return(RedirectToAction("Index")); }
public SpareOutgoEditView(invoice _inv) { da = new DataAccess(); InitializeComponent(); edtNumber.Text = da.SpareOutgoGetMaxId().ToString(); Invoice = da.InvoiceGet(_inv.id); }
public void ShowEditForm(invoice invoice) { InvoiceEditForm dlg = new InvoiceEditForm(); AddEvents(invoice, dlg); dlg.SetDataSource(invoice); dlg.ShowDialog(); }
private void DGInvoice_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.invoiceSelected = null; if (DGInvoice.SelectedItem != null) { this.invoiceSelected = (invoice)DGInvoice.SelectedItem; } }
public ActionResult DeleteConfirmed(int id) { invoice invoice = db.invoices.Find(id); db.invoices.Remove(invoice); db.SaveChanges(); return(RedirectToAction("Index")); }
private void AddNewBtn_Click(object sender, EventArgs e) { if (controller != null) { invoice invoice = new invoice(); controller.ShowEditForm(invoice); } }
public ReportViewInvoice(int id) { InitializeComponent(); DataAccess da = new DataAccess(); InvoiceId = id; Outgo = da.InvoiceGet(id); }
public ActionResult delete(string id) { invoice i = new invoice(); i.in_id = int.Parse(id); i.delete(); return(RedirectToAction("show")); }
private void noinvoice_selectedchange(object sender, SelectionChangedEventArgs e) { this.invoiceSelected = null; if (cbinvoiceNumber.SelectedItem != null) { this.invoiceSelected = (invoice)cbinvoiceNumber.SelectedItem; } }
public int AddInvoice(int documentId) { var invoice = new invoice(); invoice.DocumentID = documentId; _db.invoices.Add(invoice); _db.SaveChanges(); return(invoice.DocumentID); }
public String LineCreate(string fkidx, invoiceline line) { invoice header = db.invoices.Find(Convert.ToInt32(fkidx)); line.invoice = header; db.invoicelines.Add(line); db.SaveChanges(); return(""); }
// // GET: /Invoice/Details/5 public ActionResult Details(int id = 0) { invoice invoice = db.invoices.Find(id); if (invoice == null) { return(HttpNotFound()); } return(View(invoice)); }
private static void EmailInvoiceData(invoice curInvoice) { //print customer number appendToBody("Customer Number: " + curInvoice.customerNumber); //print coupon amount appendToBody(String.Format("Coupon Amount: ${0}", curInvoice.couponAmount.ToString("0.00"))); //print date paid appendToBody("Date Paid: " + fileDate); appendToBody(""); }
private static void EmailInvoiceData(invoice curInvoice) { for (int i = 0; i < curInvoice.SupplimentalInvoices.customerIDs.Count; i++) { //print customer number appendToBody("Customer Number: " + curInvoice.SupplimentalInvoices.customerIDs[i]); for (int j = 0; j < curInvoice.SupplimentalInvoices.checkData.Count; j++) { //print check number appendToBody(String.Format("Check Number: {0}", curInvoice.SupplimentalInvoices.checkData[j].checkNumber)); //print check amount appendToBody(String.Format("Check Total: ${0}", curInvoice.SupplimentalInvoices.checkData[j].total.ToString("0.00"))); } //print coupon amount appendToBody(String.Format("Coupon Amount: ${0}", curInvoice.SupplimentalInvoices.couponAmounts[i].ToString("0.00"))); //print date paid appendToBody("Date Paid: " + fileDate); appendToBody(""); } }
private static void parseSI(string line) { List<string> lineData = line.Split('|').ToList<string>(); string key = lineData[27]; string transactionNumber; string checkNumber; string customerNumber; double couponValue; //transaction ID and check# if (key == "I019") { transactionNumber = lineData[29]; checkNumber = lineData[30]; //There will only ever be 1 line that has the transaction # //If the transaction numbers match...the data is an extension of the previous invoice. All new data needs to be appended to it if (previousInvoice != null && previousInvoice.SupplimentalInvoices.transactionID == transactionNumber) { currentInvoice = previousInvoice; } currentInvoice.SupplimentalInvoices.transactionID = transactionNumber; check checkData = new check(); checkData.checkNumber = checkNumber; checkData.total = invoiceValue; currentPaymentRecord.numChecks += 1; currentPaymentRecord.checkTotal += checkData.total; currentInvoice.SupplimentalInvoices.checkData.Add(checkData); } //Cutomer ID else if (key == "C151") { customerNumber = lineData[29]; currentInvoice.SupplimentalInvoices.customerIDs.Add(customerNumber); } //Coupon Amount else if (key == "C041") { couponValue = double.Parse(lineData[29]); currentInvoice.SupplimentalInvoices.couponAmounts.Add(couponValue); currentPaymentRecord.numCoupons += 1; currentPaymentRecord.couponTotal += couponValue; } }
/// <summary> /// This is a debug version of Process files that allows me to pass in the name of an individual file to be processed /// </summary> /// <param name="file">The name of the file to be processed. Starts looking in CWD. If you want a different path, send in the entire location</param> private static void processFiles(string file) { //create a new payment record list for each file ... paymentRecords = new List<paymentRecord>(); //appendToBody(String.Format("Downloaded {0} files from Wells Fargo", sftpFiles.Count())); int count = 0; try { using (StreamReader sr = new StreamReader(file)) { //appendToBody(String.Format("Parsing file {0}", file)); string line = ""; string recordType = ""; currentPaymentRecord = new paymentRecord(); currentInvoice = null; previousInvoice = null; currentSI = null; invoiceValue = 0; while ((line = sr.ReadLine()) != null && line.Length > 15) { line = line.Replace(" ", ""); recordType = line.Substring(0, 2); Console.WriteLine(line); switch (recordType) { case "FH": //This is a header line. We can pull the 10 digits and the date from this line... parseHeader(line); break; case "PR": //We need to make sure we catch the final payment in the PR before we start another if (currentInvoice != null) { //If we have a previous invoice if (previousInvoice != null) { //compare the currentInvocie Id vs previousInvoiceID. If they don't match. Push the previousInvoice if (currentInvoice.SupplimentalInvoices.transactionID != previousInvoice.SupplimentalInvoices.transactionID) { if (previousInvoice.SupplimentalInvoices.transactionID != null) { currentPaymentRecord.invoices.Add(previousInvoice); } previousInvoice = null; } } if (currentInvoice.SupplimentalInvoices.transactionID != null) { currentPaymentRecord.invoices.Add(currentInvoice); } currentInvoice = null; } //This is a payment record... //create a new payment record currentPaymentRecord = new paymentRecord(); currentPaymentRecord.total = parsePR(line); paymentRecords.Add(currentPaymentRecord); break; case "IV": //if there is a currentInvoice if (currentInvoice != null) { //If we have a previous invoice if (previousInvoice != null) { //compare the currentInvocie Id vs previousInvoiceID. If they don't match. Push the previousInvoice //If transaction Ids are null. that means there were no SI fields below it ... if (previousInvoice.SupplimentalInvoices.transactionID != null && (currentInvoice.SupplimentalInvoices.transactionID != previousInvoice.SupplimentalInvoices.transactionID)) { currentPaymentRecord.invoices.Add(previousInvoice); } } //regardless, currentInvoice becomes previous invoice previousInvoice = currentInvoice; } invoiceValue = parseIV(line); currentInvoice = new invoice(); //create a new SI currentSI = new supplimentalInvoice(); currentInvoice.SupplimentalInvoices = currentSI; break; case "SI": //Supplemental Invoice //Parse the line and determine what type of data it is... parseSI(line); //push into the invoice break; case "BT": //Trailer Record //If we have payment records. We need to do a final check to make sure we don't miss the last 2 records we read... //If the currentPaymentRecord does not have at least 2 records in it... //Case 1. //Case 2 //Case 3 //Case 1. There are 0 records in the paymentRecord. Need to add all valid if (currentPaymentRecord.invoices.Count == 0) { if (previousInvoice != null && previousInvoice.SupplimentalInvoices.transactionID != null) { currentPaymentRecord.invoices.Add(previousInvoice); } if (currentInvoice != null && currentInvoice.SupplimentalInvoices.transactionID != null) { currentPaymentRecord.invoices.Add(currentInvoice); } } //Case 2. There is 1 record in the paymentRecord...Need to add all valid else if (currentPaymentRecord.invoices.Count == 1) { if (previousInvoice != null && previousInvoice.SupplimentalInvoices.transactionID != null && previousInvoice.SupplimentalInvoices.transactionID != currentPaymentRecord.invoices[0].SupplimentalInvoices.transactionID) { currentPaymentRecord.invoices.Add(previousInvoice); } if (currentInvoice != null && currentInvoice.SupplimentalInvoices.transactionID != null && currentInvoice.SupplimentalInvoices.transactionID != currentPaymentRecord.invoices[0].SupplimentalInvoices.transactionID) { currentPaymentRecord.invoices.Add(currentInvoice); } } //Case 3. There are x records in the paymentRecord ... need to add all valid else { string prevID = currentPaymentRecord.invoices[currentPaymentRecord.invoices.Count - 2].SupplimentalInvoices.transactionID; string curID = currentPaymentRecord.invoices[currentPaymentRecord.invoices.Count - 1].SupplimentalInvoices.transactionID; if (previousInvoice.SupplimentalInvoices.transactionID != prevID && previousInvoice.SupplimentalInvoices.transactionID != curID) { currentPaymentRecord.invoices.Add(previousInvoice); } if (currentInvoice.SupplimentalInvoices.transactionID != prevID && currentInvoice.SupplimentalInvoices.transactionID != curID) { currentPaymentRecord.invoices.Add(currentInvoice); } } break; default: //Do nothing //Console.WriteLine("unrecognized line header: {0}", line); break; } } //close the file sr.Close(); } //add stuff to the body of the email //we can validate all checks add up here... //upload the file to the lockbox createOutputFile(file); appendToBody(""); } catch (Exception e) { Console.WriteLine("Exception processing file...{0}", e); appendToBody(String.Format("Error while processing {0}", file)); } //appendToBody(String.Format("Processed {0} valid files", count)); }
/// <summary> /// Loops over all the files we downloaded from the SFTP. Goes through the data line by line. /// Looks for a line beginning with "8" as that signifies a valid file structure /// </summary> private static void processFiles() { appendToBody(String.Format("Wells Fargo files to be processed: {0}", sftpFilesToProcess.Count())); //int count = 0; //Loop over each file. We need to determine if it is a morning file and in the correct format foreach (var file in sftpFilesToProcess) { //create a new payment record list for each file ... batches = new List<batch>(); bool validFile = false; bool multiCheck = false; try { using (StreamReader sr = new StreamReader(file)) { //appendToBody(String.Format("Parsing file {0}", file.Name)); string line = ""; string recordType = ""; currentPaymentRecord = null; currentBatch = new batch(); currentInvoice = null; invoiceValue = 0; while ((line = sr.ReadLine()) != null && line.Length > 15) { line = line.Replace(" ", ""); recordType = line.Substring(0, 2); Console.WriteLine(line); switch (recordType) { //File contains 1 FH case "FH": //This is a header line. We can pull the 10 digits and the date from this line... parseHeader(line); break; //File can contain multiple BH case "BH": //create a new Batch currentBatch = new batch(); break; //Each BH can contain multiple PR case "PR": //In order for the file to be valid we have to have at least 1 payment record... validFile = true; currentBatch.numChecks++; //If there is no open paymentRecord. Create a new one if (!multiCheck){ currentPaymentRecord = new paymentRecord(); currentBatch.paymentRecords.Add(currentPaymentRecord); } //Every PR wil create a new "check". currentCheck = new check(); currentCheck.checkAmount = parsePR(line); currentBatch.checkTotal += currentCheck.checkAmount; currentPaymentRecord.checks.Add(currentCheck); currentPaymentRecord.total += currentCheck.checkAmount; break; //Each PR will contain a SP case "SP": //Need to parse the SP and see if the flag is set for additional checks multiCheck = parseSP(line); break; //Each PR can contain multiple IV case "IV": currentBatch.numInvoices++; currentInvoice = new invoice(); invoiceValue = parseIV(line); currentPaymentRecord.invoices.Add(currentInvoice); break; case "SI": //Supplemental Invoice //Parse the line and determine what type of data it is... if (currentInvoice != null) { currentInvoice.invoiceDate = parseSI(line); } else { Console.WriteLine("Current invoice is null while reading in an SI...Should Never happen!!!! problem!"); Console.ReadKey(); } //push into the invoice break; case "BT": //Trailer Record batches.Add(currentBatch); break; default: //Do nothing //Console.WriteLine("unrecognized line header: {0}", line); break; } } //close the file sr.Close(); } if (validFile) { string fileName = createOutputFile(file); attachments.Add(new FileInfo(fileName)); appendToBody(""); //upload file ... //ftpUploadFile(fileName, fileName); } } catch (Exception e) { Console.WriteLine("Exception processing file...{0}", e); appendToBody(String.Format("Error while processing {0}", file)); } } //appendToBody(String.Format("Processed {0} valid files", count)); }