コード例 #1
0
        public void runItemCost()
        {
            error = 0;
            Dictionary <string, double> B1_costs = msSqlDBHandler.getItemCosts(rproDBHandler);
            string modified_date = rproDBHandler.getServerDate(rproDBHandler);

            if (string.IsNullOrWhiteSpace(modified_date))
            {
                return;
            }
            InventoryBO            inventory = new InventoryBO(modified_date);
            Queue <CostDifference> updates   = rproDBHandler.matchItemCost(B1_costs);

            foreach (CostDifference update in updates)
            {
                if (update.B1cost == 0)
                {
                    rproDBHandler.addLog(MainController.LogType.ERROR, update.item_sid, update.alu, feature, "B1 and Rpro cost mismatch - Cost in B1 is 0 when cost in Rpro is " + update.RproCost.ToString("0.0000"), null);
                }
            }
            if (updates.Count == 0)
            {
                rproDBHandler.addLog(MainController.LogType.REPORT, null, null, feature, "No XML file is created because there are no items to update", null);
                return;
            }

            while (updates.Count > 0)
            {
                CostDifference update = updates.Dequeue();
                inventory.AddInventory(update.item_sid, update.B1cost);
            }
            string filepath = createInventoryXMLFilePath();

            try
            {
                inventory.save(filepath);
            }
            catch (Exception e)
            {
                string subject = "Exception occurred when running " + feature.ToString();
                string body    = "Exception occured when trying to create Inventory.xml during Item Cost. Filepath: " + filepath;
                rproDBHandler.addLog(MainController.LogType.EXCEPTION, null, null, feature, body, e);
                new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
                return;
            }

            string message = inventory.inventoryCount() + " items are updated in " + filepath;

            rproDBHandler.addLog(MainController.LogType.REPORT, null, null, feature, message, null);

            string command = settings.getItemCostCMDInstruction();
            string ecm     = settings.getECM();

            if (!string.IsNullOrWhiteSpace(command) && !string.IsNullOrWhiteSpace(ecm))
            {
                try
                {
                    ProcessStartInfo cmdsi = new ProcessStartInfo(ecm);
                    cmdsi.Arguments = command;
                    Process cmd = Process.Start(cmdsi);
                    cmd.WaitForExit();
                    Queue <CostDifference> costDifferences = getCostDifferences();
                    if (costDifferences.Count == 0)
                    {
                        rproDBHandler.addLog(MainController.LogType.REPORT, null, null, feature, "0 cost differences after running item cost.", null);
                    }
                    else
                    {
                        rproDBHandler.addLog(MainController.LogType.ERROR, null, null, feature, costDifferences.Count + " cost differences after running item cost.", null);
                    }
                }
                catch (Exception e)
                {
                    string subject = "Exception occurred when running " + feature.ToString();
                    string body    = "Exception occured when processing Inventory.xml using ECM.";

                    rproDBHandler.addLog(MainController.LogType.EXCEPTION, null, null, feature, "Exception occured when processing Inventory.xml using ECM.", e);
                    new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
                    return;
                }
            }
        }