|
楼主 |
发表于 2020-2-19 10:18:39
|
显示全部楼层
下面是完整代码,U8ApiBroker broker = new U8ApiBroker(myApiAddress, envContext);//运行到这一句 程序退出,无报错
U8Login.clsLogin u8Login = new U8Login.clsLogin();
String sSubId = "AS";
String sAccID = "(default)@666";
String sYear = "2019";
String sUserID = "demo";
String sPassword = "demo";
String sDate = "2019-12-22";
String sServer = @"192.168.2.203";
String sSerial = "";
if (!u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial))
{
Console.WriteLine("登陆失败,原因:" + u8Login.ShareString);
Marshal.FinalReleaseComObject(u8Login);
return;
}
//第二步:构造环境上下文对象,传入login,并按需设置其它上下文参数
U8EnvContext envContext = new U8EnvContext();
envContext.U8Login = u8Login;
//第三步:设置API地址标识(Url)
U8ApiAddress myApiAddress = new U8ApiAddress("U8API/MaterialOut/Add");
U8ApiBroker broker = new U8ApiBroker(myApiAddress, envContext);
//第五步:API参数赋值
//给普通参数sVouchType赋值。此参数的数据类型为System.String,此参数按值传递,表示单据类型:11
System.String ss = "11";
broker.AssignNormalValue("sVouchType", ss);
BusinessObject DomHead = broker.GetBoParam("DomHead");
DomHead.RowCount = 1; //设置BO对象(表头)行数,只能为一行
/****************************** 以下是必输字段 ****************************/
DomHead[0]["id"] = "111"; //主关键字段,int类型
DomHead[0]["ccode"] = ""; //出库单号,string类型
DomHead[0]["ddate"] = "2020-2-1 00:00:00"; //出库日期,DateTime类型
DomHead[0]["cwhname"] = ""; //仓库,string类型
/***************************** 以下是非必输字段 ****************************/
DomHead[0]["cmodifyperson"] = ""; //修改人,string类型
DomHead[0]["dmodifydate"] = ""; //修改日期,DateTime类型
DomHead[0]["dnmaketime"] = ""; //制单时间,DateTime类型
DomHead[0]["dnmodifytime"] = ""; //修改时间,DateTime类型
DomHead[0]["dnverifytime"] = ""; //审核时间,DateTime类型
DomHead[0]["hcinvdefine1"] = ""; //存货自定义项1,string类型
DomHead[0]["hcinvdefine2"] = ""; //存货自定义项2,string类型
DomHead[0]["hcinvdefine3"] = ""; //存货自定义项3,string类型
DomHead[0]["hcinvdefine4"] = ""; //存货自定义项3,string类型
DomHead[0]["hcinvdefine5"] = ""; //存货自定义项5,string类型
DomHead[0]["hcinvdefine6"] = "";
DomHead[0]["hcinvdefine7"] = "";
DomHead[0]["hcinvdefine8"] = "";
DomHead[0]["hcinvdefine9"] = ""; //存货自定义项9,string类型
DomHead[0]["hcinvdefine10"] = ""; //存货自定义项10,string类型
DomHead[0]["hcinvdefine11"] = ""; //存货自定义项11,int类型
DomHead[0]["hcinvdefine12"] = ""; //存货自定义项12,int类型
DomHead[0]["hcinvdefine13"] = ""; //存货自定义项13,double类型
DomHead[0]["hcinvdefine14"] = ""; //存货自定义项14,double类型
DomHead[0]["hcinvdefine15"] = ""; //存货自定义项15,DateTime类型
DomHead[0]["hcinvdefine16"] = ""; //存货自定义项16,DateTime类型
DomHead[0]["cinvstd"] = ""; //规格型号,string类型
DomHead[0]["dchkdate"] = ""; //检验日期,DateTime类型
DomHead[0]["iavaquantity"] = ""; //可用量,string类型
DomHead[0]["iavanum"] = ""; //可用件数,string类型
DomHead[0]["ipresentnum"] = ""; //现存件数,string类型
DomHead[0]["ufts"] = ""; //时间戳,string类型
DomHead[0]["iproorderid"] = "0000000010"; //生产订单ID,string类型
DomHead[0]["cmpocode"] = ""; //订单号,string类型
DomHead[0]["cpspcode"] = ""; //产品编码,string类型
DomHead[0]["cproinvaddcode"] = "01102"; //存货代码,string类型
DomHead[0]["ireturncount"] = ""; //ireturncount,string类型
DomHead[0]["iverifystate"] = ""; //iverifystate,string类型
DomHead[0]["iswfcontrolled"] = ""; //iswfcontrolled,string类型
DomHead[0]["imquantity"] = "100"; //产量,double类型
DomHead[0]["cprobatch"] = ""; //生产批号,string类型
DomHead[0]["cbustype"] = ""; //业务类型,int类型
DomHead[0]["cbuscode"] = ""; //业务号,string类型
DomHead[0]["cchkperson"] = ""; //检验员,string类型
DomHead[0]["crdname"] = ""; //出库类别,string类型
DomHead[0]["cdepname"] = ""; //部门,string类型
DomHead[0]["itopsum"] = ""; //最高库存量,string类型
DomHead[0]["ilowsum"] = ""; //最低库存量,string类型
DomHead[0]["cvenabbname"] = ""; //委外商,string类型
DomHead[0]["bomfirst"] = ""; //bomfirst,string类型
DomHead[0]["isafesum"] = ""; //安全库存量,string类型
DomHead[0]["dveridate"] = ""; //审核日期,DateTime类型
DomHead[0]["crdcode"] = ""; //出库类别编码,string类型
DomHead[0]["cmemo"] = ""; //备注,string类型
DomHead[0]["cmaker"] = ""; //制单人,string类型
DomHead[0]["chandler"] = ""; //审核人,string类型
DomHead[0]["caccounter"] = ""; //记账人,string类型
DomHead[0]["ipresent"] = ""; //现存量,string类型
DomHead[0]["cinvname"] = ""; //产品名称,string类型
DomHead[0]["biscomplement"] = ""; //补料标志,int类型
DomHead[0]["cpersonname"] = ""; //业务员,string类型
DomHead[0]["bpositive"] = ""; //红蓝标识,string类型
DomHead[0]["cdefine1"] = ""; //表头自定义项1,string类型
DomHead[0]["cdefine11"] = ""; //表头自定义项11,string类型
DomHead[0]["cdefine12"] = ""; //表头自定义项12,string类型
DomHead[0]["cdefine13"] = ""; //表头自定义项13,string类型
DomHead[0]["cdefine14"] = ""; //表头自定义项14,string类型
DomHead[0]["cdefine2"] = ""; //表头自定义项2,string类型
DomHead[0]["cdefine3"] = ""; //表头自定义项3,string类型
DomHead[0]["csource"] = ""; //单据来源,int类型
DomHead[0]["cdefine5"] = ""; //表头自定义项5,int类型
DomHead[0]["cdefine15"] = ""; //表头自定义项15,int类型
DomHead[0]["cdefine6"] = ""; //表头自定义项6,DateTime类型
DomHead[0]["brdflag"] = ""; //收发标志,string类型
DomHead[0]["cdefine7"] = ""; //表头自定义项7,double类型
DomHead[0]["cdefine16"] = ""; //表头自定义项16,double类型
DomHead[0]["cdefine8"] = ""; //表头自定义项8,string类型
DomHead[0]["cdefine9"] = ""; //表头自定义项9,string类型
DomHead[0]["cvencode"] = ""; //委外商编码,string类型
DomHead[0]["cdefine10"] = ""; //表头自定义项10,string类型
DomHead[0]["cvouchtype"] = ""; //单据类型,string类型
DomHead[0]["cwhcode"] = "0101"; //仓库编码,string类型
DomHead[0]["cdepcode"] = ""; //部门编码,string类型
DomHead[0]["cpersoncode"] = ""; //业务员编码,string类型
DomHead[0]["vt_id"] = "85"; //模版号,int类型
DomHead[0]["cdefine4"] = ""; //表头自定义项4,DateTime类型
//方法二是构造BusinessObject对象,具体方法如下:
BusinessObject domBody = broker.GetBoParam("domBody");
domBody.RowCount = 1; //设置BO对象行数
/****************************** 以下是必输字段 ****************************/
domBody[0]["autoid"] = ""; //主关键字段,int类型
domBody[0]["cinvcode"] = ""; //材料编码,string类型
domBody[0]["editprop"] = "A"; //编辑属性:A表新增,M表修改,D表删除,string类型
/***************************** 以下是非必输字段 ****************************/
domBody[0]["id"] = "111"; //与主表关联项,int类型
domBody[0]["cinvaddcode"] = "01001"; //材料代码,string类型
domBody[0]["cinvname"] = ""; //材料名称,string类型
domBody[0]["cinvstd"] = ""; //规格型号,string类型
domBody[0]["cinvm_unit"] = ""; //主计量单位,string类型
domBody[0]["cinva_unit"] = ""; //库存单位,string类型
domBody[0]["creplaceitem"] = ""; //替换件,string类型
domBody[0]["cposition"] = ""; //货位编码,string类型
domBody[0]["cinvdefine1"] = ""; //存货自定义项1,string类型
domBody[0]["cinvdefine2"] = ""; //存货自定义项2,string类型
domBody[0]["cinvdefine3"] = ""; //存货自定义项3,string类型
domBody[0]["cfree1"] = ""; //存货自由项1,string类型
domBody[0]["cbatchproperty1"] = ""; //批次属性1,double类型
domBody[0]["cbatchproperty2"] = ""; //批次属性2,double类型
domBody[0]["cfree2"] = ""; //存货自由项2,string类型
domBody[0]["cbatch"] = ""; //批号,string类型
domBody[0]["iinvexchrate"] = ""; //换算率,double类型
domBody[0]["inum"] = ""; //件数,double类型
domBody[0]["iquantity"] = "12.0"; //数量,double类型
domBody[0]["iunitcost"] = ""; //单价,double类型
domBody[0]["iprice"] = ""; //金额,double类型
domBody[0]["ipunitcost"] = ""; //计划单价,double类型
domBody[0]["ipprice"] = ""; //计划金额,double类型
domBody[0]["dvdate"] = ""; //失效日期,DateTime类型
domBody[0]["cobjcode"] = ""; //成本对象编码,string类型
domBody[0]["cname"] = ""; //项目,string类型
domBody[0]["isoutquantity"] = ""; //累计出库数量,double类型
domBody[0]["isoutnum"] = ""; //累计出库件数,double类型
domBody[0]["dsdate"] = ""; //结算日期,DateTime类型
domBody[0]["ifquantity"] = ""; //实际数量,double类型
domBody[0]["ifnum"] = ""; //实际件数,double类型
domBody[0]["cvouchcode"] = ""; //对应入库单id,string类型
domBody[0]["cbatchproperty3"] = ""; //批次属性3,double类型
domBody[0]["cfree3"] = ""; //存货自由项3,string类型
domBody[0]["cfree4"] = ""; //存货自由项4,string类型
domBody[0]["cbatchproperty4"] = ""; //批次属性4,double类型
domBody[0]["cbatchproperty5"] = ""; //批次属性5,double类型
domBody[0]["cfree5"] = ""; //存货自由项5,string类型
domBody[0]["cfree6"] = ""; //存货自由项6,string类型
domBody[0]["cbatchproperty6"] = ""; //批次属性6,string类型
domBody[0]["cbatchproperty7"] = ""; //批次属性7,string类型
domBody[0]["cfree7"] = ""; //存货自由项7,string类型
domBody[0]["cfree8"] = ""; //存货自由项8,string类型
domBody[0]["cbatchproperty8"] = ""; //批次属性8,string类型
domBody[0]["cbatchproperty9"] = ""; //批次属性9,string类型
domBody[0]["cfree9"] = ""; //存货自由项9,string类型
domBody[0]["cfree10"] = ""; //存货自由项10,string类型
domBody[0]["cbatchproperty10"] = ""; //批次属性10,DateTime类型
domBody[0]["cdefine36"] = ""; //表体自定义项15,DateTime类型
domBody[0]["cdefine37"] = ""; //表体自定义项16,DateTime类型
domBody[0]["cinvdefine13"] = ""; //存货自定义项13,string类型
domBody[0]["cinvdefine14"] = ""; //存货自定义项14,string类型
domBody[0]["cinvdefine15"] = ""; //存货自定义项15,string类型
domBody[0]["cinvdefine16"] = ""; //存货自定义项16,string类型
domBody[0]["inquantity"] = ""; //应发数量,double类型
domBody[0]["innum"] = ""; //应发件数,double类型
domBody[0]["dmadedate"] = ""; //生产日期,DateTime类型
domBody[0]["impoids"] = ""; //生产订单子表ID,int类型
domBody[0]["isodid"] = ""; //销售订单子表ID,string类型
domBody[0]["iomomid"] = ""; //委外用料表ID,int类型
domBody[0]["iomodid"] = ""; //委外订单子表ID,int类型
domBody[0]["cbvencode"] = ""; //供应商编码,string类型
domBody[0]["cinvouchcode"] = ""; //对应入库单号,string类型
domBody[0]["imassdate"] = ""; //保质期,int类型
domBody[0]["cassunit"] = ""; //库存单位码,string类型
domBody[0]["cvenname"] = ""; //供应商,string类型
domBody[0]["cposname"] = ""; //货位,string类型
domBody[0]["corufts"] = ""; //对应单据时间戳,string类型
domBody[0]["cmolotcode"] = ""; //生产批号,string类型
domBody[0]["dmsdate"] = ""; //核销日期,DateTime类型
domBody[0]["cmassunit"] = ""; //保质期单位,int类型
domBody[0]["csocode"] = ""; //需求跟踪号,string类型
domBody[0]["cmocode"] = ""; //生产订单号,string类型
domBody[0]["comcode"] = ""; //委外订单号,string类型
domBody[0]["cvmivencode"] = ""; //代管商代码,string类型
domBody[0]["cvmivenname"] = ""; //代管商,string类型
domBody[0]["bvmiused"] = ""; //代管消耗标识,int类型
domBody[0]["ivmisettlequantity"] = ""; //代管挂账确认单数量,double类型
domBody[0]["ivmisettlenum"] = ""; //代管挂账确认单件数,double类型
domBody[0]["productinids"] = ""; //productinids,int类型
domBody[0]["crejectcode"] = ""; //在库不良品处理单号,string类型
domBody[0]["cdemandmemo"] = ""; //需求分类代号说明,string类型
domBody[0]["iordertype"] = ""; //销售订单类别,int类型
domBody[0]["iorderdid"] = ""; //iorderdid,int类型
domBody[0]["iordercode"] = ""; //销售订单号,string类型
domBody[0]["iorderseq"] = ""; //销售订单行号,string类型
domBody[0]["iexpiratdatecalcu"] = ""; //有效期推算方式,int类型
domBody[0]["cexpirationdate"] = ""; //有效期至,string类型
domBody[0]["dexpirationdate"] = ""; //有效期计算项,string类型
domBody[0]["cciqbookcode"] = ""; //手册号,string类型
domBody[0]["ibondedsumqty"] = ""; //累计保税处理抽取数量,string类型
domBody[0]["copdesc"] = ""; //工序说明,string类型
domBody[0]["cmworkcentercode"] = ""; //工作中心编码,string类型
domBody[0]["cmworkcenter"] = ""; //工作中心,string类型
domBody[0]["invcode"] = ""; //产品编码,string类型
domBody[0]["invname"] = ""; //产品,string类型
domBody[0]["cwhpersonname"] = ""; //库管员名称,string类型
domBody[0]["cbaccounter"] = ""; //记账人,string类型
domBody[0]["bcosting"] = ""; //是否核算,string类型
domBody[0]["isotype"] = ""; //需求跟踪方式,int类型
domBody[0]["isoseq"] = ""; //需求跟踪行号,string类型
domBody[0]["imoseq"] = ""; //生产订单行号,string类型
domBody[0]["iopseq"] = ""; //工序行号,string类型
domBody[0]["isquantity"] = ""; //累计核销数量,double类型
domBody[0]["ismaterialfee"] = ""; //累计核销金额,double类型
domBody[0]["cdefine34"] = ""; //表体自定义项13,int类型
domBody[0]["cdefine35"] = ""; //表体自定义项14,int类型
domBody[0]["cwhpersoncode"] = ""; //库管员编码,string类型
domBody[0]["cdefine22"] = ""; //表体自定义项1,string类型
domBody[0]["cdefine28"] = ""; //表体自定义项7,string类型
domBody[0]["cdefine29"] = ""; //表体自定义项8,string类型
domBody[0]["cdefine30"] = ""; //表体自定义项9,string类型
domBody[0]["cdefine31"] = ""; //表体自定义项10,string类型
domBody[0]["cdefine32"] = ""; //表体自定义项11,string类型
domBody[0]["cdefine33"] = ""; //表体自定义项12,string类型
domBody[0]["cinvdefine4"] = ""; //存货自定义项4,string类型
domBody[0]["cinvdefine5"] = ""; //存货自定义项5,string类型
domBody[0]["cinvdefine6"] = "";
domBody[0]["cinvdefine7"] = "";
domBody[0]["cinvdefine8"] = "";
domBody[0]["cinvdefine9"] = "";
domBody[0]["cinvdefine10"] = ""; //存货自定义项10,string类型
domBody[0]["cinvdefine11"] = ""; //存货自定义项11,string类型
domBody[0]["cinvdefine12"] = ""; //存货自定义项12,string类型
domBody[0]["cbarcode"] = ""; //条形码,string类型
domBody[0]["cdefine23"] = ""; //表体自定义项2,string类型
domBody[0]["cdefine24"] = ""; //表体自定义项3,string类型
domBody[0]["itrids"] = ""; //特殊单据子表标识,double类型
domBody[0]["cdefine25"] = ""; //表体自定义项4,string类型
domBody[0]["cdefine26"] = ""; //表体自定义项5,double类型
domBody[0]["cdefine27"] = ""; //表体自定义项6,double类型
domBody[0]["citemcode"] = ""; //项目编码,string类型
domBody[0]["citem_class"] = ""; //项目大类编码,string类型
domBody[0]["citemcname"] = ""; //项目大类名称,string类型
broker.AssignNormalValue("domPosition", new System.Object());
broker.AssignNormalValue("cnnFrom", new ADODB.Connection());
ss = string.Empty;// "";
broker.AssignNormalValue("VouchId", ss);
MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocument();
broker.AssignNormalValue("domMsg", domMsg);
broker.AssignNormalValue("bCheck", new System.Boolean());
broker.AssignNormalValue("bBeforCheckStock", new System.Boolean());
broker.AssignNormalValue("bIsRedVouch", new System.Boolean());
ss = string.Empty;// "";
broker.AssignNormalValue("sAddedState", ss);
broker.AssignNormalValue("bReMote", new System.Boolean());
//第六步:调用API
if (!broker.Invoke())
{
//错误处理
Exception apiEx = broker.GetException();
if (apiEx != null)
{
if (apiEx is MomSysException)
{
MomSysException sysEx = apiEx as MomSysException;
Console.WriteLine("系统异常:" + sysEx.Message);
MessageBox.Show("系统异常:" + sysEx.Message);
//todo:异常处理
}
else if (apiEx is MomBizException)
{
MomBizException bizEx = apiEx as MomBizException;
Console.WriteLine("API异常:" + bizEx.Message);
MessageBox.Show("API异常:" + bizEx.Message);
//todo:异常处理
}
//异常原因
String exReason = broker.GetExceptionString();
if (exReason.Length != 0)
{
Console.WriteLine("异常原因:" + exReason);
MessageBox.Show("异常原因:" + exReason);
}
}
broker.Release();
return;
}
//第七步:获取返回结果
System.Boolean result = Convert.ToBoolean(broker.GetReturnValue());
System.String errMsgRet = broker.GetResult("errMsg") as System.String;
System.String VouchIdRet = broker.GetResult("VouchId") as System.String;
MSXML2.IXMLDOMDocument2 domMsgRet = (MSXML2.DOMDocument)(broker.GetResult("domMsg"));
broker.Release();
return;
|
|