示例#1
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;
                }
            }
        }
示例#2
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;
        }