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)); } }
/// <summary> /// Re-Assigns PR's to the highest level revision assembly available for part numbers /// </summary> public void pushPrsUpRevisions() { CItemTools itemsTool = new CItemTools(this.theConnection); List <Item> thePrSearch = itemsTool.findItemsList("PR"); Parallel.ForEach(thePrSearch, (thePR) => { //(Item thePR in thePrSearch){ // get the PR and its associated parts // should be the ID's for the parts Console.WriteLine("parallel processing pr"); string affectedPart = thePR.getProperty("affected_item"); string rootCausePart = thePR.getProperty("root_cause_part"); Item affectedPartItem = itemsTool.findItemById(affectedPart, "part"); Item rootCausePartItem = itemsTool.findItemById(rootCausePart, "part"); // lock item for changes thePR.setAction("lock"); thePR.apply(); // fix the affected item part relationship if its set if (affectedPartItem != null) { // get the item number, get the part, set the part string affectedPartItemNumber = affectedPartItem.getProperty("item_number"); // default behavior is to higest rev when rev is not set Item affectedPartItemLatestRev = itemsTool.findItem("part", affectedPartItemNumber); thePR.setProperty("affected_item", affectedPartItemLatestRev.getID()); } // fix the root cause item part relationship if its set if (rootCausePartItem != null) { // get the item number, get the part, set the part string rootCausePartItemNumber = rootCausePartItem.getProperty("item_number"); // default behavior is to higest rev when rev is not set Item rootCausePartItemLatestRev = itemsTool.findItem("part", rootCausePartItemNumber); thePR.setProperty("root_cause_part", rootCausePartItemLatestRev.getID()); } // apply changes, unlock thePR.setAction("update"); thePR.apply(); thePR.setAction("unlock"); // current part is version and unlocked. thePR.apply(); }); }
private static void TraverseNodes(XmlNodeList nodes, CItemTools itemTool) { foreach (XmlNode node in nodes) { // Do something with the node. if (node.Attributes != null && node.Attributes["type"] != null) { // fix part links if (node.Attributes["type"].Value == "Change Controlled Item" || node.Attributes["type"].Value == "Part") { //Console.WriteLine(node.Attributes["type"].Value); //Console.WriteLine(node.InnerText); //Console.WriteLine(node.Attributes["keyed_name"].Value); string oldId = node.InnerText; string partNumber = node.Attributes["keyed_name"].Value; if (partNumber == "AS-UTA") { partNumber = "AS-UTA-006"; } Item arasItem = itemTool.findItem("Part", partNumber); while (arasItem == null) { Console.WriteLine("Part not found - Enter a new Part Number:" + partNumber); partNumber = Console.ReadLine(); arasItem = itemTool.findItem("Part", partNumber); } if (arasItem != null) { //Console.WriteLine("Old Item ID" + oldId + " New ID:" + arasItem.getID() + ""); node.InnerText = arasItem.getID(); node.Attributes["keyed_name"].Value = partNumber; //Console.WriteLine("New Item ID" + node.InnerText + " New ID:" + arasItem.getID() + ""); } else { Console.WriteLine("Item not found on ARAS" + partNumber); } } } TraverseNodes(node.ChildNodes, itemTool); } }
public bool movePartToRevLevel(StdBomStructures thePart) { bool success = false; CItemTools itemsTool = new CItemTools(this.theConnection); // go find the item we are attempting to revision Item theArasPart = itemsTool.findItem("part", thePart.BillNo.ToString(), thePart.Revision.ToString()); // found the revision. no need to increment. if (theArasPart != null) { string arasRevLevel = theArasPart.getProperty("major_rev"); Console.WriteLine("Revision Found:" + arasRevLevel + " MAS Rev:" + thePart.Revision.ToString() + " Imported Part Data:" + thePart.ToString()); } else if (thePart.Revision <= 99 && theArasPart == null) { // find the highest revision part Item highestRevLevelPart = itemsTool.findItem("part", thePart.BillNo.ToString()); if (highestRevLevelPart != null) { Console.WriteLine("cranking revision level:" + thePart.ToString()); string majorRev = highestRevLevelPart.getProperty("major_rev"); int arasRevLevel = int.Parse(majorRev); while (arasRevLevel < thePart.Revision) { // go ahead and revision the part, then fetcht he revision level to try and satisfy the while loop this.revisionPart(highestRevLevelPart); highestRevLevelPart = itemsTool.findItem("part", thePart.BillNo.ToString()); majorRev = highestRevLevelPart.getProperty("major_rev"); arasRevLevel = int.Parse(majorRev); //Console.WriteLine("Wrote:"+ arasRevLevel + " Of:" + thePart.Revision); } } else { Console.WriteLine("Missing Part or part rev in excess of Aras Limit " + thePart); } } return(success); }
/// Depracated /// <summary> /// takes in an input row from MAS and updates the BOMs in ARAS /// works on the current level revision /// </summary> /// /*public void updateBomRevisions(MasterStructure masterBomItem) { * // turns out that there are parts in the newest version of thre BOM export that Ted provided me. * // check if component rev ==0, not worth running if so * CItemTools itemsTool = new CItemTools(this.theConnection); * if (masterBomItem.revisionLevel != 0) * { * Item sourcItem = itemsTool.findItem("part", masterBomItem.parentPart); * Item bomItemNewRev = itemsTool.findItem("part", masterBomItem.partNumber, masterBomItem.revisionLevel.ToString()); * Item bomItemCurrentRev = itemsTool.findItem("part", masterBomItem.partNumber, "0"); * Console.ReadLine(); * // description is in the masBomItem.comment * if (sourcItem != null && bomItemCurrentRev != null && bomItemCurrentRev != null) * { * Console.WriteLine(masterBomItem.ToString()); * Console.ReadLine(); * var bomSearch = this.theConnection.newItem("Part BOM", "get"); * //bomSearch.setAction("lock"); * //bomSearch.apply(); * bomSearch.setAttribute("select", "related_id,quantity,source_id"); * bomSearch.setProperty("related_id", bomItemCurrentRev.getID()); * bomSearch.setPropertyCondition("related_id", "eq"); * bomSearch.setProperty("quantity", masterBomItem.bomQuantity.ToString()); * bomSearch.setPropertyCondition("quantity", "eq"); * bomSearch.setProperty("source_id", sourcItem.getID()); * bomSearch.setPropertyCondition("source_id", "eq"); * var results = bomSearch.apply(); * int count = results.getItemCount(); * if (count == 1) * { * //var bomItem = this.theConnection.newItem("Part BOM", "add"); * //if (quantity == "0") * // quantity = "1"; * //bomItem.setProperty("related_id", thePart.getID()); * //bomItem.setProperty("quantity", quantity); * //parent.addRelationship(bomItem); * //parent.apply(); * //System.Threading.Thread.Sleep(100); * * } * * // apply changes, unlock * bomSearch.setAction("update"); * bomSearch.apply(); * bomSearch.setAction("unlock"); * // current part is version and unlocked. * bomSearch.apply(); * * } * else * { * * Console.WriteLine("Item not in current DB" + masterBomItem.ToString()); * Console.WriteLine("Current Part Search Results:" + bomItemCurrentRev); * Console.ReadLine(); * } * } * else { * Console.WriteLine(masterBomItem.revisionLevel); * * } * * * }*/ public void updateAmStatus(List <MoldsStatus> theMoldsData) { CItemTools itemTool = new CItemTools(this.theConnection); foreach (MoldsStatus statusItem in theMoldsData) { Item thePart = itemTool.findItem("Part", statusItem.AMNum); if (thePart != null) { string action = null; switch (statusItem.Status) { case "Obsolete": action = "Obsolete"; break; case "Prototype": action = "Preliminary"; break; case "In Design": action = "Preliminary"; break; case "Inactive": action = "Superseded"; break; case "Active": action = "Released"; break; default: action = "void"; break; } if (action != "void") { Console.WriteLine("Part Updated:" + statusItem.AMNum + " State:" + statusItem.Status); thePart.promote(action, "Manual Revision Move"); var results = thePart.apply(); } } else { Console.WriteLine("Part Not found From Molds DB:" + statusItem.AMNum); } } return; }
public Item revisionPart(Item thePart) { CItemTools itemsTool = new CItemTools(this.theConnection); thePart.setAction("version"); Item returnedAction = thePart.apply(); // the new revision is currently locked, so unlock it to release it Item newRevision = itemsTool.findItem("part", thePart.getProperty("item_number")); //newRevision.setAction("unlock"); //newRevision.apply(); newRevision.promote("Released", "Manual Release"); // new revision is released, move on newRevision.apply(); return(thePart); }
public Item revisionPart(Item thePart) { CItemTools itemsTool = new CItemTools(this.theConnection); thePart.setAction("version"); var results = thePart.apply(); string errorString = results.getErrorString(); if (errorString != "") { throw new Exception("Exception on part promote:" + errorString); } // the new revision is currently locked, so unlock it to release it Item newRevision = itemsTool.findItem("part", thePart.getProperty("item_number")); newRevision.setAction("unlock"); results = newRevision.apply(); newRevision.promote("Released", "Manual Release"); // new revision is released, move on results = newRevision.apply(); errorString = results.getErrorString(); return(thePart); }
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); } }