private void btnGet_Click(object sender, RoutedEventArgs e) { try { // var result1 = CommonCode.GenerateTopPurchaseOrder(Guid.NewGuid().ToString()); // var SplitResult = result1.Split('-'); // var SplitResultInt = Convert.ToInt64(SplitResult[1]) + 1; //var TotalZeros = ""; //switch (SplitResultInt.ToString().Count()) //{ // case 3: // TotalZeros = "00000"; // break; // case 4: // TotalZeros = "0000"; // break; // case 5: // TotalZeros = "000"; // break; // case 6: // TotalZeros = "00"; // break; // case 7: // TotalZeros = "0"; // break; // default: // break; //} string message = string.Empty; string order = "<?xml version=\"1.0\"?> \r\n <PurchaseOrder xmlns:xsd = \"http://www.w3.org/2001/XMLSchema\" xmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xmlns = \"http://api.unleashedsoftware.com/version/1\" >"; string supplierCode = string.Empty; string currencyCode = string.Empty; double taxRate = 0.0; double subTotal = 0.0; double taxTotal = 0.0; double total = 0.0; Warehouses wh = new Warehouses(); // Random generator = new Random(); // int r = generator.Next(0000000, 9999999); order += "\r\n<Guid>" + Guid.NewGuid().ToString() + "\r\n</Guid><OrderDate>" + DateTime.Now.ToString("yyyy-MM-dd") + "</OrderDate>"; order += "<RequiredDate>" + DateTime.Now.AddDays(Convert.ToInt32(TimeSpanUpcoming)).ToString("yyyy-MM-dd") + "</RequiredDate>"; order += " <Supplier><SupplierCode>{0}</SupplierCode></Supplier><OrderStatus>Parked</OrderStatus><ExchangeRate>0.478090</ExchangeRate><Currency><CurrencyCode>{1}</CurrencyCode></Currency>"; order += "<PurchaseOrderLines>"; int i = 0; SupplierItem supplier = null; foreach (System.Windows.Forms.DataGridViewRow row in UnleashedData.Rows) { bool isSelected = Convert.ToBoolean(row.Cells["checkBoxColumn"].EditedFormattedValue); if (isSelected) { i = i + 1; string productCode = row.Cells["ProductCode"].Value.ToString(); var result = ULDataCalculation.productList.Where(m => m.ProductCode == productCode).FirstOrDefault(); //DataRow[] dr = CommonCode.productDt.Select("[Product Code]='" + productCode + "'"); double defaultPurchasePrice = 0; string units = string.Empty; //if (dr.Count() > 0) //{ // defaultPurchasePrice = Convert.ToDouble(dr[0]["Default Purchase Price"]); // units = Convert.ToString(dr[0]["Units"]); //} if (result != null) { defaultPurchasePrice = result.DefaultPurchasePrice == null ? 0.0 : result.DefaultPurchasePrice.Value; units = result.UnitOfMeasure == null ? "EA" : result.UnitOfMeasure.Name; } if (supplierCode == string.Empty) { supplierCode = row.Cells["SupplierCode"].Value.ToString(); var response = CommonCode.GetSupplierInformation(supplierCode); if (response != null) { supplier = response.Items.Where(m => m.SupplierCode == supplierCode).FirstOrDefault(); if (supplier != null) { currencyCode = supplier.Currency.CurrencyCode; } } } double linetax = 0; //UpcomingOrderQuantities string orderQuantity = row.Cells["Quantity"].Value.ToString(); if (orderQuantity == string.Empty) { orderQuantity = "0"; } //objSupplier.SupplierCode = row.Cells["SupplierCode"].Value.ToString(); double lineTotal = defaultPurchasePrice * Convert.ToDouble(orderQuantity); subTotal += lineTotal; if (supplier != null) { //if (supplier.Currency.CurrencyCode == "AUD") if (supplier.Taxable == true) { linetax = (lineTotal * 10) / 100; taxRate = 10; taxTotal += linetax; } } order += "<PurchaseOrderLine><LineNumber> " + i + " </LineNumber><Product><ProductCode>" + productCode + "</ProductCode></Product>"; order += "<OrderQuantity> " + orderQuantity + " </OrderQuantity><UnitPrice>" + defaultPurchasePrice + "</UnitPrice><LineTotal>" + lineTotal + "</LineTotal><LineTax>" + linetax + "</LineTax>"; // order += "<BCUnitPrice>" + Math.Round(defaultPurchasePrice,2) + "</BCUnitPrice><BCSubTotal>" + Math.Round(lineTotal,2) + "</BCSubTotal>"; order += "<UnitOfMeasure><Name>" + units + "</Name></UnitOfMeasure>"; order += "</PurchaseOrderLine>"; } } total = subTotal + taxTotal; subTotal = subTotal; taxTotal = taxTotal; order += "</PurchaseOrderLines><TaxRate>" + Math.Round(taxRate / 100, 2) + "</TaxRate><SubTotal>" + subTotal + "</SubTotal><TaxTotal>" + taxTotal + "</TaxTotal><Total>" + total + "</Total>"; //order += "<BCSubTotal>" + subTotal + "</BCSubTotal><BCTaxTotal>" + taxTotal + "</BCTaxTotal><BCTotal>" + total + "</BCTotal>"; if (glbWarehouse != string.Empty) { order += "<Warehouse><WarehouseCode>" + glbWarehouse + "</WarehouseCode></Warehouse>"; wh = CommonCode.GetWarehouseInformation(glbWarehouse); } order += "<DiscountRate>0.00</DiscountRate></PurchaseOrder>"; string completeOrder = string.Format(order, supplierCode, currencyCode); if (supplierCode != string.Empty) { try { var xmlstring = CommonCode.AddPurchaseOrder(completeOrder); var firstIndex = xmlstring.IndexOf("<Guid>"); var lastIndex = xmlstring.IndexOf("</Guid>"); int indexStart = firstIndex + 6; int indexLast = lastIndex - firstIndex - 6; //var remainingString = xmlstring.Substring(indexStart, indexLast); //var result222 = CommonCode.GeneratePurchaseOrder(remainingString); //ConvertHTMLtoPDF(result222); if (indexStart >= 0 && indexLast >= 0) { var remainingString = xmlstring.Substring(indexStart, indexLast); var result222 = CommonCode.GeneratePurchaseOrder(remainingString); //ConvertHTMLtoPDF(result222, wh); Helpers.Converters.ConvertHTMLtoPDF(result222, wh); } else { MessageBox.Show(xmlstring); } } catch (Exception) { throw; } } else { MessageBox.Show("Supplier is not selected.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show(ex.InnerException + "," + ex.Message + "," + ex.StackTrace, "Error"); } }