예제 #1
0
        public OrderStatus runSwitches(SwitchesSapOrderProperty switchObj, string id, string tableName)
        {
            string csrNote = "";

            startSwitchesLog(switchObj, id, tableName);

            OrderStatus status = va02.enterOrder(switchObj.orderNumber);

            if (status == OrderStatus.blockedByUser || status == OrderStatus.blockedByBatchJob)
            {
                return(status);
            }

            va02.bypassInitialPopups();

            status = va02.isChangeNeeded();

            if (status != OrderStatus.available)
            {
                return(status);
            }

            ITable table = va02.getTable();

            va02.moveRouteCodeColumnToIndexEight(table);

            foreach (var lineSwitch in switchObj.lineDetails)
            {
                int  sapLineNumber = (lineSwitch.lineNumber / 10 - 1);
                bool shouldChange  = isForChange(table, lineSwitch, sapLineNumber);
                bool isChanged     = false;

                if (shouldChange)
                {
                    string unitOfMeasure = table.getCellValue(sapLineNumber, "Un");
                    string itemCategory  = table.getCellValue(sapLineNumber, "ItCa");
                    string routeCode     = table.getCellValue(sapLineNumber, VA02.routeCodeColumnIndex); // have to use by index because the table retains its indexes by name after reordering but not actual indexes within a table
                    string cmir          = table.getCellValue(sapLineNumber, "Customer Material Numb");

                    table.setCellValue(sapLineNumber, "Material", lineSwitch.newSku);
                    sap.pressEnter();
                    sap.getRidOfPopUps();

                    string tempReason = "";
                    isChanged = va02.isLineChanged(table, lineSwitch, sapLineNumber, ref tempReason);

                    if (tempReason != "")
                    {
                        lineSwitch.reason = tempReason;
                    }

                    if (sap.getInfoBarMsg().Contains("Z4"))
                    {
                        return(OrderStatus.bothSkusAreZ4);
                    }

                    if (sap.getInfoBarMsg().Contains("not approved"))
                    {
                        return(OrderStatus.bothSkusAreNotApproved);
                    }

                    unitsOfMeasureAction(table, sapLineNumber, unitOfMeasure);
                    itemCategoryAction(table, sapLineNumber, itemCategory);
                    routeCodeAction(table, sapLineNumber, routeCode);
                    cmirAction(switchObj, table, lineSwitch, sapLineNumber, cmir);
                }

                csrNote += $"sku {lineSwitch.oldSku} has{(isChanged ? " " : " not ")}been switched to {lineSwitch.newSku}. Reason: {lineSwitch.reason}{Constants.vbCr}";

                endSwtichesLog(switchObj, id, tableName, lineSwitch, isChanged);
            }

            va02.soarAction(csrNote, "Line Switches", switchObj.orderNumber);
            va02.save();
            return(va02.getOrderStatusAfterSaving());
        }