/* ship and confirm the selected items */ private void shipmentConfirmButton_Click(object sender, EventArgs e) { // error check -> the case if the user has not select any of the order to confirm if (listview.CheckedItems.Count < 1) { MessageBox.Show("Please select the order you want to ship", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // get user confirmation ConfirmPanel confirm = new ConfirmPanel("Are you sure you want to ship the order you selected ?"); confirm.ShowDialog(this); // if user select to confirm, process the orders that have been checked if (confirm.DialogResult != DialogResult.OK) { return; } // start the timer timer.Start(); // set confirm button to enable shipmentConfirmButton.Enabled = false; // initialize orderList for further shipment confirm use int length = listview.CheckedItems.Count; orderList = new Order[length]; // adding each order to the list with source and transaction id for (int i = 0; i < length; i++) { Order order = new Order { Source = listview.CheckedItems[i].SubItems[0].Text, TransactionId = listview.CheckedItems[i].SubItems[4].Text }; orderList[i] = order; } // call backgorund worker if (!backgroundWorker.IsBusy) { backgroundWorker.RunWorkerAsync(); } }
/* create label button clicks that create shipment and retrieve the label and tracking number */ private void createLabelButton_Click(object sender, EventArgs e) { // ask for user confirmaiton ConfirmPanel confirm = new ConfirmPanel("Are you sure you want to ship the package ?"); confirm.ShowDialog(this); if (confirm.DialogResult != DialogResult.OK) { return; } trackingNumberTextbox.Text = "Shipping"; shipmentConfirmButton.Enabled = false; createLabelButton.Enabled = false; // start timer timerShip.Start(); // initialize field for shipment package switch (CHANNEL) { case "Sears": searsValues.Package = new Package(weightKgUpdown.Value, lengthUpdown.Value, widthUpdown.Value, heightUpdown.Value, serviceCombobox.SelectedItem.ToString(), serviceCombobox.SelectedItem.ToString(), "", "", "", ""); break; case "Shop.ca": shopCaValues.Package = new Package(weightKgUpdown.Value, lengthUpdown.Value, widthUpdown.Value, heightUpdown.Value, serviceCombobox.SelectedItem.ToString(), serviceCombobox.SelectedItem.ToString(), "", "", "", ""); break; case "Giant Tiger": giantTigerValues.Package = new Package(weightKgUpdown.Value, lengthUpdown.Value, widthUpdown.Value, heightUpdown.Value, serviceCombobox.SelectedItem.ToString(), serviceCombobox.SelectedItem.ToString(), "", "", "", ""); break; } if (!backgroundWorkerShip.IsBusy) { backgroundWorkerShip.RunWorkerAsync(); } }
/* end of day event */ private void endOfDayButton_Click(object sender, EventArgs e) { // check all the items that can be end of day foreach (ListViewItem item in listview.Items) { if (item.SubItems[0].Text == "Shop.ca" || item.SubItems[0].Text == "Giant Tiger") { item.Checked = true; } } // get confirmation from the user ConfirmPanel confirm = new ConfirmPanel("Are you sure you want to do the end of day for Canada Post?"); confirm.ShowDialog(this); // the case if user not conifrm or there is no shipment to end of day -> return if (confirm.DialogResult != DialogResult.OK || listview.CheckedItems.Count < 1) { return; } #region Real Work // set end of day button to disabled and cursor to wait state endOfDayButton.Enabled = false; Cursor.Current = Cursors.WaitCursor; // get all the manifest links string groupId = DateTime.Today.ToString("yyyyMMdd"); string[] list = canadaPost.TransmitShipments(groupId); // error check 1 if (canadaPost.Error) { MessageBox.Show(canadaPost.ErrorMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); endOfDayButton.Enabled = true; return; } Thread.Sleep(5000); // confirm each manifest and get artifact link List <string> manifestList = new List <string>(); foreach (string manifest in list) { manifestList.Add(canadaPost.GetManifest(manifest)); // error check 2 if (!canadaPost.Error) { continue; } MessageBox.Show(canadaPost.ErrorMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); endOfDayButton.Enabled = true; return; } Thread.Sleep(5000); // get artifact and save as pdf for (int i = 0; i < manifestList.Count; i++) { byte[] binary = canadaPost.GetArtifact(manifestList[i]); canadaPost.ExportLabel(binary, groupId + '_' + (i + 1), false, false); } // set end of day to true in database shopCa.PostShip(true, DateTime.ParseExact(groupId, "yyyyMMdd", CultureInfo.InvariantCulture)); giantTiger.PostShip(true, DateTime.ParseExact(groupId, "yyyyMMdd", CultureInfo.InvariantCulture)); // show the new result MessageBox.Show("Manifests have been successfully exported to\n" + canadaPost.SavePathManifest, "Congratulation"); ShowResult(); // set end of day button to enabled and cursor to default state endOfDayButton.Enabled = true; Cursor.Current = Cursors.Default; #endregion }
/* shipment confirm button clicks that send the confirm xml to sears */ private void shipmentConfirmButton_Click(object sender, EventArgs e) { // get user's confirmation ConfirmPanel confirm = new ConfirmPanel("Are you sure you want to ship this order ?"); confirm.ShowDialog(this); // get user confirmation if (confirm.DialogResult != DialogResult.OK) { return; } // start timer timerConfirm.Start(); // generate cancel list cancelList = new Dictionary <int, string>(); for (int i = 0; i < listview.Items.Count; i++) { if (listview.Items[i].SubItems[5].Text != "Cancelled") { continue; } string reason = listview.Items[i].SubItems[6].Text; // the case if the user has not provide the reason for cancelling a item if (reason == "") { MessageBox.Show("Please provide the reason of cancellation", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } cancelList.Add(i, reason); } // error check for non shipped items if (CHANNEL == "Sears" && cancelList.Count < searsValues.LineCount && searsValues.Package.TrackingNumber == "") { MessageBox.Show("There are items that are not shipped", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (CHANNEL == "Shop.ca" && cancelList.Count < shopCaValues.OrderItemId.Count && shopCaValues.Package.TrackingNumber == "") { MessageBox.Show("There are items that are not shipped", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (CHANNEL == "Giant Tiger" && cancelList.Count < giantTigerValues.VendorSku.Count && giantTigerValues.Package.TrackingNumber == "") { MessageBox.Show("There are items that are not shipped", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } progressbar.Visible = true; // call background worker if (!backgroundWorkerConfirm.IsBusy) { backgroundWorkerConfirm.RunWorkerAsync(); } }