U9 API 调用分享之创建料品
ISV地址:
U9/Services/UFIDA.U9.ISV.Item.IBatchCreateItemByDTOSRV.svc
调用示例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
namespace 命名空间
{
static class CreateItemSvStub
{
public static string CreateItem(DataTable dt)
{
CreateItemStub.BatchCreateItemByDTOSRVStub client = new CreateItemStub.BatchCreateItemByDTOSRVStub();
List<CreateItemStub.UFIDAU9ISVItemItemMasterDTOData> listItem = new List<CreateItemStub.UFIDAU9ISVItemItemMasterDTOData>();
CreateItemStub.UFIDAU9ISVItemItemMasterDTOData itemInfo = new CreateItemStub.UFIDAU9ISVItemItemMasterDTOData();
itemInfo.m_code = dt.Rows[0][“item_code”].ToString();//料品编码
itemInfo.m_name = dt.Rows[0][“item_name”].ToString();//料品名称
itemInfo.m_sPECS = dt.Rows[0][“item_SPECS”].ToString();料品规格
itemInfo.m_itemFormAttribute = Convert.ToInt32(dt.Rows[0][“ItemFormAttribute”].ToString());//料品形态属性,请查询数据字段并和实施沟通具体传哪个数值
itemInfo.m_itemFormAttributeSpecified = true;
itemInfo.m_isInventoryEnable = true;//可库存交易
itemInfo.m_isInventoryEnableSpecified = true;
itemInfo.m_isPurchaseEnable = true;//可采购
itemInfo.m_isPurchaseEnableSpecified = true;
itemInfo.m_isSalesEnable = true;//可销售
itemInfo.m_isSalesEnableSpecified = true;
if (Convert.ToInt32(dt.Rows[0][“ItemFormAttribute”].ToString()) == 9)
{
itemInfo.m_isBuildEnable = false;//可自制
itemInfo.m_isBuildEnableSpecified = true;
}
else if (Convert.ToInt32(dt.Rows[0][“ItemFormAttribute”].ToString()) == 10)
{
itemInfo.m_isBuildEnable = true;
itemInfo.m_isBuildEnableSpecified = true;
}
itemInfo.m_isOutsideOperationEnable = true;//可委外
itemInfo.m_isOutsideOperationEnableSpecified = true;
//主分类
itemInfo.m_mainItemCategory = new CreateItemStub.UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
itemInfo.m_mainItemCategory.m_code = dt.Rows[0][“item_catory”].ToString();
itemInfo.m_isMRPEnable = true;//可MRP
itemInfo.m_isMRPEnableSpecified = true;
itemInfo.m_isBOMEnable = true;//可BOM
itemInfo.m_isBOMEnableSpecified = true;
CreateItemStub.UFIDAU9CBOPubControllerCommonArchiveDataDTOData uom = new CreateItemStub.UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
uom.m_code = dt.Rows[0][“item_uom”].ToString();//计量单位,要传实际的计量单位编码
itemInfo.m_inventoryUOM = uom;//库存主单位
itemInfo.m_inventorySecondUOM = uom;//库存单位
itemInfo.m_salesUOM = uom;//销售单位
itemInfo.m_purchaseUOM = uom;//采购单位
itemInfo.m_priceUOM = uom;//计价单位
itemInfo.m_manufactureUOM = uom;//生产单位
itemInfo.m_materialOutUOM = uom;//领料单位
itemInfo.m_costUOM = uom;//成本单位
itemInfo.m_converRatioRule = 0;// 转换率策略
itemInfo.m_converRatioRuleSpecified = true;
if (dt.Rows[0][“item_weight”].ToString() != “”)
{
itemInfo.m_weight = Convert.ToDecimal(dt.Rows[0][“item_weight”].ToString());//库存单位重量
itemInfo.m_weightSpecified = true;
}
//料品库存信息DTO
itemInfo.m_inventoryInfo = new CreateItemStub.UFIDAU9ISVItemItemInvInfoDTOData();
itemInfo.m_inventoryInfo.m_inventoryPlanningMethod = Convert.ToInt32(dt.Rows[0][“InventoryPlanningMethod”].ToString());//规划方法
itemInfo.m_inventoryInfo.m_inventoryPlanningMethodSpecified = true;
itemInfo.m_inventoryInfo.m_purchaseControlMode = 1;//采购控制方法
itemInfo.m_inventoryInfo.m_purchaseControlModeSpecified = true;
itemInfo.m_inventoryInfo.m_warehouse = new CreateItemStub.UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
itemInfo.m_inventoryInfo.m_warehouse.m_code = dt.Rows[0][“item_wh”].ToString();//在默认存储地点需要传编码
//料品采购信息DTO ItemPurchaseInfoDTO
itemInfo.m_purchaseInfo = new CreateItemStub.UFIDAU9ISVItemItemPurchaseInfoDTOData();
itemInfo.m_purchaseInfo.m_quotaSupplier = 1;//配额供应商
itemInfo.m_purchaseInfo.m_quotaSupplierSpecified = true;
itemInfo.m_purchaseInfo.m_receiptType = 0;//收货方式
itemInfo.m_purchaseInfo.m_receiptTypeSpecified = true;
itemInfo.m_purchaseInfo.m_priceSourceSpecified = true;
itemInfo.m_purchaseInfo.m_receiptMode = 0;//收货程序
itemInfo.m_purchaseInfo.m_receiptModeSpecified = true;
//料品销售信息DTO ItemSaleInfoDTO
itemInfo.m_saleInfo = new CreateItemStub.UFIDAU9ISVItemItemSaleInfoDTOData();
itemInfo.m_saleInfo.m_limitPriceMode = 0;//限价方式
itemInfo.m_saleInfo.m_limitPriceModeSpecified = true;
itemInfo.m_saleInfo.m_supplyOrg = new CreateItemStub.UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
itemInfo.m_saleInfo.m_supplyOrg.m_code = “……”;//供应组织编码
//料品生产信息DTO ItemMFGInfoDTO
itemInfo.m_mfgInfo = new CreateItemStub.UFIDAU9ISVItemItemMFGInfoDTOData();
itemInfo.m_mfgInfo.m_buildShrinkageRate = 1M;//产出率
itemInfo.m_mfgInfo.m_buildShrinkageRateSpecified = true;
itemInfo.m_mfgInfo.m_isSueOverType = -1;//备料超额类型
itemInfo.m_mfgInfo.m_isSueOverTypeSpecified = true;
itemInfo.m_mfgInfo.m_buildQuanSelectType = 0;//生产数量选择
itemInfo.m_mfgInfo.m_buildQuanSelectTypeSpecified = true;
itemInfo.m_mfgInfo.m_productDepartment = new CreateItemStub.UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
if (dt.Rows[0][“item_pt”].ToString() != “”)
{
itemInfo.m_mfgInfo.m_productDepartment.m_iD = long.Parse(dt.Rows[0][“item_pt”].ToString());//生产部门ID
itemInfo.m_mfgInfo.m_productDepartment.m_iDSpecified = true;
}
if (dt.Rows[0][“IsInheritBomMasterNo”].ToString() == “1”)
{
itemInfo.m_mfgInfo.m_isInheritBomMasterNo = true;//继承母项番
itemInfo.m_mfgInfo.m_isInheritBomMasterNoSpecified = true;
itemInfo.m_mfgInfo.m_defaultExpandLevel = Convert.ToInt32(dt.Rows[0][“DesignationRule”].ToString());//默认展开阶数
itemInfo.m_mfgInfo.m_defaultExpandLevelSpecified = true;
}
//料品MRP(计划)信息DTO ItemMRPInfoDTO
itemInfo.m_mrpInfo = new CreateItemStub.UFIDAU9ISVItemItemMRPInfoDTOData();
itemInfo.m_mrpInfo.m_forecastContorlType = 1;// 预测控制
itemInfo.m_mrpInfo.m_forecastContorlTypeSpecified = true;
itemInfo.m_mrpInfo.m_isTraceRequirement = true;//需求追溯
itemInfo.m_mrpInfo.m_isTraceRequirementSpecified = true;
if(dt.Rows[0][“InventoryPlanningMethod”].ToString()==”4″)
{
itemInfo.m_mrpInfo.m_mRPPlanningType = 1;//计划方法
itemInfo.m_mrpInfo.m_mRPPlanningTypeSpecified = true;
}
else
{
itemInfo.m_mrpInfo.m_mRPPlanningType = -1;
itemInfo.m_mrpInfo.m_mRPPlanningTypeSpecified = true;
}
//扩展字段
itemInfo.m_descFlexField = new CreateItemStub.UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
itemInfo.m_descFlexField.m_privateDescSeg1 = dt.Rows[0][“item_descFlexField1”].ToString();
itemInfo.m_descFlexField.m_privateDescSeg2 = dt.Rows[0][“item_descFlexField2”].ToString();
CreateItemStub.UFIDAU9CBOPubControllerContextDTOData context = new CreateItemStub.UFIDAU9CBOPubControllerContextDTOData();
context.m_entCode = “….”;//企业编码
context.m_orgCode = “….”;//组织编码
context.m_userCode = “….”;//用户编码
CreateItemStub.MessageBase[] messageBase = null;
listItem.Add(itemInfo);
try
{
CreateItemStub.UFIDAU9CBOSCMItemItemMasterData[] result = client.Do(GetItemAddContext(), listItem.ToArray(), context, out messageBase);
if (result != null && result.Length > 0)
{
return result[0].m_code.ToString() + “创建成功”;
}
else
{
return “失败”;
}
}
catch (System.Web.Services.Protocols.SoapException ex)
{
var rtn = ex.Detail.InnerXml;
return “ 错” + rtn;
}
}
static object GetItemAddContext()
{
List<CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType> sslist = new List<CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType>();
CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType ss = new CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
ss.Key = “OrgID”;
ss.Value =”….”;//组织ID;必须填写正确。
sslist.Add(ss);
CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType ss0 = new CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
ss0.Key = “UserID”;
ss0.Value = “….”;//用户ID;必须填写正确。
sslist.Add(ss0);
CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType _ss1 = new CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
_ss1.Key = “UserName”;
_ss1.Value = “….”;//对应单据的制单人
sslist.Add(_ss1);
CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType ss2 = new CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
ss2.Key = “CultureName”;
ss2.Value = “zh-CN”;
sslist.Add(ss2);
CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType ss3 = new CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
ss3.Key = “DefaultCultureName”;
ss3.Value = “zh-CN”;
sslist.Add(ss3);
CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType ss4 = new CreateItemStub.ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
ss4.Key = “EnterpriseID”;
ss4.Value = myVoid.enterprisecode;//企业编码;必须填写正确。
sslist.Add(ss4);
CreateItemStub.ThreadContext context = new CreateItemStub.ThreadContext();
context.nameValueHas = sslist.ToArray();
return context;
}
}
}
//代码部分到此结束
注意事项:
1 VS引用ISV时 要注意使用web引用
2 每个string型字段赋值后,要加上一句Specified = true,例下
itemInfo.m_mrpInfo.m_mRPPlanningType = 1;//计划方法
itemInfo.m_mrpInfo.m_mRPPlanningTypeSpecified = true;
3 示例参数dt,是自定义的一个料品信息的datatable,可根据自己应用场景,换成其它的如json等
以上为创建料品的API,有需要的朋友可以参考!希望朋友们多关注点赞,感谢!
下期分享创建销售订单的API!
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!