/* a method that generate xml order and upload to the sftp server and update database */ public void GenerateTxt(ShopCaValues value, Dictionary <int, string> cancelList) { // adding txt file header string txt = "Base Data\tfeed_id=shop.ca_order_update_01\t(For internal processing. Do not remove rows 1 and 2)\n" + "supplier_id\tstore_name\torder_id\torder_item_id\titem_state\titem_state_date\tcarrier_code\tcarrier_name\tshipping_method\ttracking_number\texpected_shipping_date\tcancel_reason\tfulfillment_center_name\tfullfillment_center_address1\tfullfillment_center_address2\tfullfillment_center_city\tfullfillment_center_postalcode\tfullfillment_center_country\tbackorder_replacement_sku\tbackorder_replacement_sku_title\tbackorder_replacement_sku_price\tsupplier_order_number\treturn_grade\treturn_instructions_confirmation\trma_number\trecovery_amount\n"; // fields for database update SqlConnection connection = new SqlConnection(Credentials.OrderHubCon); SqlCommand command = new SqlCommand { Connection = connection }; connection.Open(); // start adding content to the txt file for (int i = 0; i < value.OrderItemId.Count; i++) { // this is necessary fields txt += value.SupplierId + '\t' + value.StoreName + '\t' + value.OrderId + '\t' + value.OrderItemId[i] + '\t'; #region TXT Generation and Database Item Update if (cancelList.Keys.Contains(i)) { // the case if the item is cancelled -> show the cancel reason txt += "Cancelled\t" + DateTime.Today.ToString("yyyy-MM-dd") + "\t\t\t\t\t\t" + cancelList[i] + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n"; // update item to cancelled to database command.CommandText = "UPDATE ShopCa_Order_Item SET Cancelled = 'True' WHERE OrderItemId = \'" + value.OrderItemId[i] + '\''; command.ExecuteNonQuery(); } else { // the case if the item is shipped -> show the shipping info txt += "Shipped\t" + DateTime.Today.ToString("yyyy-MM-dd") + "\tCP\tCanada Post\t" + value.Package.Service + '\t' + value.Package.TrackingNumber + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n"; // update item to shipped to database command.CommandText = "UPDATE ShopCa_Order_Item SET Shipped = 'True' WHERE OrderItemId = \'" + value.OrderItemId[i] + '\''; command.ExecuteNonQuery(); } #endregion } // convert txt to xsd file string path = completeOrderDir + "\\" + value.OrderId + ".txt"; StreamWriter writer = new StreamWriter(path); writer.WriteLine(txt); writer.Close(); // master database update command.CommandText = "UPDATE ShopCa_Order SET TrackingNumber = \'" + value.Package.TrackingNumber + "\', CompleteDate = \'" + DateTime.Today.ToString("yyyy-MM-dd HH:mm:ss") + "\', SelfLink = \'" + value.Package.SelfLink + "\', LabelLink = \'" + value.Package.LabelLink + "\', " + "Complete = 'True' WHERE OrderId = \'" + value.OrderId + '\''; command.ExecuteNonQuery(); connection.Close(); // upload file to sftp server sftp.Connect(); sftp.Put(path, CONFIRM_DIR); sftp.Close(); }
/* a method that return all shipped order */ public ShopCaValues[] GetAllShippedOrder() { // local field for storing shipment value List <ShopCaValues> list = new List <ShopCaValues>(); // grab all shipped using (SqlConnection connection = new SqlConnection(Credentials.OrderHubCon)) { string date = DateTime.Today.ToString("yyyy-MM-dd"); SqlCommand command = new SqlCommand("SELECT OrderId, TrackingNumber, SelfLink FROM ShopCa_Order " + "WHERE EndofDay != 1 AND TrackingNumber != '' AND (ShipDate = \'" + date + "\' OR CompleteDate = \'" + date + "\')", connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ShopCaValues value = new ShopCaValues { OrderId = reader.GetString(0), Package = { TrackingNumber = reader.GetString(1), SelfLink = reader.GetString(2) } }; list.Add(value); } } return(list.ToArray()); }
/* a method that get all new order on the server and update to the database */ public void GetOrder() { // get all the new file on the order directory to local new order storing directory IEnumerable <string> orderCheck = CheckOrderFile(); GetOrder(newOrderDir, orderCheck); // return the transaction that haved not been processed Dictionary <string, string> dic = GetOrderId(); dic = CheckOrder(dic); // get information for each unprocessed order and update the them to the database foreach (KeyValuePair <string, string> keyValue in dic) { ShopCaValues value = GenerateValue(keyValue.Key, keyValue.Value); AddNewOrder(value); } }
/* a method that add a new order to database */ private static void AddNewOrder(ShopCaValues value) { using (SqlConnection connection = new SqlConnection(Credentials.OrderHubCon)) { // add new order to database SqlCommand command = new SqlCommand("INSERT INTO ShopCa_Order " + "(OrderId, SupplierId, StoreName, OrderCreateDate, GrandTotal, TotalPrice, TotalTax, TotalShippingCost, TotalDiscount, BillToName, BillToAddress1, BillToAddress2, BillToCity, BillToState, BillToPostalCode, BillToPhone, ShipToName, ShipToAddress1, ShipToAddress2, ShipToCity, ShipToState, ShipToPostalCode, ShipToPhone, OptionIn, ShippingMethod, Complete, TrackingNumber, EndofDay, SelfLink, LabelLink) Values " + "(\'" + value.OrderId + "\',\'" + value.SupplierId + "\',\'" + value.StoreName + "\',\'" + value.OrderCreateDate.ToString("yyyy-MM-dd") + "\'," + value.GrandTotal + "," + value.TotalPrice + "," + value.TotalTax + "," + value.TotalShippingCost + "," + value.TotalDiscount + ",\'" + value.BillTo.Name.Replace("'", "''") + "\',\'" + value.BillTo.Address1.Replace("'", "''") + "\',\'" + value.BillTo.Address2.Replace("'", "''") + "\',\'" + value.BillTo.City.Replace("'", "''") + "\',\'" + value.BillTo.State + "\',\'" + value.BillTo.PostalCode + "\',\'" + value.BillTo.DayPhone + "\',\'" + value.ShipTo.Name.Replace("'", "''") + "\',\'" + value.ShipTo.Address1.Replace("'", "''") + "\',\'" + value.ShipTo.Address2.Replace("'", "''") + "\',\'" + value.ShipTo.City.Replace("'", "''") + "\',\'" + value.ShipTo.State + "\',\'" + value.ShipTo.PostalCode + "\',\'" + value.ShipTo.DayPhone + "\',\'" + value.Option + "\',\'" + value.ShippingMethod + "\',\'False\',\'" + value.Package.TrackingNumber + "\',\'False\', \'" + value.Package.SelfLink + "\',\'" + value.Package.LabelLink + "\')", connection); connection.Open(); command.ExecuteNonQuery(); // add each item for the order to database for (int i = 0; i < value.OrderItemId.Count; i++) { command.CommandText = "INSERT INTO ShopCa_Order_Item " + "(OrderId, OrderItemId, Sku, Title, Ssrp, SsrpTax, Quantity, ItemPrice, ExtendedItemPrice, ItemTax, ItemShippingCost, ItemDiscount, Shipped, Cancelled) Values" + "(\'" + value.OrderId + "\',\'" + value.OrderItemId[i] + "\',\'" + value.Sku[i] + "\',\'" + value.Title[i].Replace("'", "''") + "\'," + value.Ssrp[i] + ',' + value.SsrpTax[i] + ',' + value.Quantity[i] + ',' + value.ItemPrice[i] + ',' + value.ExtendedItemPrice[i] + ',' + value.ItemTax[i] + ',' + value.ItemShippingCost[i] + ',' + value.ItemDiscount[i] + ",'False','False')"; command.ExecuteNonQuery(); } } }
/* a method that save the packing slip pdf */ public static void CreatePackingSlip(ShopCaValues value, int[] cancelIndex, bool preview) { // the case if all of the items in the order are cancelled -> don't need to print the packing slip if (cancelIndex.Length >= value.OrderItemId.Count) { return; } // first check if the save directory exist -> if not create it if (!File.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } // initialize fields Document doc = new Document(PageSize.LETTER, 0, 0, 0, 0); string file = SavePath + "\\" + value.OrderId + ".pdf"; PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(file, FileMode.Create)); // open the documents doc.Open(); #region Logo and Lines Set Up // add shop.ca logo Image logo = Image.GetInstance(Properties.Resources.shopcaPackSlip, ImageFormat.Png); logo.ScalePercent(15f); logo.SetAbsolutePosition(40f, doc.PageSize.Height - 60f); doc.Add(logo); // drawline - horizontal PdfContentByte draw = writer.DirectContent; draw.MoveTo(40f, doc.PageSize.Height - 165f); draw.LineTo(doc.PageSize.Width - 40f, doc.PageSize.Height - 165f); draw.Stroke(); // drawline - vertical draw.MoveTo(doc.PageSize.Width - 180f, doc.PageSize.Height - 30f); draw.LineTo(doc.PageSize.Width - 180f, doc.PageSize.Height - 155f); draw.Stroke(); #endregion // initialize local fields for text BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); BaseFont boldFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false); ColumnText ct = new ColumnText(draw); #region Ship To // set ship to // title Phrase text = new Phrase("Ship To:", new Font(boldFont, 10)); ct.SetSimpleColumn(text, 40f, 680f, 150f, 700f, 0f, Element.ALIGN_LEFT); ct.Go(); // ship to address text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City + ' ' + value.ShipTo.State + " , CA\n" + value.ShipTo.PostalCode, new Font(baseFont, 10)); ct.SetSimpleColumn(text, 40f, 630f, 175f, 700f, 12f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Top Right // order info // field names text = new Phrase("From:\n\n\n\n\nOrder#:\nOrder Placed Date:", new Font(boldFont, 10)); ct.SetSimpleColumn(text, 310f, 655f, 425f, 760f, 15f, Element.ALIGN_RIGHT); ct.Go(); // from text = new Phrase("SHOP.CA", new Font(boldFont, 10)); ct.SetSimpleColumn(text, 439f, 729f, 489f, 744f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("70 Peter Street, 2nd Floor\nToronto, Ontario, Canada, M5V 2G5\n1-855-4-SHOPCA", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 439f, 672.5f, 559f, 742.5f, 12f, Element.ALIGN_LEFT); ct.Go(); // order number & order placed date text = new Phrase(value.OrderId + '\n' + value.OrderCreateDate.ToString("yyyy-MM-dd"), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 439f, 655f, 509f, 685f, 15f, Element.ALIGN_LEFT); ct.Go(); #endregion // words for customers text = new Phrase("Thank you for shopping with SHOP.CA! With thousands of premium brands, free shipping and free returns on most products, and " + "Aeroplan Miles* earned on your purchases, SHOP.CA is the convenient, rewarding, and Canadian way to shop. We continue to add " + "new brands and incredible new products every day at SHOP.CA, and we hope to see you back soon", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 40f, 565f, doc.PageSize.Width - 40f, 615f, 11f, Element.ALIGN_LEFT); ct.Go(); #region Order Title // drawline for order title draw.SetLineWidth(0.25f); draw.MoveTo(40f, 550f); draw.LineTo(198f, 550f); draw.Stroke(); draw.MoveTo(40f, 550f); draw.LineTo(40f, 525f); draw.Stroke(); draw.MoveTo(40f, 525f); draw.LineTo(198f, 525f); draw.Stroke(); draw.MoveTo(198f, 525f); draw.LineTo(198f, 550f); draw.Stroke(); // order title text = new Phrase("ORDER PACKING LIST", new Font(baseFont, 13)); ct.SetSimpleColumn(text, 46f, 512f, 196, 532f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Order Column // draw box for order column names draw.MoveTo(40f, 520f); draw.LineTo(doc.PageSize.Width - 40f, 520f); draw.Stroke(); draw.MoveTo(40f, 520f); draw.LineTo(40f, 495f); draw.Stroke(); draw.MoveTo(233f, 520f); draw.LineTo(233f, 495f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 88f, 520f); draw.LineTo(doc.PageSize.Width - 88f, 495f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 520f); draw.LineTo(doc.PageSize.Width - 40f, 495f); draw.Stroke(); draw.MoveTo(40f, 495f); draw.LineTo(doc.PageSize.Width - 40f, 495f); draw.Stroke(); text = new Phrase("SKU TITLE QTY" , new Font(baseFont, 10f)); ct.SetSimpleColumn(text, 120f, 483f, doc.PageSize.Width - 43f, 503f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Order Item float height = 495f; // adding items for (int i = 0; i < value.OrderItemId.Count; i++) { // if the item is cancelled, skip this item if (cancelIndex.Any(j => i == j)) { continue; } // draw box draw.MoveTo(40f, height); draw.LineTo(40f, height - 25f); draw.Stroke(); draw.MoveTo(233f, height); draw.LineTo(233f, height - 25f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 88f, height); draw.LineTo(doc.PageSize.Width - 88f, height - 25f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, height); draw.LineTo(doc.PageSize.Width - 40f, height - 25f); draw.Stroke(); draw.MoveTo(40f, height - 25); draw.LineTo(doc.PageSize.Width - 40f, height - 25f); draw.Stroke(); // sku text = new Phrase(value.Sku[i], new Font(baseFont, 10)); ct.SetSimpleColumn(text, 100f, height - 25, 200, height - 15, 0f, Element.ALIGN_LEFT); ct.Go(); // title text = new Phrase(value.Title[i], new Font(baseFont, 10)); ct.SetSimpleColumn(text, 238f, height - 25, doc.PageSize.Width - 88f, height - 15, 0f, Element.ALIGN_LEFT); ct.Go(); // title text = new Phrase(value.Quantity[i].ToString(), new Font(baseFont, 10)); ct.SetSimpleColumn(text, doc.PageSize.Width - 70f, height - 25, doc.PageSize.Width - 40f, height - 15, 0f, Element.ALIGN_LEFT); ct.Go(); // decrease height for next item height -= 25f; } #endregion #region Bottom Left Box // draw box draw.MoveTo(40f, 220f); draw.LineTo(doc.PageSize.Width / 2 - 15f, 220f); draw.Stroke(); draw.MoveTo(40f, 220f); draw.LineTo(40f, 90f); draw.Stroke(); draw.MoveTo(40f, 90f); draw.LineTo(doc.PageSize.Width / 2 - 15f, 90f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width / 2 - 15f, 90f); draw.LineTo(doc.PageSize.Width / 2 - 15f, 220f); draw.Stroke(); // title text = new Phrase("If you are missing items from your order.", new Font(boldFont, 8)); ct.SetSimpleColumn(text, 47f, 185f, doc.PageSize.Width / 2 - 22f, 205f, 0f, Element.ALIGN_LEFT); ct.Go(); // content text = new Phrase("SHOP.CA is a premium marketplace that allows you to purchase products " + "from hundreds of different merchant partners. If your order includes more " + "than one type of product, it is very likely for items to ship at different times " + "and arrive in separate boxes. You can view any outstanding items by logging " + "into your SHOP.CA Member Account at any time, or by visiting " + "\"Trac Order\" from the menu on the SHOP.CA homepage." + "If you received damaged, defactive or incorrectly shipped merchandise, " + "please contact our Customer Loyalty Team within 48 hours of receipt.", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 47f, 60f, doc.PageSize.Width / 2 - 22f, 200f, 11f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Bottom Right Box // draw box draw.MoveTo(doc.PageSize.Width / 2 + 15f, 220f); draw.LineTo(doc.PageSize.Width - 40f, 220f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width / 2 + 15f, 220f); draw.LineTo(doc.PageSize.Width / 2 + 15f, 90f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width / 2 + 15f, 90f); draw.LineTo(doc.PageSize.Width - 40f, 90f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 90f); draw.LineTo(doc.PageSize.Width - 40f, 220f); draw.Stroke(); // title text = new Phrase("Need to return somthing?", new Font(boldFont, 8)); ct.SetSimpleColumn(text, doc.PageSize.Width / 2 + 22f, 185f, doc.PageSize.Width - 47f, 205f, 0f, Element.ALIGN_LEFT); ct.Go(); // content text = new Phrase("Our Customer Loyalty Team is always heppy to help!" + "With just a few easy steps your order can be on its way back to us for a refund:\n" + "1. Check out our return policy to make sure your order qualifies: shop.ca/returns\n" + "2. Make sure the item to be returned is in the same condition as it arrived, " + "including all packaging and tags intact.\n" + "3.Contact us at 1.855.4.SHOPCA or shop.ca/help with your order number " + "and we'll help you set up the return, and send you a prepaid shipping label!" , new Font(baseFont, 7)); ct.SetSimpleColumn(text, doc.PageSize.Width / 2 + 22f, 60f, doc.PageSize.Width - 47f, 200f, 11f, Element.ALIGN_LEFT); ct.Go(); #endregion // additional words text = new Phrase("*®Aeroplan and the Aeroplan logo are registered trademarks of Aimia Canada Inc.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, doc.PageSize.Width / 2 + 15f, 60f, doc.PageSize.Width - 40f, 70f, 0f, Element.ALIGN_RIGHT); ct.Go(); #region Most Bottom Box draw.MoveTo(40f, 62f); draw.LineTo(doc.PageSize.Width - 40f, 62f); draw.Stroke(); draw.MoveTo(40f, 62f); draw.LineTo(40f, 47f); draw.Stroke(); draw.MoveTo(40f, 47f); draw.LineTo(doc.PageSize.Width - 40f, 47f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 47f); draw.LineTo(doc.PageSize.Width - 40f, 62f); draw.Stroke(); text = new Phrase("Have another question? Our Customer Loyalty Team is ready to help! Please contact us directly for all other inquiries at 1.855.4.SHOPCA (746722) or shop.ca/help.", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 47f, 42f, doc.PageSize.Width - 47f, 52f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion doc.Close(); if (!preview) { return; } // start the pdf for previewing if (System.Diagnostics.Process.GetProcessesByName(file).Length < 1) { System.Diagnostics.Process.Start(file); } }
/* a method that return all the new order values */ public ShopCaValues[] GetAllNewOrder() { // local field for storing order values List <ShopCaValues> list = new List <ShopCaValues>(); DataTable table = new DataTable(); using (SqlConnection connection = new SqlConnection(Credentials.OrderHubCon)) { SqlCommand command = new SqlCommand("SELECT OrderId, SupplierId, StoreName, OrderCreateDate, GrandTotal, TotalPrice, TotalTax, TotalShippingCost, TotalDiscount, BillToName, BillToAddress1, BillToAddress2, BillToCity, BillToState, BillToPostalCode, BillToPhone, " + "ShipToName, ShipToAddress1, ShipToAddress2, ShipToCity, ShipToState, ShipToPostalCode, ShipToPhone, OptionIn, ShippingMethod " + "FROM ShopCa_Order WHERE Complete ='False' ORDER BY OrderId", connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ShopCaValues value = new ShopCaValues(); string orderId = reader.GetString(0); value.OrderId = orderId; value.SupplierId = reader.GetString(1); value.StoreName = reader.GetString(2); value.OrderCreateDate = reader.GetDateTime(3); value.GrandTotal = reader.GetDecimal(4); value.TotalPrice = reader.GetDecimal(5); value.TotalTax = reader.GetDecimal(6); value.TotalShippingCost = reader.GetDecimal(7); value.TotalDiscount = reader.GetDecimal(8); value.BillTo.Name = reader.GetString(9); value.BillTo.Address1 = reader.GetString(10); value.BillTo.Address2 = reader.GetString(11); value.BillTo.City = reader.GetString(12); value.BillTo.State = reader.GetString(13); value.BillTo.PostalCode = reader.GetString(14); value.BillTo.DayPhone = reader.GetString(15); value.ShipTo.Name = reader.GetString(16); value.ShipTo.Address1 = reader.GetString(17); value.ShipTo.Address2 = reader.GetString(18); value.ShipTo.City = reader.GetString(19); value.ShipTo.State = reader.GetString(20); value.ShipTo.PostalCode = reader.GetString(21); value.ShipTo.DayPhone = reader.GetString(22); value.Option = reader.GetBoolean(23); value.ShippingMethod = reader.GetString(24); SqlDataAdapter adatper = new SqlDataAdapter("SELECT OrderItemId, Sku, Title, Ssrp, SsrpTax, Quantity, ItemPrice, ExtendedItemPrice, ItemTax, ItemShippingCost, ItemDiscount " + "FROM ShopCa_Order_Item WHERE OrderId = \'" + orderId + '\'', connection); adatper.Fill(table); for (int i = 0; i < table.Rows.Count; i++) { value.OrderItemId.Add(table.Rows[i][0].ToString()); value.Sku.Add(table.Rows[i][1].ToString()); value.Title.Add(table.Rows[i][2].ToString()); value.Ssrp.Add(Convert.ToDecimal(table.Rows[i][3])); value.SsrpTax.Add(Convert.ToDecimal(table.Rows[i][4])); value.Quantity.Add(Convert.ToInt32(table.Rows[i][5])); value.ItemPrice.Add(Convert.ToDecimal(table.Rows[i][6])); value.ExtendedItemPrice.Add(Convert.ToDecimal(table.Rows[i][7])); value.ItemTax.Add(Convert.ToDecimal(table.Rows[i][8])); value.ItemShippingCost.Add(Convert.ToDecimal(table.Rows[i][9])); value.ItemDiscount.Add(Convert.ToDecimal(table.Rows[i][10])); } table.Reset(); list.Add(value); } } return(list.ToArray()); }
/* a method that generate ShopCaValues object for the given order number (first version -> take from local) */ public ShopCaValues GenerateValue(string targetOrder, string filePath) { //Load xml file content XmlDocument doc = new XmlDocument(); doc.Load(filePath); int orderPosition = 1; int orderItemPosition = 1; // field for return ShopCaValues value = new ShopCaValues(); #region Retrieve Data foreach (XmlNode parentnode in doc.DocumentElement.SelectSingleNode("/shop_ca_feed")) { if (parentnode.Name == "order") { foreach (XmlNode order in doc.DocumentElement.SelectSingleNode("/shop_ca_feed/order[" + orderPosition + "]")) { // bool flag for determine if the order is the target -> default set to true bool isTarget = true; #region Order switch (order.Name) { case "order_id": // check if this order is the order that needs to be processed, if not set boolean flag to false if (order.InnerText != targetOrder) { isTarget = false; break; } value.OrderId = order.InnerText; break; case "supplier_id": value.SupplierId = order.InnerText; break; case "store_name": value.StoreName = order.InnerText; break; case "order_create_date": value.OrderCreateDate = DateTime.ParseExact(order.InnerText, "yyyy-MM-dd", CultureInfo.InvariantCulture); break; case "grand_total": value.GrandTotal = decimal.Parse(order.InnerText); break; case "total_price": value.TotalPrice = decimal.Parse(order.InnerText); break; case "total_tax": value.TotalTax = decimal.Parse(order.InnerText); break; case "total_shipping_cost": value.TotalShippingCost = decimal.Parse(order.InnerText); break; case "total_discount": value.TotalDiscount = decimal.Parse(order.InnerText); break; case "billing_first_name": value.BillTo.Name = order.InnerText; break; case "billing_last_name": value.BillTo.Name += " " + order.InnerText; break; case "billing_phone_number": value.BillTo.DayPhone = order.InnerText; break; case "billing_address_one": value.BillTo.Address1 = order.InnerText; break; case "billing_address_two": value.BillTo.Address2 = order.InnerText; break; case "billing_city": value.BillTo.City = order.InnerText; break; case "billing_province": value.BillTo.State = order.InnerText; break; case "billing_postalcode": value.BillTo.PostalCode = order.InnerText; break; case "opt_in": value.Option = bool.Parse(order.InnerText); break; #endregion #region Order Item case "order_item": foreach (XmlNode subnode in doc.DocumentElement.SelectSingleNode("/shop_ca_feed/order[" + orderPosition + "]/order_item[" + orderItemPosition + "]")) { switch (subnode.Name) { case "order_item_id": value.OrderItemId.Add(subnode.InnerText); break; case "sku": value.Sku.Add(subnode.InnerText); break; case "title": value.Title.Add(subnode.InnerText); break; case "ssrp": value.Ssrp.Add(decimal.Parse(subnode.InnerText)); break; case "ssrp_tax": value.SsrpTax.Add(decimal.Parse(subnode.InnerText)); break; case "quantity": decimal dec = decimal.Parse(subnode.InnerText); string tmp = dec.ToString("0.#"); value.Quantity.Add(int.Parse(tmp)); break; case "item_price": value.ItemPrice.Add(decimal.Parse(subnode.InnerText)); break; case "extended_item_price": value.ExtendedItemPrice.Add(decimal.Parse(subnode.InnerText)); break; case "item_tax": value.ItemTax.Add(decimal.Parse(subnode.InnerText)); break; case "item_shipping_cost": value.ItemShippingCost.Add(decimal.Parse(subnode.InnerText)); break; case "item_discount": value.ItemDiscount.Add(decimal.Parse(subnode.InnerText)); break; case "shipping_first_name": if (orderItemPosition == 1) { value.ShipTo.Name = subnode.InnerText; } break; case "shipping_last_name": if (orderItemPosition == 1) { value.ShipTo.Name += " " + subnode.InnerText; } break; case "shipping_address_one": if (orderItemPosition == 1) { value.ShipTo.Address1 = subnode.InnerText; } break; case "shipping_address_two": if (orderItemPosition == 1) { value.ShipTo.Address2 = subnode.InnerText; } break; case "shipping_city": if (orderItemPosition == 1) { value.ShipTo.City = subnode.InnerText; } break; case "shipping_province": if (orderItemPosition == 1) { value.ShipTo.State = subnode.InnerText; } break; case "shipping_postalcode": if (orderItemPosition == 1) { value.ShipTo.PostalCode = subnode.InnerText; } break; case "shipping_phone": if (orderItemPosition == 1) { value.ShipTo.DayPhone = subnode.InnerText; } break; case "shipping_method": if (orderItemPosition == 1) { value.ShippingMethod = subnode.InnerText; } break; } } //increment position (for multiple order item) orderItemPosition++; break; } #endregion // the case if it is not the target order -> skip to next order node if (!isTarget) { break; } } } //adjust position of order item orderPosition++; orderItemPosition = 1; } #endregion return(value); }