示例#1
0
        /* cancel shipment button click that mark the selected order to cancelled in database */
        private void cancelShipmentButton_Click(object sender, EventArgs e)
        {
            // error check
            if (listview.CheckedItems.Count < 1)
            {
                MessageBox.Show("Please select the shipment you want to cancel", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // local fields for storing data -> [0] sears, [1] shop.ca, [2] giant tiger
            List <string>[] list    = { new List <string>(), new List <string>(), new List <string>() };
            bool[]          channel = { false, false, false };

            // adding cancel order list and post shipment void
            List <Order> cancelList = (from ListViewItem item in listview.CheckedItems
                                       select new Order
            {
                Source = item.SubItems[0].Text,
                TransactionId = item.SubItems[1].Text,
                ShipmentIdentificationNumber = item.SubItems[3].Text
            }).ToList();

            // cancellation to carriers
            foreach (Order cancelledOrder in cancelList)
            {
                switch (cancelledOrder.Source)
                {
                case "Sears":
                    list[0].Add(cancelledOrder.TransactionId);
                    ups.PostShipmentVoid(cancelledOrder.ShipmentIdentificationNumber);
                    if (ups.Error)
                    {
                        MessageBox.Show(ups.ErrorMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    channel[0] = true;
                    break;

                case "Shop.ca":
                    list[1].Add(cancelledOrder.TransactionId);
                    canadaPost.DeleteShipment(cancelledOrder.ShipmentIdentificationNumber);
                    if (canadaPost.Error)
                    {
                        MessageBox.Show(canadaPost.ErrorMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    channel[1] = true;
                    break;

                case "Giant Tiger":
                    list[2].Add(cancelledOrder.TransactionId);
                    canadaPost.DeleteShipment(cancelledOrder.ShipmentIdentificationNumber);
                    if (canadaPost.Error)
                    {
                        MessageBox.Show(canadaPost.ErrorMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    channel[2] = true;
                    break;
                }
            }

            // cancellation to database
            if (channel[0])
            {
                sears.PostVoid(list[0].ToArray());
            }
            if (channel[1])
            {
                shopCa.PostVoid(list[1].ToArray());
            }
            if (channel[2])
            {
                giantTiger.PostVoid(list[2].ToArray());
            }

            // show new result
            ShowResult();
        }
示例#2
0
        /* void shipment button that void the current shipment for the order */
        private void voidShipmentButton_Click(object sender, EventArgs e)
        {
            switch (CHANNEL)
            {
            case "Sears":
                #region UPS
                // post void shipment request and get the response
                Ups ups = new Ups();
                ups.PostShipmentVoid(searsValues.Package.IdentificationNumber);

                // the case if is bad request
                if (ups.Error)
                {
                    MessageBox.Show(ups.ErrorMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // mark transaction as not shipped
                new Sears().PostVoid(new[] { searsValues.TransactionId });

                // set tracking and identification to nothing
                searsValues.Package.IdentificationNumber = string.Empty;
                searsValues.Package.TrackingNumber       = string.Empty;

                break;

                #endregion
            case "Shop.ca":
                #region Canada Post
            {
                // post void shipment request and get the response
                CanadaPost canadaPost = new CanadaPost();
                canadaPost.DeleteShipment(shopCaValues.Package.SelfLink);

                // the cas if is bad request
                if (canadaPost.Error)
                {
                    MessageBox.Show(canadaPost.ErrorMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // mar order as not shipped
                new ShopCa().PostVoid(new[] { shopCaValues.OrderId });

                // set tracking, self link, label link to nothing
                shopCaValues.Package.TrackingNumber = string.Empty;
                shopCaValues.Package.SelfLink       = string.Empty;
                shopCaValues.Package.LabelLink      = string.Empty;
            }
            break;

                #endregion
            case "Giant Tiger":
                #region Canada Post
            {
                // post void shipment request and get the response
                CanadaPost canadaPost = new CanadaPost();
                canadaPost.DeleteShipment(giantTigerValues.Package.SelfLink);

                // the cas if is bad request
                if (canadaPost.Error)
                {
                    MessageBox.Show(canadaPost.ErrorMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // mar order as not shipped
                new GiantTiger().PostVoid(new[] { giantTigerValues.PoNumber });

                // set tracking, self link, label link to nothing
                giantTigerValues.Package.TrackingNumber = string.Empty;
                giantTigerValues.Package.SelfLink       = string.Empty;
                giantTigerValues.Package.LabelLink      = string.Empty;
            }
            break;
                #endregion
            }

            // mark cancel as invisible, set tracking number text to not shipped, and enable create label button
            voidShipmentButton.Visible = false;
            trackingNumberTextbox.Text = "Not shipped";
            createLabelButton.Enabled  = true;
        }