Пример #1
0
        /* 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
        }
Пример #2
0
        /* 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;
                }
            }
        }
Пример #3
0
        private void backgroundWorkerShip_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            switch (CHANNEL)
            {
            case "Sears":
                #region UPS
                // initialize field for shipment
                Ups ups = new Ups();

                // post shipment confirm and get the digest string from response
                string[] digest = ups.PostShipmentConfirm(searsValues);

                // error checking
                if (ups.Error)
                {
                    MessageBox.Show(ups.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Result = true;
                    return;
                }

                // post shipment accept and get tracking number and image
                string[] acceptResult = ups.PostShipmentAccept(digest[1]);

                // error checking
                if (ups.Error)
                {
                    MessageBox.Show(ups.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Result = true;
                    return;
                }

                // retrieve identification number and tracking number
                searsValues.Package.IdentificationNumber = digest[0];
                searsValues.Package.TrackingNumber       = acceptResult[0];

                // update database set the order's tracking number and identification number
                new Sears().PostShip(searsValues.Package.TrackingNumber, searsValues.Package.IdentificationNumber, searsValues.TransactionId);

                // get the shipment label and show it
                ups.ExportLabel(acceptResult[1], searsValues.TransactionId, true);
                break;

                #endregion
            case "Shop.ca":
                #region Canada Post
            {
                // initialize field for shipment
                CanadaPost canadaPost = new CanadaPost();

                // create shipment for canada post
                string[] result = canadaPost.CreateShipment(shopCaValues.ShipTo, shopCaValues.Package);

                // error checking
                if (canadaPost.Error)
                {
                    MessageBox.Show(canadaPost.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Result = true;
                    return;
                }

                // retrieve tracking number, refund link and label link
                shopCaValues.Package.TrackingNumber = result[0];
                shopCaValues.Package.SelfLink       = result[1];
                shopCaValues.Package.LabelLink      = result[2];

                // update database set the order's tracking number refund link and label link
                new ShopCa().PostShip(shopCaValues.Package.TrackingNumber, shopCaValues.Package.SelfLink, shopCaValues.Package.LabelLink, shopCaValues.OrderId);

                // get artifect
                Thread.Sleep(5000);
                byte[] artifect = canadaPost.GetArtifact(result[2]);

                // error checking
                if (canadaPost.Error)
                {
                    MessageBox.Show(canadaPost.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Result = true;
                    return;
                }

                // get the shipment label and show it
                canadaPost.ExportLabel(artifect, shopCaValues.OrderId, true, true);
            }
            break;

                #endregion
            case "Giant Tiger":
                #region Canada Post
            {
                // initialize field for shipment
                CanadaPost canadaPost = new CanadaPost();

                // create shipment for canada post
                string[] result = canadaPost.CreateShipment(giantTigerValues.ShipTo, giantTigerValues.Package);

                // error checking
                if (canadaPost.Error)
                {
                    MessageBox.Show(canadaPost.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Result = true;
                    return;
                }

                // retrieve tracking number, refund link and label link
                giantTigerValues.Package.TrackingNumber = result[0];
                giantTigerValues.Package.SelfLink       = result[1];
                giantTigerValues.Package.LabelLink      = result[2];

                // update database set the order's tracking number refund link and label link
                new GiantTiger().PostShip(giantTigerValues.Package.TrackingNumber, giantTigerValues.Package.SelfLink, giantTigerValues.Package.LabelLink, giantTigerValues.PoNumber);

                // get artifect
                Thread.Sleep(5000);
                byte[] artifect = canadaPost.GetArtifact(result[2]);

                // error checking
                if (canadaPost.Error)
                {
                    MessageBox.Show(canadaPost.ErrorMessage, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Result = true;
                    return;
                }

                // get the shipment label and show it
                canadaPost.ExportLabel(artifect, giantTigerValues.PoNumber, true, true);
            }
            break;
                #endregion
            }

            // set bool flag to false
            e.Result = false;
        }