Exemplo n.º 1
0
        public void createMyItem(string itemType)
        {
            try
            {
                // Get the service stub
                DataManagementService dmService   = DataManagementService.getService(Session.getConnection());
                ObjectOwner           objectOwner = new ObjectOwner();

                //根据物料号创建ITEMID
                ItemProperties itemProperty = new ItemProperties();

                itemProperty.ClientId    = "Maxtt-Test-demo10";                                   //物料名称
                itemProperty.ItemId      = "000092";                                              //物料代码
                itemProperty.RevId       = "00";                                                  //版本
                itemProperty.Name        = "Maxtt-Test";                                          //物料名称
                itemProperty.Type        = itemType;                                              //创建ITEM的类型
                itemProperty.Description = "Test Item for the SOA AppX sample application.Hello"; //描述
                //test
                itemProperty.Uom = "PCS";                                                         //单位

                //增加额外属性
                itemProperty.ExtendedAttributes = new ExtendedAttributes[2];   //增加多少个?
                ExtendedAttributes[] theExtendedAttr = new ExtendedAttributes[2];

                //第1个
                theExtendedAttr[0]            = new ExtendedAttributes();
                theExtendedAttr[0].Attributes = new Hashtable();
                theExtendedAttr[0].ObjectType = "Item Master";      //对应哪个form表
                theExtendedAttr[0].Attributes["project_id"] = "project_id";
                itemProperty.ExtendedAttributes[0]          = theExtendedAttr[0];

                //第2个
                theExtendedAttr[1]            = new ExtendedAttributes();
                theExtendedAttr[1].Attributes = new Hashtable();
                theExtendedAttr[1].ObjectType = "ItemRevision Master";      //对应哪个form表
                theExtendedAttr[1].Attributes["user_data_2"] = "data_2";
                itemProperty.ExtendedAttributes[1]           = theExtendedAttr[1];



                //链接服务器创建
                CreateItemsResponse response = dmService.CreateItems(new ItemProperties[] { itemProperty }, null, "");

                //调用查询构建器,查询ITEM和ITEMRevision
                ModelObject itemObj       = findModel("Item ID", new string[] { "Item ID" }, new string[] { itemProperty.ItemId });
                ModelObject itemReversion = findModel("MY_WEB_ITEM_REVISION", new string[] { "iid", "vid" }, new string[] { itemProperty.ItemId, itemProperty.RevId });


                //修改ITEM所有者
                //changeOnwer("maxtt", "项目管理", itemObj);
                //changeOnwer("maxtt", "项目管理", itemReversion);

                //新增版本--不能修改所有者不是infodba用户的ITEM
                //reviseItem(itemReversion);

                //修改原有的版本


                //deleteItems_single(itemReversion);

                //发布流程
                wf("MyRelease", itemReversion);
            }
            //catch (ServiceException e)
            catch (Exception e)
            {
                System.Console.Out.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
        /**
         * Create Items
         *
         * @param itemIds        Array of Item and Revision IDs
         * @param itemType       Type of item to create
         *
         * @return Set of Items and ItemRevisions
         *
         * @throws ServiceException  If any partial errors are returned
         */
        public CreateItemsOutput[] createItems(ItemIdsAndInitialRevisionIds[] itemIds, String itemType)
        //       throws ServiceException
        {
            // Get the service stub
            DataManagementService dmService = DataManagementService.getService(MyFormAppSession.getConnection());
            // Populate form type
            GetItemCreationRelatedInfoResponse relatedResponse = dmService.GetItemCreationRelatedInfo(itemType, null);

            String[] formTypes = new String[0];
            if (relatedResponse.ServiceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.getItemCretionRelatedInfo returned a partial error.");
            }

            formTypes = new String[relatedResponse.FormAttrs.Length];
            for (int i = 0; i < relatedResponse.FormAttrs.Length; i++)
            {
                FormAttributesInfo attrInfo = relatedResponse.FormAttrs[i];
                formTypes[i] = attrInfo.FormType;
            }

            ItemProperties[] itemProps = new ItemProperties[itemIds.Length];
            for (int i = 0; i < itemIds.Length; i++)
            {
                // Create form in cache for form property population
                ModelObject[] forms = createForms(itemIds[i].NewItemId, formTypes[0],
                                                  itemIds[i].NewRevId, formTypes[1],
                                                  null, false);
                ItemProperties itemProperty = new ItemProperties();

                itemProperty.ClientId    = "AppX-Test";
                itemProperty.ItemId      = itemIds[i].NewItemId;
                itemProperty.RevId       = itemIds[i].NewRevId;
                itemProperty.Name        = "AppX-Test";
                itemProperty.Type        = itemType;
                itemProperty.Description = "Test Item for the SOA AppX sample application.";
                itemProperty.Uom         = "";

                // Retrieve one of form attribute value from Item master form.
                ServiceData serviceData = dmService.GetProperties(forms, new String[] { "project_id" });
                if (serviceData.sizeOfPartialErrors() > 0)
                {
                    throw new ServiceException("DataManagementService.getProperties returned a partial error.");
                }
                Property property = null;
                try
                {
                    property = forms[0].GetProperty("project_id");
                }
                catch (NotLoadedException /*ex*/) {}


                // Only if value is null, we set new value
                if (property == null || property.StringValue == null || property.StringValue.Length == 0)
                {
                    itemProperty.ExtendedAttributes = new ExtendedAttributes[1];
                    ExtendedAttributes theExtendedAttr = new ExtendedAttributes();
                    theExtendedAttr.Attributes = new Hashtable();
                    theExtendedAttr.ObjectType = formTypes[0];
                    theExtendedAttr.Attributes["project_id"] = "project_id";
                    itemProperty.ExtendedAttributes[0]       = theExtendedAttr;
                }
                itemProps[i] = itemProperty;
            }


            // *****************************
            // Execute the service operation
            // *****************************
            CreateItemsResponse response = dmService.CreateItems(itemProps, null, "");

            // before control is returned the ChangedHandler will be called with
            // newly created Item and ItemRevisions



            // The AppXPartialErrorListener is logging the partial errors returned
            // In this simple example if any partial errors occur we will throw a
            // ServiceException
            if (response.ServiceData.sizeOfPartialErrors() > 0)
            {
                throw new ServiceException("DataManagementService.createItems returned a partial error.");
            }

            return(response.Output);
        }
Exemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="itemType">创建TC中ITEM的类型</param>
        /// <param name="codeNumber">物料号</param>
        /// <param name="CodeName">物料名称</param>
        /// <param name="longDetail">详细描述</param>
        /// <param name="unit">单位</param>
        /// <param name="productionType">物料属性(自制、外购、委外)</param>
        /// <param name="ReqName">物料申请人</param>
        public String createTCItem(String codeNumber, String CodeName, String longDetail, String unit, String productionType, String ReqName, String group)
        {
            String erroMsg = "";

            //处理详细描述,10-79插入详细描述,80-90不插入详细描述
            longDetail = codeNumber.Length < 2 ? ""
                        : (codeNumber.Substring(0, 2).CompareTo("80") >= 0 ? "" : longDetail);

            String itemType = codeNumber.Length >= 2 && codeNumber.Substring(0, 2).Equals("80") ?
                              cfg.get("CPTyep") : cfg.get("LBJType");

            try
            {
                DataManagementService dmService = DataManagementService.getService(Session.getConnection());

                //查询最新的ITEM版本
                //ModelObject LastestRevision = findModel("MY_WEB_ITEM_REVISION", new string[] { "iid" }, new string[] { codeNumber });
                ModelObject LastestRevision = findModel(cfg.get("query_builder_lastestRevisionById_name")
                                                        , new string[] { cfg.get("query_builder_lastestRevisionById_queryKey") }, new string[] { codeNumber });
                if (null != LastestRevision && !string.IsNullOrEmpty(LastestRevision.Uid))
                {
                    dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "release_status_list" });
                    dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "item_revision_id" });
                    dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "object_name" });
                    dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "IMAN_master_form_rev" });
                    var master = LastestRevision.GetProperty("IMAN_master_form_rev").ModelObjectArrayValue[0];
                    dmService.GetProperties(new ModelObject[] { master }, new string[] { cfg.get("exAttr_detail") });
                    dmService.GetProperties(new ModelObject[] { LastestRevision }, new string[] { "IMAN_specification" });
                    String item_revision_id = LastestRevision.GetProperty("item_revision_id").StringValue.ToString();

                    //如果名称、规格相同,不执行更新。
                    if (LastestRevision.GetProperty("object_name").StringValue.Equals(CodeName) &&
                        master.GetProperty(cfg.get("exAttr_detail")).StringValue.Equals(longDetail))
                    {
                        return(erroMsg);
                    }

                    if (LastestRevision.GetProperty("IMAN_specification").ModelObjectArrayValue.Length > 0)
                    {
                        return(codeNumber + "/" + item_revision_id + ":有图纸,请在TC中更新。");
                    }

                    ModelObject release_status_obj = null;
                    if (LastestRevision.GetProperty("release_status_list").ModelObjectArrayValue.Length > 0)
                    {
                        release_status_obj = LastestRevision.GetProperty("release_status_list").ModelObjectArrayValue[0];
                        dmService.GetProperties(new ModelObject[] { release_status_obj }, new string[] { "name" });
                    }
                    String release_status = null == release_status_obj ? "" : release_status_obj.GetProperty("name").StringValue;

                    //查询是否存在未发布版本
                    if (!release_status.Equals(cfg.get("publish_status_value")))
                    {
                        workflow_publish(cfg.get("publish_workflow"), LastestRevision);
                    }

                    //创建新版本前,修改ITEM数据
                    updateItem(codeNumber, CodeName, longDetail);
                    //创建新版本
                    reviseItem(LastestRevision, CodeName, longDetail, productionType, item_revision_id);
                }
                else
                {
                    //开始新增ITEM
                    //根据物料号创建ITEMID
                    ItemProperties itemProperty = new ItemProperties();
                    itemProperty.Type        = itemType;   //创建ITEM的类型
                    itemProperty.ItemId      = codeNumber; //物料代码
                    itemProperty.Name        = CodeName;   //物料名称
                    itemProperty.RevId       = "00";       //版本
                    itemProperty.Description = "";         //描述
                    itemProperty.Uom         = unit;       //单位

                    //增加额外属性-对于同一个form,只用一次ExtendedAttributes,多个属性写在Hashtable上
                    ExtendedAttributes exAttr = new ExtendedAttributes();
                    exAttr.Attributes = new Hashtable();
                    exAttr.ObjectType = itemType + "RevisionMaster";      //对应哪个form表
                    exAttr.Attributes[cfg.get("exAttr_productionType")] = productionType;
                    exAttr.Attributes[cfg.get("exAttr_detail")]         = longDetail;

                    itemProperty.ExtendedAttributes = new ExtendedAttributes[] { exAttr };

                    //创建前查找文件路径
                    var RootFile = (Teamcenter.Soa.Client.Model.Strong.Folder)findModel(cfg.get("query_builder_folder_name")
                                                                                        , new string[] { cfg.get("query_builder_folder_queryKey1"), cfg.get("query_builder_folder_queryKey2") }
                                                                                        , new string[] { cfg.get("query_builder_folder_queryval1"), cfg.get("query_builder_folder_queryval2") });

                    var TargetFolder = findFolder(group, RootFile, cfg.get("group_split_flag"));

                    //链接服务器创建Item
                    CreateItemsResponse response = dmService.CreateItems(new ItemProperties[] { itemProperty }, TargetFolder, "contents");
                    //CreateItemsResponse response = dmService.CreateItems(new ItemProperties[] { itemProperty }, null, "");
                    if (response.ServiceData.sizeOfPartialErrors() > 0)
                    {
                        return("创建ITEM失败。" + response.ServiceData.GetPartialError(0).Messages[0]);
                    }
                    //结束新增ITEM

                    //新增完后附加文件。
                    ModelObject itemReversion2add = findModel(cfg.get("query_builder_lastestRevisionById_name")
                                                              , new string[] { cfg.get("query_builder_lastestRevisionById_queryKey") }, new string[] { codeNumber });

                    //ModelObject datasets = createEmptyFile("Text",codeNumber, "./template/url.txt", "Text");
                    //createRelations(itemReversion2add, datasets, "IMAN_specification");
                    //changeOnwer(ReqName, datasets);

                    //创建dataset并关联,修改所有者

                    if (codeNumber.Length > 4 &&
                        //codeNumber.Substring(0,2).CompareTo("80") >= 0)
                        codeNumber.Substring(0, 2).Equals("80"))
                    {
                        var subCodeNumber    = codeNumber.Substring(0, 4);
                        var uploadCfgPramary = subCodeNumber.Equals("8102") || subCodeNumber.Equals("8301") ?
                                               "uploadFile_part" : "uploadFile_asm";
                        var cfgList = cfg.tc[uploadCfgPramary].ToObject <ArrayList>();
                        foreach (var uploadObj in cfgList)
                        {
                            var         uploadCfg     = JObject.Parse(uploadObj.ToString());
                            ModelObject datasets_temp = createEmptyFile(uploadCfg["datasetType"].ToString()
                                                                        , codeNumber
                                                                        , uploadCfg["filePath"].ToString()
                                                                        , uploadCfg["fileRefName"].ToString()
                                                                        , itemReversion2add
                                                                        , uploadCfg["relationType"].ToString()
                                                                        );
                            //createRelations(itemReversion2add, datasets_temp, uploadCfg["relationType"].ToString());
                            changeOnwer(ReqName, datasets_temp);
                        }
                    }
                }

                //调用查询构建器,查询ITEM和ITEMRevision
                ModelObject itemObj = findModel(cfg.get("query_builder_ItemById_name")
                                                , new string[] { cfg.get("query_builder_ItemById_queryKey") }, new string[] { codeNumber });
                ModelObject itemReversion = findModel(cfg.get("query_builder_lastestRevisionById_name")
                                                      , new string[] { cfg.get("query_builder_lastestRevisionById_queryKey") }, new string[] { codeNumber });
                if (null == itemObj || null == itemReversion)
                {
                    return("查询构建器失败。");
                }

                //修改所有者
                changeOnwer(ReqName, itemObj);
                changeOnwer(ReqName, itemReversion);

                //发布-外购件
                if (codeNumber.Length >= 2 && (codeNumber.Substring(0, 2).CompareTo("80") < 0))
                {
                    workflow_publish(cfg.get("publish_workflow"), itemReversion);
                }
            }
            catch (Exception e)
            {
                deleteItem(codeNumber);
                throw e;
            }

            return(erroMsg);
        }