Esempio n. 1
0
        public int LoadOrders(Products itemList)
        {
            var orders    = SqlHelper.GetPendingOrders();
            var lineCount = orders.Rows.Count;

            InitProgressBar(this, new ProgressBarEventArgs(0, lineCount));

            foreach (DataRow row in orders.Rows)
            {
                var objOrdLine = new OrderLine(row);

                IncrementProgressBar(this, new ProgressBarEventArgs());
                Logger.Log(
                    String.Format("  Loaded order line {0}, Item - {1}", objOrdLine.Key, objOrdLine.ProductId),
                    LogLevel.Debug);

                var itemNum = objOrdLine.ProductId;

                Product item;
                if (!_cachedItems.TryGetValue(itemNum, out item))
                {
                    item = itemList.GetItem(itemNum);
                    _cachedItems.Add(itemNum, item);
                }
                objOrdLine.Item = item;

                Add(objOrdLine.Key, objOrdLine);
            }

            return(lineCount);
        }
Esempio n. 2
0
        public void ExecuteUpdate()
        {
            SqlTransaction trans = null;

            try
            {
                using (var cn = new SqlConnection(connectionString))
                {
                    cn.Open();
                    trans = cn.BeginTransaction();

                    UpdateOrderItems(trans, cn);
                    UpdateOrders(cn, trans);

                    trans.Commit();

                    Logger.Log("Orders updated successfully.");
                }
            }
            catch (SqlException)
            {
                if (trans != null)
                {
                    trans.Rollback();
                }

                throw;
            }
        }
Esempio n. 3
0
        public void AddUpdateRecord(ManifestRecord manifestRecord, XmlNode orderNode)
        {
            var updateRecord = new UpdateRecord(manifestRecord, orderNode);

            updateRecords.Add(updateRecord.OrderItemId, updateRecord);
            Logger.Log("Added UpdateRecord '" + updateRecord.Key + "'", LogLevel.Debug);
        }
Esempio n. 4
0
        public void SynchronizePackages(OrdersToPackages xref, UpdateRecords updates)
        {
            ManifestRecord manifestRec = null;

            foreach (XmlNode pkgNode in xref.FirstChild.ChildNodes)
            {
                // ReSharper disable PossibleNullReferenceException
                var key = pkgNode.Attributes["Key"].Value;
                if (ContainsKey(key))
                {
                    manifestRec = base[key];
                }
                else
                {
                    foreach (XmlNode orderNode in pkgNode.FirstChild.ChildNodes)
                    {
                        key = orderNode.Attributes["OrderNumber"].Value + "_" +
                              orderNode.Attributes["OrderItemID"].Value;
                        if (ContainsKey(key))
                        {
                            manifestRec = base[key];
                            break;
                        }
                    }
                }

                if (manifestRec == null)
                {
                    UnmatchedPackageCount++;
                    Logger.Log("   **** Unable to sync package '" + pkgNode.Attributes["ID"].Value +
                               "' with shipping info *****");
                    foreach (XmlNode orderNode in pkgNode.SelectSingleNode("Orders").ChildNodes)
                    {
                        Logger.Log(
                            String.Format("/tOrderID: {0}, OrderItemID: {1}", orderNode.Attributes["OrderID"].Value,
                                          orderNode.Attributes["OrderItemID"]), LogLevel.Debug);
                    }
                }
                else
                {
                    MatchedPackageCount++;
                    Logger.Log("Syncing shipping information for '" + manifestRec.Key + " and package '" +
                               pkgNode.Attributes["ID"].Value + "'", LogLevel.Verbose);
                    foreach (XmlNode orderNode in pkgNode.SelectSingleNode("Orders").ChildNodes)
                    {
                        updates.AddUpdateRecord(manifestRec, orderNode);
                    }
                    updates.AddOrderID(manifestRec.OrderId);
                }

                manifestRec = null;
                // ReSharper restore PossibleNullReferenceException
            }
        }
Esempio n. 5
0
        public void CustomerMatchup()
        {
            Customer       prevCustomer = null;
            CustomerOrders custOrd      = null;

            const byte IS_MATCH = 8;

            InitProgressBar(this, new ProgressBarEventArgs(0, Values.Count + 1));

            foreach (var currCustomer in rawCustomerList.Values)
            {
                if (prevCustomer == null)
                {
                    prevCustomer = currCustomer;
                    custOrd      = new CustomerOrders(currCustomer.OrderNumber, currCustomer.Key);
                    Logger.Log(String.Format("Created CustomerOrder '{0}'", currCustomer.Key));
                    Add(currCustomer.Key, currCustomer);
                    Logger.Log(String.Format("Added customer '{0}' to base collection.", currCustomer.Key),
                               LogLevel.Debug);
                    continue;
                }

                byte matchTest = currCustomer.IsSameCustomer(prevCustomer);

                if (matchTest == IS_MATCH)
                {
                    custOrd.Add(currCustomer.OrderNumber);
                    Logger.Log(String.Format("\tAdded order '{0}' to CustomerOrder '{1}'", currCustomer.OrderNumber,
                                             currCustomer.Key));
                }
                else
                {
                    ordersByCustomer.Add(custOrd.Key, custOrd);
                    Logger.Log(String.Format("  CustomerOrder '{0}' added to the collection.", custOrd.Key),
                               LogLevel.Verbose);
                    Add(currCustomer.Key, currCustomer);
                    Logger.Log(String.Format("Added customer '{0}' to base collection.", currCustomer.Key));

                    custOrd = new CustomerOrders(currCustomer.OrderNumber, currCustomer.Key);
                    Logger.Log(String.Format("Created CustomerOrder '{0}'", currCustomer.Key));
                    prevCustomer = currCustomer;
                }

                IncrementProgressBar(this, new ProgressBarEventArgs());
            }

            // ReSharper disable PossibleNullReferenceException
            ordersByCustomer.Add(custOrd.Key, custOrd);
            // ReSharper restore PossibleNullReferenceException

            Logger.Log(String.Format("  CustomerOrder '{0}' added to the collection.", custOrd.Key), LogLevel.Verbose);

            rawCustomerList.Clear();
        }
Esempio n. 6
0
 public OrdersToPackages(byte style)
 {
     pathFileName = Settings.AppPath + @"\XRefOrders2Packages.xml";
     pathFileName = pathFileName.Replace("file:\\", "");
     if (style == NewStyle.Init)
     {
         InitializeDocument();
         Logger.Log("XRefOrders2Packages.xml has been initialized.", LogLevel.Verbose);
     }
     else
     {
         LoadDocument();
         Logger.Log("XRefOrders2Packages.xml has been loaded.", LogLevel.Verbose);
     }
 }
Esempio n. 7
0
 public void AddOrderID(int orderId)
 {
     orderIds.Add(orderId, orderId);
     Logger.Log("Added OrderID '" + orderId + "'", LogLevel.Debug);
 }
Esempio n. 8
0
        public void LoadFiles()
        {
            var upsManifest    = Settings.UPSManifestFile;
            var usMailManifest = Settings.USMailManifestFile;
            var currentFile    = "";

            Logger.Log("Verifying manifest files exist...", LogLevel.Verbose);

            if (!File.Exists(upsManifest))
            {
                throw new MissingFileException(upsManifest);
            }
            Logger.Log(upsManifest + " verified.", LogLevel.Verbose);

            if (!File.Exists(usMailManifest))
            {
                throw new MissingFileException(usMailManifest);
            }
            Logger.Log(usMailManifest + " verified.", LogLevel.Verbose);

            try
            {
                // ReSharper disable PossibleNullReferenceException
                string         lineIn;
                var            headerSkipped = false;
                ManifestRecord rec;
                ManifestRecord dummy;

                Logger.Log("Loading records from UPS manifest file...", LogLevel.Verbose);
                currentFile = Settings.UPSManifestFileName();
                using (var sr = new StreamReader(upsManifest))
                {
                    while (!sr.EndOfStream)
                    {
                        lineIn = sr.ReadLine().Trim().Replace("\"", "");
                        if (String.IsNullOrEmpty(lineIn))
                        {
                            continue;
                        }

                        if (!headerSkipped)
                        {
                            headerSkipped = true;
                            continue;
                        }

                        rec = new ManifestRecord(lineIn, "UPS");
                        if (!TryGetValue(rec.Key, out dummy))
                        {
                            Add(rec.Key, rec);
                            upsLinesIn++;
                            Logger.Log("Added ManifestRecord " + rec.Key, LogLevel.Debug);
                        }
                    }
                }

                Logger.Log(String.Format("Loaded {0} records from UPS manifest file...", upsLinesIn), LogLevel.Verbose);

                Logger.Log("Loading records from USPS manifest file...", LogLevel.Verbose);
                currentFile = Settings.USMailManifestFileName();
                using (var sr = new StreamReader(usMailManifest))
                {
                    while (!sr.EndOfStream)
                    {
                        lineIn = sr.ReadLine().Trim().Replace("\"", "");
                        if (String.IsNullOrEmpty(lineIn))
                        {
                            continue;
                        }

                        rec = new ManifestRecord(lineIn, "USPS");
                        if (!TryGetValue(rec.Key, out dummy))
                        {
                            Add(rec.Key, rec);
                            usMailLinesIn++;
                            Logger.Log("Added ManifestRecord " + rec.Key, LogLevel.Debug);
                        }
                    }
                }

                Logger.Log(String.Format("Loaded {0} records from USPS manifest file...", usMailLinesIn),
                           LogLevel.Verbose);
                // ReSharper restore PossibleNullReferenceException
            }
            catch (IndexOutOfRangeException)
            {
                throw new ProcessManifestsException(currentFile + "does not appear to be in the correct format.", null);
            }
            catch (Exception ex)
            {
                throw new ProcessManifestsException("An exception occurred while loading the records from " + currentFile, ex);
            }
        }
Esempio n. 9
0
        public void CreatePackages()
        {
            Package shipPkg = null;

            InitProgressBar(this, new ProgressBarEventArgs(0, prePkgObjs.Values.Count + 1));

            foreach (var prePkg in prePkgObjs.Values)
            {
                IncrementProgressBar(this, new ProgressBarEventArgs());

                var objOrder    = orderList[prePkg.Key];
                var objCustomer = custList[prePkg.CustomerKey];

                XmlNode pkgNode;
                if (prePkg.SinglePackItems.Count > 0)
                {
                    foreach (var objOrdItem in prePkg.SinglePackItems.Values)
                    {
                        pkgNode = xrefList.CreatePackageNode(packageID, objOrdItem.OrderInfo);
                        // ReSharper disable PossibleNullReferenceException
                        Logger.Log(String.Format("  Package node created, {0} - {1}",
                                                 pkgNode.Attributes["ID"].Value, pkgNode.Attributes["Key"].Value),
                                   LogLevel.Debug);
                        // ReSharper restore PossibleNullReferenceException

                        xrefList.AddOrderNode(pkgNode, objOrdItem.OrderInfo, objOrdItem.Quantity);
                        Logger.Log(String.Format("    Order line added, {0} - {1} - {2}",
                                                 objOrdItem.OrderInfo.OrderNumber, objOrdItem.OrderInfo.OrderItemId,
                                                 objOrdItem.OrderInfo.OrderId), LogLevel.Debug);

                        var objItem    = objOrdItem.Item;
                        var shipUSMail = (objItem.ShipUSMail || objCustomer.POBox);
                        shipPkg = new Package(packageID, objItem, objOrder, objOrdItem.OrderInfo.OrderItemId,
                                              objCustomer, (shipUSMail ? "USPS" : "UPS"));

                        if (objItem.HasDimensions)
                        {
                            shipPkg.SetDimensions(objItem);
                        }

                        shipPkg.Weight = objItem.Weight;

                        Add(packageID.ToString(), shipPkg);
                        xrefList.AddPackageNode(pkgNode);

                        Logger.Log(String.Format("  Package node added, {0}", pkgNode.Attributes["ID"].Value),
                                   LogLevel.Debug);

                        packageID++;

                        if (objItem.IsKit)
                        {
                            {
                                for (int i = 0; i < objItem.SubItems.Count - 1; i++)
                                {
                                    var tempItem   = itemList.GetItem(objItem.SubItems[i]);
                                    var newShipPkg = new Package(packageID, shipPkg, tempItem);

                                    if (tempItem.HasDimensions)
                                    {
                                        newShipPkg.SetDimensions(tempItem);
                                    }

                                    newShipPkg.Weight = tempItem.Weight;

                                    Add(packageID.ToString(), newShipPkg);

                                    packageID++;
                                }
                            }
                        }
                    }
                }

                pkgNode = null;

                foreach (var multiPackList in prePkg.MultiPackItems.Values)
                {
                    // ReSharper disable PossibleNullReferenceException
                    if (multiPackList.Count > 0)
                    {
                        var multiItemList = new PackageItems();
                        foreach (var objOrdItem in multiPackList.Values)
                        {
                            multiItemList.AddItem(objOrdItem);
                            if (pkgNode == null)
                            {
                                pkgNode = xrefList.CreatePackageNode(packageID, objOrdItem.OrderInfo);
                                shipPkg = new Package(packageID, objOrder, objCustomer, objOrdItem.OrderInfo);
                                Logger.Log(String.Format("  Package node created, {0} - {1}",
                                                         pkgNode.Attributes["ID"].Value, pkgNode.Attributes["Key"].Value),
                                           LogLevel.Debug);
                            }

                            xrefList.AddOrderNode(pkgNode, objOrdItem.OrderInfo, objOrdItem.Quantity);
                            Logger.Log(String.Format("    Order line added, {0} - {1} - {2}",
                                                     objOrdItem.OrderInfo.OrderNumber,
                                                     objOrdItem.OrderInfo.OrderItemId,
                                                     objOrdItem.OrderInfo.OrderId), LogLevel.Debug);
                        }

                        multiItemList.CalcWeightAndSize(itemList);
                        shipPkg.AddItems(multiItemList);
                        shipPkg.SetCarrier(itemList);
                        Add(packageID.ToString(), shipPkg);
                        xrefList.AddPackageNode(pkgNode);

                        Logger.Log(String.Format("  Package node added, {0}", pkgNode.Attributes["ID"].Value),
                                   LogLevel.Debug);

                        packageID++;
                    }

                    pkgNode = null;
                    // ReSharper restore PossibleNullReferenceException
                }
            }

            xrefList.SaveDocument();

            Settings.PackageID = packageID;
        }
Esempio n. 10
0
        public void ProcessOrderLines(OrderLines lines, Customers custList)
        {
            Order    objOrder = null;
            Customer objCust  = null;

            var previousOrderNum = "";

            InitProgressBar(this, new ProgressBarEventArgs(0, lines.Values.Count + 1));

            try
            {
                foreach (var objLine in lines.Values)
                {
                    IncrementProgressBar(this, new ProgressBarEventArgs());

                    var currentOrderNum = objLine.OrderNumber;

                    if (currentOrderNum == previousOrderNum)
                    {
                        // ReSharper disable PossibleNullReferenceException
                        objOrder.AddOrderItem(objLine);
                        Logger.Log("    Adding suborder " + objLine.OrderItemID + " to " + currentOrderNum + ".",
                                   LogLevel.Debug);
                        // ReSharper restore PossibleNullReferenceException
                    }
                    else
                    {
                        if (objOrder == null)
                        {
                            objOrder = new Order(objLine);
                            Logger.Log(
                                "Creating object for order number '" + currentOrderNum + "' (suborder " +
                                objLine.OrderItemID + ").", LogLevel.Debug);
                            objCust = new Customer(objLine);
                            Logger.Log("Created object for customer " + objLine.LastName + ", " + objLine.FirstName,
                                       LogLevel.Debug);
                        }
                        else
                        {
                            Add(objOrder.OrderNumber, objOrder);
                            custList.AddCustomer(objCust, objOrder);
                            Logger.Log("  Order '" + objOrder.OrderNumber + "' added to the base collection.",
                                       LogLevel.Debug);

                            objOrder = new Order(objLine);
                            Logger.Log(
                                "Creating object for order number '" + currentOrderNum + "' (suborder " +
                                objLine.OrderItemID + ").", LogLevel.Debug);
                            objCust = new Customer(objLine);
                            Logger.Log("Created object for customer " + objLine.LastName + ", " + objLine.FirstName,
                                       LogLevel.Debug);
                        }
                    }

                    previousOrderNum = currentOrderNum;
                }

                // ReSharper disable PossibleNullReferenceException
                Add(objOrder.OrderNumber, objOrder);
                custList.AddCustomer(objCust, objOrder);
                Logger.Log("  Order '" + objOrder.OrderNumber + "' added to the base collection.", LogLevel.Debug);
                // ReSharper restore PossibleNullReferenceException
            }
            catch (Exception ex)
            {
                throw new ProcessOrderException("An exception occurred while processing the order lines collection.", ex);
            }
        }