U8调拨单API接口 --

   //第二步:构造环境上下文对象,传入login,并按需设置其它上下文参数
                U8EnvContext envContext = new U8EnvContext();
                envContext.U8Login = u8Login;

                //第三步:设置API地址标识(Url)
                //当前API:添加新单据的地址标识为:U8API/PuStoreIn/Add
                U8ApiAddress myApiAddress = new U8ApiAddress("U8API/TransVouch/Add");

                //第四步:构造APIBroker
                U8ApiBroker broker = new U8ApiBroker(myApiAddress, envContext);

                //第五步:API参数赋值

                //给普通参数sVouchType赋值。此参数的数据类型为System.String,此参数按值传递,表示单据类型:01
                broker.AssignNormalValue("sVouchType", "12");


                MSXML2.IXMLDOMDocument2 docHead = new DOMDocument();
                MSXML2.IXMLDOMDocument2 docBody = new DOMDocument();
                docHead.load(Server.MapPath("./") + @"XML\TransVouch.xml");
                docBody.load(Server.MapPath("./") + @"XML\TransVouchs.xml");
                MSXML2.IXMLDOMNode nodeHead = docHead.selectSingleNode("//z:row");


                xeHead.setAttribute("cmaker", dtHead.Rows[0]["cmaker"].ToString()); //供应商,string类型
                xeHead.setAttribute("VT_ID", dtHead.Rows[0]["VT_ID"].ToString()); //供应商,string类型
                xeHead.setAttribute("cowhcode", dtHead.Rows[0]["cOWhcode"].ToString());//转出仓库,string类型
                xeHead.setAttribute("ciwhcode", dtHead.Rows[0]["cIWhcode"].ToString());//转入仓库,string类型
                xeHead.setAttribute("codepcode", dtHead.Rows[0]["cODepCode"].ToString());//转出部门,string类型
                xeHead.setAttribute("cidepcode", dtHead.Rows[0]["cIDepCode"].ToString()); //转入部门,string类型
                xeHead.setAttribute("ctranrequestcode", dtHead.Rows[0]["cTVCode"].ToString()); //调拨申请单号,string类型
                xeHead.setAttribute("ctvcode", ccode);               //DomHead[0]["cmaker"] = ""; //制单人,string类型
                xeHead.setAttribute("dtvdate", u8Login.CurDate);     //DomHead[0]["cmaker"] = ""; //制单人,string类型
                xeHead.setAttribute("cmemo", "");//备注,string类型
                xeHead.setAttribute("cordcode", dtHead.Rows[0]["cORdCode"].ToString());//调出收发类别,string类型
                xeHead.setAttribute("cirdcode", dtHead.Rows[0]["cIRdCode"].ToString());//调入收发类别,string类型

                xeHead.setAttribute("cdefine1", dtHead.Rows[0]["cdefine1"].ToString()); //表头自定义项1,string类型
                xeHead.setAttribute("cdefine2", dtHead.Rows[0]["cdefine2"].ToString()); //表头自定义项2,string类型
                xeHead.setAttribute("cdefine3", dtHead.Rows[0]["cdefine3"].ToString()); //表头自定义项3,string类型
                xeHead.setAttribute("cdefine4", dtHead.Rows[0]["cdefine4"].ToString()); //表头自定义项4,DateTime类型
                xeHead.setAttribute("cdefine5", dtHead.Rows[0]["cdefine5"].ToString()); //表头自定义项5,int类型
                xeHead.setAttribute("cdefine6", dtHead.Rows[0]["cdefine6"].ToString()); //表头自定义项6,DateTime类型
                xeHead.setAttribute("cdefine7", dtHead.Rows[0]["cdefine7"].ToString()); //表头自定义项7,double类型
                xeHead.setAttribute("cdefine8", dtHead.Rows[0]["cdefine8"].ToString()); //表头自定义项8,string类型
                xeHead.setAttribute("cdefine9", dtHead.Rows[0]["cdefine9"].ToString()); //表头自定义项9,string类型
                xeHead.setAttribute("cdefine10", dtHead.Rows[0]["cdefine10"].ToString()); //表头自定义项10,string类型
                xeHead.setAttribute("cdefine11", dtHead.Rows[0]["cdefine11"].ToString()); //表头自定义项11,string类型
                xeHead.setAttribute("cdefine12", dtHead.Rows[0]["cdefine12"].ToString()); //表头自定义项12,string类型
                xeHead.setAttribute("cdefine13", dtHead.Rows[0]["cdefine13"].ToString()); //表头自定义项13,string类型
                xeHead.setAttribute("cdefine14", dtHead.Rows[0]["cdefine14"].ToString()); //表头自定义项14,string类型
                xeHead.setAttribute("cdefine15", dtHead.Rows[0]["cdefine15"].ToString()); //表头自定义项15,int类型


                MSXML2.IXMLDOMNode nodeBody = docBody.selectSingleNode("//z:row");
                IXMLDOMElement xeBody = (IXMLDOMElement)nodeBody;
                int irowno = 1;
                foreach (DataRow datarow in dtBody.Rows)
                {
                    if (Convert.ToDouble(datarow["ihasquantity"].ToString()) <= 0) continue;

                    if (irowno != 1)
                    {
                        IXMLDOMNode newNode = nodeBody.cloneNode(false);
                        IXMLDOMElement xeBody1 = (IXMLDOMElement)newNode;

                        xeBody1.setAttribute("cinvcode", datarow["cinvcode"].ToString());

                        #region 判断存货是否启用保质期管理并获取保质期单位
                        string cmassunit = "";
                        int iMassDate = 0;
                        bool bInvQuality = false;
                        DateTime dVDate = DateTime.Parse(ClsSystem.gnvl(u8Login.CurDate, DateTime.Today.ToString("yyyy-MM-dd")));
                        string strsql = "select cMassUnit,bInvQuality,iMassDate from inventory where cinvcode = '" + ClsSystem.gnvl(datarow["cinvcode"], "") + "' and bInvQuality = 1";
                        System.Data.DataTable invt = DbHelperSQL.Query(strsql).Tables[0];

                        if (invt != null && invt.Rows.Count > 0)
                        {
                            cmassunit = ClsSystem.gnvl(invt.Rows[0]["cMassUnit"], "");
                            bInvQuality = Convert.ToBoolean(ClsSystem.gnvl(invt.Rows[0]["bInvQuality"], "false"));
                            iMassDate = Convert.ToInt16(ClsSystem.gnvl(invt.Rows[0]["iMassDate"], 0));
                            //计算保质期天数
                            if (cmassunit != "" || bInvQuality == true)
                            {
                                if (cmassunit == "1")
                                    dVDate = dVDate.AddYears(iMassDate);
                                else if (cmassunit == "2")
                                    dVDate = dVDate.AddMonths(iMassDate);
                                else
                                {
                                    dVDate = dVDate.AddDays(iMassDate);
                                }
                            }
                            xeBody1.setAttribute("ddisdate", dVDate.ToString("yyyy-MM-dd"));//失效日期,DateTime类型
                            xeBody1.setAttribute("imassdate", iMassDate);//保质期,int类型
                            xeBody1.setAttribute("cMassUnit", ClsSystem.gnvl(invt.Rows[0]["cMassUnit"], ""));//保质期单位,int类型
                        }

                        string bInvBatchsql = "select isnull(bInvBatch,0) as  bInvBatch from inventory where cinvcode = '" + ClsSystem.gnvl(datarow["cinvcode"], "") + "' ";
                        System.Data.DataTable bInvBatcht = DbHelperSQL.Query(bInvBatchsql).Tables[0];
                        if (bInvBatcht != null && bInvBatcht.Rows.Count > 0)
                        {
                            int bInvBatch = Convert.ToInt16(bInvBatcht.Rows[0]["bInvBatch"]);
                            xeBody1.setAttribute("ctvBatch", bInvBatch == 1 ? datarow["cBatch"].ToString() : "");

                        }
                        #endregion

                        xeBody1.setAttribute("iTRIds", datarow["iTRIds"].ToString());
                        xeBody1.setAttribute("itvquantity", datarow["ihasquantity"].ToString());
                        xeBody1.setAttribute("irowno", irowno);

                        xeBody1.setAttribute("cinposcode", datarow["cinposcode"].ToString());//cinposcode调入货位   coutposcode调出货位  cTVBatch批号
                        xeBody1.setAttribute("coutposcode", datarow["coutposcode"].ToString());
                        xeBody1.setAttribute("cTVBatch", datarow["cTVBatch"].ToString());

                        xeBody1.setAttribute("cdefine22", datarow["cdefine22"].ToString());  //表体自定义项1,string类型
                        xeBody1.setAttribute("cdefine23", datarow["cdefine23"].ToString());  //表体自定义项2,string类型
                        xeBody1.setAttribute("cdefine24", datarow["cdefine24"].ToString());  //表体自定义项3,string类型
                        xeBody1.setAttribute("cdefine25", datarow["cdefine25"].ToString());  //表体自定义项4,string类型
                        xeBody1.setAttribute("cdefine26", datarow["cdefine26"].ToString());  //表体自定义项5,double类型
                        xeBody1.setAttribute("cdefine27", datarow["cdefine27"].ToString());  //表体自定义项6,double类型
                        xeBody1.setAttribute("cdefine28", datarow["cdefine28"].ToString());  //表体自定义项7,string类型
                        xeBody1.setAttribute("cdefine29", datarow["cdefine29"].ToString());  //表体自定义项8,string类型
                        xeBody1.setAttribute("cdefine30", datarow["cdefine30"].ToString());  //表体自定义项9,string类型
                        xeBody1.setAttribute("cdefine31", datarow["cdefine31"].ToString());  //表体自定义项10,string类型
                        xeBody1.setAttribute("cdefine32", datarow["cdefine32"].ToString());  //表体自定义项11,string类型
                        xeBody1.setAttribute("cdefine33", datarow["cdefine33"].ToString());  //表体自定义项12,string类型
                        xeBody1.setAttribute("cdefine34", datarow["cdefine34"].ToString());  //表体自定义项13,int类型
                        xeBody1.setAttribute("cdefine35", datarow["cdefine35"].ToString());  //表体自定义项14,int类型
                        xeBody1.setAttribute("cdefine36", datarow["cdefine36"].ToString());  //表体自定义项15,DateTime类型
                        xeBody1.setAttribute("cdefine37", datarow["cdefine37"].ToString());  //表体自定义项16,DateTime类型


                        docBody.selectSingleNode("//rs:data").appendChild(newNode);
                    }
                    else
                    {
                        xeBody.setAttribute("cinvcode", datarow["cinvcode"].ToString());

                        #region 判断存货是否启用保质期管理并获取保质期单位
                        string cmassunit = "";
                        int iMassDate = 0;
                        bool bInvQuality = false;
                        DateTime dVDate = DateTime.Parse(ClsSystem.gnvl(u8Login.CurDate, DateTime.Today.ToString("yyyy-MM-dd")));
                        string strsql = "select cMassUnit,bInvQuality,iMassDate from inventory where cinvcode = '" + ClsSystem.gnvl(datarow["cinvcode"], "") + "' and bInvQuality = 1";
                        System.Data.DataTable invt = DbHelperSQL.Query(strsql).Tables[0];

                        if (invt != null && invt.Rows.Count > 0)
                        {
                            cmassunit = ClsSystem.gnvl(invt.Rows[0]["cMassUnit"], "");
                            bInvQuality = Convert.ToBoolean(ClsSystem.gnvl(invt.Rows[0]["bInvQuality"], "false"));
                            iMassDate = Convert.ToInt16(ClsSystem.gnvl(invt.Rows[0]["iMassDate"], 0));
                            //计算保质期天数
                            if (cmassunit != "" || bInvQuality == true)
                            {
                                if (cmassunit == "1")
                                    dVDate = dVDate.AddYears(iMassDate);
                                else if (cmassunit == "2")
                                    dVDate = dVDate.AddMonths(iMassDate);
                                else
                                {
                                    dVDate = dVDate.AddDays(iMassDate);
                                }
                            }

                            xeBody.setAttribute("ddisdate", dVDate.ToString("yyyy-MM-dd"));//失效日期,DateTime类型
                            xeBody.setAttribute("imassdate", iMassDate);//保质期,int类型
                            xeBody.setAttribute("cMassUnit", ClsSystem.gnvl(invt.Rows[0]["cMassUnit"], ""));//保质期单位,int类型
                        }

                        string bInvBatchsql = "select isnull(bInvBatch,0) as  bInvBatch from inventory where cinvcode = '" + ClsSystem.gnvl(datarow["cinvcode"], "") + "' ";
                        System.Data.DataTable bInvBatcht = DbHelperSQL.Query(bInvBatchsql).Tables[0];
                        if (bInvBatcht != null && bInvBatcht.Rows.Count > 0)
                        {
                            int bInvBatch = Convert.ToInt16(bInvBatcht.Rows[0]["bInvBatch"]);
                            xeBody.setAttribute("ctvBatch", bInvBatch == 1 ? datarow["cBatch"].ToString() : "");
                        }
                        #endregion

                        xeBody.setAttribute("iTRIds", datarow["iTRIds"].ToString());
                        xeBody.setAttribute("itvquantity", datarow["ihasquantity"].ToString());
                        xeBody.setAttribute("irowno", irowno);

                        xeBody.setAttribute("cinposcode", datarow["cinposcode"].ToString());//cinposcode调入货位   coutposcode调出货位  cTVBatch批号
                        xeBody.setAttribute("coutposcode", datarow["coutposcode"].ToString());
                        xeBody.setAttribute("cTVBatch", datarow["cTVBatch"].ToString());

                        xeBody.setAttribute("cdefine22", datarow["cdefine22"].ToString());  //表体自定义项1,string类型
                        xeBody.setAttribute("cdefine23", datarow["cdefine23"].ToString());  //表体自定义项2,string类型
                        xeBody.setAttribute("cdefine24", datarow["cdefine24"].ToString());  //表体自定义项3,string类型
                        xeBody.setAttribute("cdefine25", datarow["cdefine25"].ToString());  //表体自定义项4,string类型
                        xeBody.setAttribute("cdefine26", datarow["cdefine26"].ToString());  //表体自定义项5,double类型
                        xeBody.setAttribute("cdefine27", datarow["cdefine27"].ToString());  //表体自定义项6,double类型
                        xeBody.setAttribute("cdefine28", datarow["cdefine28"].ToString());  //表体自定义项7,string类型
                        xeBody.setAttribute("cdefine29", datarow["cdefine29"].ToString());  //表体自定义项8,string类型
                        xeBody.setAttribute("cdefine30", datarow["cdefine30"].ToString());  //表体自定义项9,string类型
                        xeBody.setAttribute("cdefine31", datarow["cdefine31"].ToString());  //表体自定义项10,string类型
                        xeBody.setAttribute("cdefine32", datarow["cdefine32"].ToString());  //表体自定义项11,string类型
                        xeBody.setAttribute("cdefine33", datarow["cdefine33"].ToString());  //表体自定义项12,string类型
                        xeBody.setAttribute("cdefine34", datarow["cdefine34"].ToString());  //表体自定义项13,int类型
                        xeBody.setAttribute("cdefine35", datarow["cdefine35"].ToString());  //表体自定义项14,int类型
                        xeBody.setAttribute("cdefine36", datarow["cdefine36"].ToString());  //表体自定义项15,DateTime类型
                        xeBody.setAttribute("cdefine37", datarow["cdefine37"].ToString());  //表体自定义项16,DateTime类型

                    }
                    irowno++;
                }

                //传入表头的MSXML2.DOMDocumentClass对象
                broker.AssignNormalValue("DomHead", docHead);

                //传入表体的MSXML2.DOMDocumentClass对象
                broker.AssignNormalValue("domBody", docBody);

                //给普通参数domPosition赋值。此参数的数据类型为System.Object,此参数按引用传递,表示货位:传空
                broker.AssignNormalValue("domPosition", null);

                //该参数errMsg为OUT型参数,由于其数据类型为System.String,为一般值类型,因此不必传入一个参数变量。在API调用返回时,可以通过GetResult("errMsg")获取其值

                //给普通参数cnnFrom赋值。此参数的数据类型为ADODB.Connection,此参数按引用传递,表示连接对象,如果由调用方控制事务,则需要设置此连接对象,否则传空
                broker.AssignNormalValue("cnnFrom", null);

                //该参数VouchId为INOUT型普通参数。此参数的数据类型为System.String,此参数按值传递。在API调用返回时,可以通过GetResult("VouchId")获取其值
                string reVouchId = "";
                broker.AssignNormalValue("VouchId", reVouchId);

                //该参数domMsg为OUT型参数,由于其数据类型为MSXML2.IXMLDOMDocument2,非一般值类型,因此必须传入一个参数变量。在API调用返回时,可以直接使用该参数
                MSXML2.IXMLDOMDocument2 domMsg = new DOMDocument();
                broker.AssignNormalValue("domMsg", domMsg);

                bool bCheck = Convert.ToBoolean(DbHelperSQL.GetSingle("select cValue from AccInformation where cName='ballowzero'"));
                //给普通参数bCheck赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否控制可用量。
                broker.AssignNormalValue("bCheck", false);

                //给普通参数bBeforCheckStock赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示检查可用量
                broker.AssignNormalValue("bBeforCheckStock", true);

                //给普通参数bIsRedVouch赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否红字单据
                broker.AssignNormalValue("bIsRedVouch", false);

                //给普通参数sAddedState赋值。此参数的数据类型为System.String,此参数按值传递,表示传空字符串
                broker.AssignNormalValue("sAddedState", "");

                //给普通参数bReMote赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否远程:转入false
                broker.AssignNormalValue("bReMote", false);


                //第六步:调用API
                if (!broker.Invoke())
                {
                    //错误处理
                    Exception apiEx = broker.GetException();
                    if (apiEx != null)
                    {
                        if (apiEx is MomSysException)
                        {
                            MomSysException sysEx = apiEx as MomSysException;
                            //Console.WriteLine("系统异常:" + sysEx.Message);
                            dr["cError"] = "系统异常:" + sysEx.Message;
                        }
                        else if (apiEx is MomBizException)
                        {
                            MomBizException bizEx = apiEx as MomBizException;
                            //Console.WriteLine("API异常:" + bizEx.Message);
                            dr["cError"] = "API异常:" + bizEx.Message;
                            //todo:异常处理
                        }
                        //异常原因
                        String exReason = broker.GetExceptionString();
                        if (exReason.Length != 0)
                        {
                            dr["cError"] = "异常原因:" + exReason;
                            //Console.WriteLine("异常原因:" + exReason);
                        }
                    }
                    //结束本次调用,释放API资源
                    broker.Release();

                          return dtRetrun;
                    //return "-1";
                }


                //第七步:获取返回结果

                //获取返回值
                //获取普通返回值。此返回值数据类型为System.Boolean,此参数按值传递,表示返回值:true:成功,false:失败
                System.Boolean result = Convert.ToBoolean(broker.GetReturnValue());

                //获取out/inout参数值

                //获取普通OUT参数errMsg。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空
                System.String errMsgRet = broker.GetResult("errMsg") as System.String;

                //获取普通INOUT参数VouchId。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空
                System.String VouchIdRet = broker.GetResult("VouchId") as System.String;
                //System.String cCodeRet = broker.GetResult("cCode") as System.String;

                //获取普通OUT参数domMsg。此返回值数据类型为MSXML2.IXMLDOMDocument2,在使用该参数之前,请判断是否为空
                MSXML2.IXMLDOMDocument2 domMsgRet = (MSXML2.IXMLDOMDocument2)broker.GetResult("domMsg");


                //结束本次调用,释放API资源
                broker.Release();

                if (!result)
                {

                    dr["cReturn"] = "-1";
                    if (errMsgRet != null)
                    {
                        dr["cError"] = errMsgRet;

                  
                    }
                }

你可能感兴趣的:(前端,java,数据库,U8,API)