/* third constructor that show giant tiger order */ public DetailPage(GiantTigerValues value) { InitializeComponent(); giantTigerValues = value; ShowResult(value); // set flag to giant tiger CHANNEL = "Giant Tiger"; }
/* fourth constructor that take GiantTigerValues object as parameter */ public Package(GiantTigerValues value) { // generate package detail -> weight and dimensions decimal[] skuDetail = { 0, 0, 0, 0 }; foreach (decimal[] detailList in value.VendorSku.Select(GetSkuDetail).Where(detailList => !detailList.Equals(null))) { for (int i = 0; i < 4; i++) { skuDetail[i] += detailList[i]; } } // allocate data Weight = skuDetail[0] / 1000; Length = skuDetail[1]; Width = skuDetail[2]; Height = skuDetail[3]; // service is set to default Service = "Expedited Parcel"; SelfLink = ""; LabelLink = ""; }
/* the event for detail button click that show the detail page for the selected item */ private void detailButton_Click(object sender, EventArgs e) { // the case if the user does not select any thing or select more than one if (listview.CheckedItems.Count != 1) { MessageBox.Show("Please select one item to see more details", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } switch (listview.CheckedItems[0].SubItems[0].Text) { case "Sears": { // the case if it is sears order SearsValues value = sears.GenerateValue(listview.CheckedItems[0].SubItems[4].Text); new DetailPage(value).ShowDialog(this); } break; case "Shop.ca": { // the case if it is shopl.ca order ShopCaValues value = shopCa.GenerateValue(listview.CheckedItems[0].SubItems[4].Text); new DetailPage(value).ShowDialog(this); } break; case "Giant Tiger": { // the case if it is giant tiger order GiantTigerValues value = giantTiger.GenerateValue(listview.CheckedItems[0].SubItems[4].Text); new DetailPage(value).ShowDialog(this); } break; } }
/* background worker that processing each order from the orderList */ private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { // initialize all carrier fields Ups ups = new Ups(); CanadaPost canadaPost = new CanadaPost(); // start processing orders foreach (Order order in orderList) { // for sears order switch (order.Source) { case "Sears": { #region Sears Order // first get the detail for the order SearsValues value = sears.GenerateValue(order.TransactionId); // check if the order has been shipped before -> if not, ship it now if (value.Package.TrackingNumber == "") { value.Package = new Package(value); // second ship it string[] digest = ups.PostShipmentConfirm(value); if (ups.Error) { MessageBox.Show(ups.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string[] result = ups.PostShipmentAccept(digest[1]); if (ups.Error) { MessageBox.Show(ups.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // get identification, tracking, label and shipment confirm with no cancellation of item value.Package.IdentificationNumber = digest[0]; value.Package.TrackingNumber = result[0]; ups.ExportLabel(result[1], value.TransactionId, false); } sears.GenerateXml(value, new System.Collections.Generic.Dictionary <int, string>()); // post order to brightpearl with no cancellation bp.PostOrder(value, new int[0]); #endregion } break; case "Shop.ca": { #region Shop.ca Order // first get the detail for the order ShopCaValues value = shopCa.GenerateValue(order.TransactionId); // check if the order has been shipped before -> if not, ship it now if (value.Package.TrackingNumber == "") { value.Package = new Package(value); // second ship it string[] links = canadaPost.CreateShipment(value.ShipTo, value.Package); if (canadaPost.Error) { MessageBox.Show(canadaPost.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // get tracking, self link, label link and shipment confirm with no cancellation of item value.Package.TrackingNumber = links[0]; value.Package.SelfLink = links[1]; value.Package.LabelLink = links[2]; System.Threading.Thread.Sleep(5000); // get artifact and export it byte[] binary = canadaPost.GetArtifact(links[2]); canadaPost.ExportLabel(binary, value.OrderId, true, false); } shopCa.GenerateTxt(value, new System.Collections.Generic.Dictionary <int, string>()); // post order to brightpearl with no cancellation bp.PostOrder(value, new int[0]); #endregion } break; case "Giant Tiger": { #region Giant Tiger Order // first get the detail for the order GiantTigerValues value = giantTiger.GenerateValue(order.TransactionId); // check if the order has been shipped before -> if not, ship it now if (value.Package.TrackingNumber == "") { value.Package = new Package(value); // second ship it string[] links = canadaPost.CreateShipment(value.ShipTo, value.Package); if (canadaPost.Error) { MessageBox.Show(canadaPost.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // get tracking, self link, label link and shipment confirm with no cancellation of item value.Package.TrackingNumber = links[0]; value.Package.SelfLink = links[1]; value.Package.LabelLink = links[2]; System.Threading.Thread.Sleep(5000); // get artifact and export it byte[] binary = canadaPost.GetArtifact(links[2]); canadaPost.ExportLabel(binary, value.PoNumber, true, false); } giantTiger.GenerateCsv(value, new System.Collections.Generic.Dictionary <int, string>()); // post order to brightpearl with no cancellation bp.PostOrder(value, new int[0]); #endregion } break; } } }
/* a method that show the information of the given GiantTigerValues object */ private void ShowResult(GiantTigerValues value) { // title bar set up logoPicturebox.Image = Properties.Resources.giantTiger; topOrderNumberTextbox.Text = value.PoNumber; #region Order Summary // date orderDateTextbox.Text = value.OrderDate.ToString("MM/dd/yyyy"); paidDateTextbox.Text = value.OrderDate.ToString("MM/dd/yyyy"); shipByDateTextbox.Text = DateTime.Today.ToString("MM/dd/yyyy"); // unit price double cost = 0; for (int i = 0; i < value.VendorSku.Count; i++) { cost += value.UnitCost[i] * value.Quantity[i]; } unitPriceTotalTextbox.Text = cost.ToString(CultureInfo.InvariantCulture); // GST and HST gsthstTextbox.Text = "0.00"; // PST pstTextbox.Text = "0.00"; // other fee otherFeeTextbox.Text = "0.00"; // total totalOrderTextbox.Text = cost.ToString(CultureInfo.InvariantCulture); #endregion #region Buyer / Recipient Info // sold to soldToTextbox.Text = value.ShipTo.Name; soldToPhoneTextbox.Text = value.ShipTo.DayPhone; // ship to shipToNameTextbox.Text = value.ShipTo.Name; shipToAddress1Textbox.Text = value.ShipTo.Address1; shipToAddress2Textbox.Text = value.ShipTo.Address2; shipToCombineTextbox.Text = value.ShipTo.City + ", " + value.ShipTo.State + ", " + value.ShipTo.PostalCode; shipToPhoneTextbox.Text = value.ShipTo.DayPhone; #endregion #region Listview and Shipping Info // adding items to service combobox serviceCombobox.Items.Clear(); serviceCombobox.Items.Add("Expedited Parcel"); serviceCombobox.Items.Add("Regular Parcel"); serviceCombobox.Items.Add("Xpresspost"); serviceCombobox.Items.Add("Priority"); serviceCombobox.SelectedIndex = 0; // adding items to reason combobox reasonCombobox.Items.Clear(); reasonCombobox.Items.Add("Select Reason"); reasonCombobox.Items.Add("Out of Stock"); reasonCombobox.Items.Add("Customer Request"); reasonCombobox.Items.Add("Incorrect product setup"); reasonCombobox.SelectedIndex = 0; // initialize field for sku detail -> [0] weight, [1] length, [2] width, [3] height decimal[] skuDetail = { 0, 0, 0, 0 }; // adding list to listview and getting sku detail for (int i = 0; i < value.VendorSku.Count; i++) { // add item to list ListViewItem item = new ListViewItem(value.ClientItemId[i]); item.SubItems.Add("Host SKU: " + value.HostSku[i] + " - Ashlin SKU: " + value.VendorSku[i]); item.SubItems.Add("$ " + value.UnitCost[i]); item.SubItems.Add(value.Quantity[i].ToString()); item.SubItems.Add("$ " + value.UnitCost[i] * value.Quantity[i]); item.SubItems.Add(""); item.SubItems.Add(""); listview.Items.Add(item); // generate sku detail decimal[] detailList = Package.GetSkuDetail(value.VendorSku[i]); // the case if bad sku if (detailList == null) { item.BackColor = Color.FromArgb(254, 126, 116); } else { for (int j = 0; j < 4; j++) { skuDetail[j] += detailList[j]; } } } // show result to shipping info weightKgUpdown.Value = skuDetail[0] / 1000; weightLbUpdown.Value = skuDetail[0] / 453.592m; lengthUpdown.Value = skuDetail[1]; widthUpdown.Value = skuDetail[2]; heightUpdown.Value = skuDetail[3]; // shipment status -> the case if the order has already shipped if (value.Package.TrackingNumber == "") { return; } createLabelButton.Enabled = false; trackingNumberTextbox.Text = value.Package.TrackingNumber; voidShipmentButton.Visible = true; #endregion }
/* a method that post giant tiger order to brightpearl on giant tiger account */ public void PostOrder(GiantTigerValues value, int[] cancelList) { // check if the order is cancelled entirely -> if it is just return no need to post it if (cancelList.Length >= value.VendorSku.Count) { return; } #region Posting Order to Giant Tiger Account on BP // initialize order BPvalues object BPvalues orderValue = new BPvalues(value.ShipTo, value.PoNumber, value.OrderDate, 12, 1, null, null, 0, 0, 0, 0); // post order string orderId = post.PostOrderRequest("10115", orderValue); Status = "Getting order ID"; if (post.HasError) { Status = "Error occur during order post - Giant Tiger"; do { Thread.Sleep(5000); orderId = post.PostOrderRequest("10115", orderValue); } while (post.HasError); } // calculate the total amount when excluding the cancelled items for (int i = 0; i < value.VendorSku.Count; i++) { // the case if not cancel post it to brightpearl if (cancelList.Where(j => j == i).Any()) { continue; } #region Tax Determination double tax; switch (value.ShipTo.State) { case "NB": tax = 0.13; break; case "NF": tax = 0.15; break; case "NL": tax = 0.15; break; case "NS": tax = 0.15; break; case "ON": tax = 0.13; break; case "PEI": tax = 0.14; break; case "BC": tax = 0.05; break; case "MAN": tax = 0.05; break; case "PQ": tax = 0.05; break; case "QC": tax = 0.05; break; case "SK": tax = 0.05; break; case "AB": tax = 0.05; break; case "NV": tax = 0.05; break; case "YK": tax = 0.05; break; default: tax = 0; break; } #endregion // initialize BPvalues object -> no need total paid ( this is unit cost & no recipt ) double totalUnitCost = value.UnitCost[i] * value.Quantity[i]; BPvalues itemValue = new BPvalues(value.ShipTo, null, DateTime.Today, 12, 1, value.VendorSku[i], "Host SKU: " + value.HostSku[i], value.Quantity[i], totalUnitCost, totalUnitCost * tax, 0); // post order row string orderRowId = post.PostOrderRowRequest(orderId, itemValue); Status = "Getting order row ID"; if (post.HasError) { Status = "Error occur during order row post " + i + " - Giant Tiger"; do { Thread.Sleep(5000); orderRowId = post.PostOrderRowRequest(orderId, itemValue); } while (post.HasError); } // post reservation post.PostReservationRequest(orderId, orderRowId, itemValue); Status = "Posting reservation request " + i; if (!post.HasError) { continue; } Status = "Error occur during reservation post " + i + " - Giant Tiger"; do { Thread.Sleep(5000); post.PostReservationRequest(orderId, orderRowId, itemValue); } while (post.HasError); } #endregion }