Пример #1
0
        public Item findBomItem(MasterStructure incommingMasPart, Item parent = null, Item child = null)
        {
            CItemTools itemTool = this;

            // load up the parent item from the master structure item if its not sent in
            if (parent == null)
            {
                parent = itemTool.findItem("Part", incommingMasPart.parentPart, incommingMasPart.parentRevision.ToString());
            }
            // get the BOM item. If the rev is 999, get the most recent
            // 999 is a key to indicate that we are looking for the most current revision. if its not 999, find the most recent rev
            if (child == null)
            {
                if (incommingMasPart.revisionLevel != 999)
                {
                    child = itemTool.findItem("Part", incommingMasPart.partNumber, incommingMasPart.revisionLevel.ToString());
                }
                else
                {
                    child = itemTool.findItem("Part", incommingMasPart.partNumber);
                }
            }
            if (child == null || parent == null)
            {
                throw new Exception();
            }
            string childQuant = incommingMasPart.bomQuantity.ToString();
            // check to see if the BOM item is in the parent assembly
            var bomSearch = this.theConnection.newItem("Part BOM", "get");

            bomSearch.setAttribute("select", "related_id,quantity,source_id");
            bomSearch.setProperty("related_id", child.getID());
            bomSearch.setPropertyCondition("related_id", "eq");
            bomSearch.setProperty("quantity", childQuant);
            bomSearch.setPropertyCondition("quantity", "eq");
            bomSearch.setProperty("source_id", parent.getID());
            bomSearch.setPropertyCondition("source_id", "eq");
            var results = bomSearch.apply();
            int count   = results.getItemCount();

            if (count < 1)
            {
                return(null);
            }
            else
            {
                //Console.WriteLine("Item exsists in BOM already incomming:" + incommingMasPart);
                return(results.getItemByIndex(0));
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            string userInput = "";

            //string rawAML = "<AML><Item type=\"File\" id=\"763E4E3C005E4D70B1D0763A1F75F38C\" action=\"add\"><checkedout_path /><file_type keyed_name=\"JPEG Image\" type=\"FileType\">992B142FCE6C4EF8B71417220CD7E92D</file_type><mimetype>image/jpeg</mimetype><actual_filename>C:\\Users\\tom\\Pictures\\317A thumbmail.png</actual_filename><filename>317A thumbmail.png</filename><Relationships><Item type=\"Located\" id=\"71DE550313744E029E2C61CBA44134F8\" action=\"add\"><file_version>4</file_version><related_id keyed_name=\"Default\" type=\"Vault\">67BBB9204FE84A8981ED8313049BA06C</related_id><sort_order>128</sort_order><source_id keyed_name=\"1st Floor.Names and Title.jpg\" type=\"File\">763E4E3C005E4D70B1D0763A1F75F38C</source_id></Item></Relationships></Item></AML>";
            //ArasTools theTool = new ArasTools();
            //var results = theTool.theConnection.applyAML(rawAML);
            //if (results.getErrorString() != "")
            //    Console.WriteLine("Error String:" + results.getErrorString());

            while (userInput != "0")
            {
                Console.WriteLine("1. to delete parts and BOMs. \n2:Clear Old BOM Items \n3. Open/Save Operation \n4. Test manager function \n5. relink parts in aras export \n6. Push PR's" +
                                  " to current revs \n7. BOM Import Tool\n 8. Update Part States \n 9. Clear PR's on part and string search \n 0. to exit");
                userInput = Console.ReadLine();
                if (userInput == "1")
                {
                    ArasTools deleteTool = new ArasTools();
                    Console.WriteLine("Are you sure you want to delete all files? Y, N");
                    string confirm = Console.ReadLine();
                    if (confirm == "Y")
                    {
                        deleteTool.deleteAllItemTypes("Part");
                    }
                    else
                    {
                        Console.WriteLine("delete aborted");
                    }
                }

                else if (userInput == "2")
                {
                    ArasTools       theArasTool = new ArasTools();
                    MasterStructure master      = new MasterStructure();
                    master.importBom();
                    List <MasterStructure> theBoms   = master.ProcessedBom;
                    CItemTools             itemTools = new CItemTools(theArasTool.theConnection);
                    itemTools.clearOldPartBoms(theBoms, theArasTool);
                }
                else if (userInput == "3")
                {
                    ArasTools readSaveTool = new ArasTools();
                    Console.WriteLine("Open and save all files? Y, N");
                    string confirm = Console.ReadLine();
                    if (confirm == "Y" || confirm == "y")
                    {
                        Console.WriteLine("Name of the item types");
                        string itemType = Console.ReadLine();
                        readSaveTool.openAndSave(itemType);
                    }
                    else
                    {
                        Console.WriteLine("Re-Save aborted aborted");
                    }
                }
                else if (userInput == "4")
                {
                    ArasTools readSaveTool = new ArasTools();
                    Console.WriteLine("Test function? Y, N");
                    string confirm = Console.ReadLine();
                    if (confirm == "Y" || confirm == "y")
                    {
                        readSaveTool.setManager();
                    }
                    else
                    {
                        Console.WriteLine("Re-Save aborted aborted");
                    }
                }
                // standard BOM import
                else if (userInput == "5")
                {
                    ArasExportXmlTool xmlTool = new ArasExportXmlTool();
                    xmlTool.rFolderAffectedItemRelink();
                }
                else if (userInput == "6")
                {
                    ArasTools arasTool = new ArasTools();
                    arasTool.pushPrsUpRevisions();
                }

                else if (userInput == "7")
                {
                    // 1. remove all of the BOMs
                    ArasTools       arasTools = new ArasTools();
                    MasterStructure master    = new MasterStructure();
                    master.importBom();
                    List <MasterStructure> theBoms = master.ProcessedBom;
                    //Console.WriteLine("Deleting All BOMs & Parts");
                    System.Threading.Thread.Sleep(1000);
                    arasTools.deleteAllItemTypes("Part BOM");
                    arasTools.deleteAllItemTypes("Part");
                    // 2. add any parts in the MAS bom output that aren't currently in the db
                    // 3. push all revisions up, based upon the MAS bom output
                    // 4. Recreate the BOM's based upon the BOM Mas output
                    // 5. reassociate all of the PR's w/ the most current BOMS
                    // 6. Re-Associate all of the serials w/ the most current revisions



                    Console.WriteLine("Adding parts in records that are non exsistent");
                    System.Threading.Thread.Sleep(1000);
                    CItemTools itemTools = new CItemTools(arasTools.theConnection);
                    int        total     = theBoms.Count();
                    int        soFar     = 0;
                    Stopwatch  sw        = Stopwatch.StartNew();

                    // creating a list with new StdBomStructures Items. There will be nore parent part in this object
                    // the purpose of this list is to hold part numbers and revisions that have already been added to the database
                    // this will allow us to avoid a lot of queries looking for parts during the run.
                    List <MasterStructure> trackingList = new List <MasterStructure>();
                    foreach (MasterStructure bomItem in theBoms)
                    {
                        MasterStructure currentPartTracker = new MasterStructure();
                        currentPartTracker.partNumber    = bomItem.partNumber;
                        currentPartTracker.revisionLevel = bomItem.revisionLevel;
                        // The "locator" array is basically a search to make sure that the component we are looking at hasn't already been
                        // added to the ARAS database. There is a lot of overlap in a BOM structure, so this saves some query time.
                        var locator       = trackingList.FindAll(m => m.partNumber == bomItem.partNumber && m.revisionLevel == bomItem.revisionLevel);
                        var parentLocator = trackingList.FindAll(m => m.partNumber == bomItem.parentPart && m.revisionLevel == bomItem.parentRevision);
                        // check and see if the part has been added to the list of things we have already entered
                        if (locator.Count() < 1 || parentLocator.Count() < 1)
                        {
                            Item addedPart = itemTools.addStandardPart(bomItem);
                            currentPartTracker.partArasItem = addedPart;
                            trackingList.Add(currentPartTracker);
                            MasterStructure addParentToTracker = new MasterStructure();
                            addParentToTracker.partNumber    = bomItem.parentPart;
                            addParentToTracker.revisionLevel = bomItem.parentRevision;
                            trackingList.Add(addParentToTracker);

                            soFar++;
                            Console.WriteLine("check " + soFar);
                            int remainder = soFar % 300;
                            if (remainder == 0)
                            {
                                sw.Stop();
                                double avgRunTime   = (sw.Elapsed.TotalSeconds / soFar);
                                double totalRunTime = total * avgRunTime;
                                //NonBlockingConsole.WriteLine("Start:"+ sw.Elapsed.TotalMilliseconds/1000+" Total Count"+total+" Estimated Run Time:" + totalRunTime);
                                Console.WriteLine("Estimated Run Time:" + totalRunTime);
                                sw.Start();
                            }
                        }
                    }

                    //Console.WriteLine("Continue w/ PR Push");
                    //System.Threading.Thread.Sleep(5000);
                    //theArasTool.pushPrsUpRevisions();
                    Console.WriteLine("Continue w/ BOM Push");
                    System.Threading.Thread.Sleep(1000);
                    //var errorFile = new StreamWriter(@"errorLog.csv");
                    //using (errorFile)
                    //{
                    //    var writer = new CsvWriter(errorFile);
                    Parallel.ForEach(theBoms, (bomItem) => { arasTools.addPartToBom(bomItem); });

                    /*  foreach (MasterStructure bomItem in theBoms)
                     * {
                     *    arasTools.addPartToBom(bomItem);
                     * }*/
                    //}
                }
                else if (userInput == "8")
                {
                    MasterStructure    master           = new MasterStructure();
                    List <MoldsStatus> theStatusObjects = master.importMoldStatus();
                    ArasTools          theTool          = new ArasTools();
                    theTool.updateAmStatus(theStatusObjects);
                }
                else if (userInput == "9")
                {
                    Console.WriteLine("P.s. your screwed if you don't lock all the PR's before doing this. ok?");
                    Console.ReadLine();
                    ArasTools theArasTool = new ArasTools();
                    Console.WriteLine("Enter a section of part number for the affected item search. Hope you know what your doing. Careful....");
                    string partNumber = Console.ReadLine();
                    Console.WriteLine("Enter a string search to delete on. e.g. \'bubbles\'.  Hope you know what your doing. Careful....");
                    string  searchSTring = Console.ReadLine();
                    PrTools thePrTool    = new PrTools(theArasTool.theConnection);
                    thePrTool.clearPrWorkflow(partNumber, searchSTring);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// adds a part to ARAS. Does not check for revisions or handle BOMS
        /// </summary>
        /// <param name="incommingPart"></param>
        /// <returns></returns>
        public Item addStandardPart(MasterStructure incommingPart)
        {
            //CItemTools itemTools = new CItemTools(this.theConnection);
            // lets see if the root assembly exsists and add it if not
            // if the incomming part has a parent assembly, lets make sure its in there and add it
            Item thePart = null;

            // make sure there is something there before searching
            if (incommingPart.parentPart != null)
            {
                thePart = this.findItem("part", incommingPart.parentPart);
            }
            // if its not there and its called out, add it
            if (thePart == null && incommingPart.parentPart != null)
            {
                thePart = this.addPart(incommingPart.parentPart, incommingPart.parentPart + " " + incommingPart.parentPartName, "", "Assembly");
                // you only get an ID back when you add a part, so go fetch the big mamma
                thePart = this.findItem("Part", incommingPart.parentPart);
                //Console.WriteLine("Added Part: " + thePart);
            }
            // there is a parent out there, its defined, its been found. Make sure its designated as an Assembly
            else if (thePart != null && thePart.getProperty("classification") != "Assembly")
            {
                thePart.setAction("lock");
                thePart.apply();
                //foundPart.setProperty("description", "");
                thePart.setAttribute("version", "0");
                thePart.setAction("update");
                thePart.setProperty("classification", "Assembly");
                thePart.apply();
                thePart.setAction("unlock");
                thePart.apply();
            }
            // finally, set the parent part to the correct revision
            this.rollUpRevisions(thePart, incommingPart.parentRevision);
            // parent assembly is in. lets look for the child part.
            Item mainPart = this.findItem("Part", incommingPart.partNumber);

            if (mainPart == null)
            {
                mainPart = this.addPart(incommingPart.partNumber, incommingPart.partNumber + " " + incommingPart.comments, incommingPart.comments, "Component");
            }
            else
            {
                // the item is there, make sure hte item doesn't contain our description
                if (mainPart.getProperty("description") != null && !mainPart.getProperty("description").Contains(incommingPart.comments))
                {
                    // its in there, but there may be some notes that haven't been added, so I'll add them.
                    Console.WriteLine(incommingPart.partNumber + " Updated Description Added:" + incommingPart.comments + " resulting in:" + mainPart.getProperty("description"));
                    mainPart.setAction("lock");
                    mainPart.apply();
                    mainPart.setAttribute("version", "0");
                    mainPart.setAction("update");
                    mainPart.setProperty("description", mainPart.getProperty("description") + " " + incommingPart.comments);
                    mainPart.apply();
                    mainPart.setAction("unlock");
                    mainPart.apply();
                    //
                }
                else
                {
                    //Console.WriteLine""
                }
            }
            // child parts that are boms and have revisions should get rolled up, because they are part of the list of boms
            // components do not have revisions
            return(mainPart);
        }
        public Item addPartToBom(MasterStructure lineItem)
        {
            // Ted has added a revision level of 999 for the moat master configuration.
            // i dont know MAS allows him to do that, but oh well... just ignore it
            // he has also added 0 quantity items that are essentially work instructions
            if (lineItem.parentRevision != 999 || lineItem.bomQuantity != 0)
            {
                CItemTools itemTool = new CItemTools(theConnection);

                // get the BOM item. If the rev is 999, get the most recent
                Item   Child;
                string childQuant = lineItem.bomQuantity.ToString();

                Item parent = itemTool.findItem("Part", lineItem.parentPart, lineItem.parentRevision.ToString());
                if (lineItem.revisionLevel != 999)
                {
                    Child = itemTool.findItem("Part", lineItem.partNumber, lineItem.revisionLevel.ToString());
                }
                else
                {
                    Child = itemTool.findItem("Part", lineItem.partNumber);
                }
                if (parent != null && Child != null)
                {
                    Item findBomItem = itemTool.findBomItem(lineItem, parent, Child);

                    if (findBomItem == null)
                    {
                        var bomItem = this.theConnection.newItem("Part BOM", "add");
                        if (childQuant == "0" || childQuant == "" || childQuant == null)
                        {
                            childQuant = "1";
                        }
                        bomItem.setProperty("related_id", Child.getID());
                        bomItem.setProperty("quantity", childQuant);
                        parent.addRelationship(bomItem);
                        var    result = parent.apply();
                        string error  = result.getErrorString();
                        if (error != "")
                        {
                            throw new Exception("Exception on part add:" + error);
                        }
                        Console.WriteLine(lineItem + " BOM added to" + parent.getProperty("item_number"));
                    }
                    else
                    {
                    }
                }

                /*// load up the parent item from the master structure item
                 * Item parent = itemTool.findItem("Part", lineItem.parentPart, lineItem.parentRevision.ToString());
                 * // get the BOM item. If the rev is 999, get the most recent
                 * Item Child;
                 * string childQuant = lineItem.bomQuantity.ToString();
                 * // 999 is a key to indicate that we are looking for the most current revision. if its not 999, find the most recent rev
                 * if (lineItem.revisionLevel != 999)
                 *  Child = itemTool.findItem("Part", lineItem.partNumber, lineItem.revisionLevel.ToString());
                 * else
                 *  Child = itemTool.findItem("Part", lineItem.partNumber);
                 *
                 * // check to see if the BOM item is in the parent assembly
                 * var bomSearch = this.theConnection.newItem("Part BOM", "get");
                 * bomSearch.setAttribute("select", "related_id,quantity,source_id");
                 * bomSearch.setProperty("related_id", Child.getID());
                 * bomSearch.setPropertyCondition("related_id", "eq");
                 * bomSearch.setProperty("quantity", childQuant);
                 * bomSearch.setPropertyCondition("quantity", "eq");
                 * bomSearch.setProperty("source_id", parent.getID());
                 * bomSearch.setPropertyCondition("source_id", "eq");
                 * var results = bomSearch.apply();
                 * int count = results.getItemCount();
                 * if (count < 1)
                 * {
                 *
                 *
                 * }
                 * else {
                 *
                 * }*/

                //Console.ReadLine();
                return(parent);
            }
            else
            {
                return(null);
            }
        }