void CreateInvoice(NAV nav) { Sales_Invoice invoice = null; Sales_InvoiceSalesLines line = null; foreach (var c in customerlst) { Sale currentsale = null; List <Sale> salesline = saleslst.Where(x => x.Customer == c.Customer).ToList(); invoice = new Sales_Invoice() { Document_Type = "Invoice", Sell_to_Customer_No = c.Customer.Trim(), Salesperson_Code = getSalesPerson(c.SalesPerson.Trim()), Posting_Date = dateTimePicker.Value, Shipment_Date = dateTimePicker.Value, Due_Date = dateTimePicker.Value, //Currency_Code = "KES", //live Shortcut_Dimension_1_Code = routecode, //other Shortcut_Dimension_2_Code = getSalesPerson(c.SalesPerson.Trim()), Location_Code = cmbLocation.Text }; nav.AddObject("Sales_Invoice", invoice); foreach (var saleline in salesline) { currentsale = saleline; line = new Sales_InvoiceSalesLines() { Description = saleline.Product, Quantity = (Decimal)saleline.Quantity }; nav.AddRelatedObject(invoice, "Sales_InvoiceSalesLines", line); } try { DataServiceResponse response = nav.SaveChanges(); if (response != null) { int uploaded = setUploaded(c.Customer, c.SalesPerson.Trim()); if (uploaded < 0) { string ex = string.Format("Did not update any records with customer: {0} and salesperson: {1}", c.Customer, c.SalesPerson); throw new System.InvalidOperationException(ex); } } } catch (Exception ex) { if (currentsale != null) { String errorstr = String.Format("Customer :{0} with Product {1} Quantity {2} .Error: ", c.Customer, currentsale.Product, currentsale.Quantity); Logger.LogThisLine(errorstr + ex.Message); } MessageBox.Show(ex.ToString()); var confirmResult = MessageBox.Show("Do you want to exit the application ??", "Confirm Exit", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { // If 'Yes', do something here. Application.Exit(); return; } else { // If 'No', do something here. } } finally { } } btnUpload.Enabled = true; btnBBack.Enabled = true; label1.Text = "Completed Upload"; System.Media.SystemSounds.Exclamation.Play(); MessageBox.Show("Completed Upload"); }
void MockCreateInvoice(NAV nav) { Sales_Invoice invoice = null; Sales_InvoiceSalesLines line = null; invoice = new Sales_Invoice() { Document_Type = "Invoice", Sell_to_Customer_No = "KE0001340", //"10000", Salesperson_Code = "AY016", Posting_Date = dateTimePicker.Value, //Currency_Code = "KES", //live // Shortcut_Dimension_1_Code = "R737", //other Shortcut_Dimension_2_Code = "AY016", Location_Code = "KAJ295 Y", }; nav.AddObject("Sales_Invoice", invoice); line = new Sales_InvoiceSalesLines() { Description = "IT00004", //"1025", Quantity = (Decimal)2 }; nav.AddRelatedObject(invoice, "Sales_InvoiceSalesLines", line); try { DataServiceResponse response = nav.SaveChanges(); if (response != null) { int uploaded = setUploaded("KE0001340", "KE0001340"); if (uploaded < 0) { string ex = string.Format("Did not update any records with customer: {0} and salesperson: {1}", "KE0001340", "KE0001340"); throw new System.InvalidOperationException(ex); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); var confirmResult = MessageBox.Show("Do you want to exit the application ??", "Confirm Exit", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { // If 'Yes', do something here. Application.Exit(); return; } else { // If 'No', do something here. } } finally { } btnUpload.Enabled = true; btnBBack.Enabled = true; label1.Text = "Completed Upload"; }