/// <summary> /// Updates the EDMPROP element with the Extended Data associated with the specified WFM node. /// </summary> /// <param name="element">The element.</param> /// <param name="node">A WFM node object representing a Work Request, Design, Work Location, or Compatible Unit.</param> private void UpdateEdm(IXMLDOMElement element, IMMWMSNode node) { IMMWMSWorkRequest workRequest = node as IMMWMSWorkRequest; if (workRequest != null) { this.SetProperty(element, _EdmRepository.WorkRequest, string.Format(CultureInfo.InvariantCulture, "{0} = {1}", Fields.WorkRequestID, workRequest.ID)); } else { IMMWMSDesign design = node as IMMWMSDesign; if (design != null) { this.SetProperty(element, _EdmRepository.Design, string.Format(CultureInfo.InvariantCulture, "{0} = {1}", Fields.DesignID, design.ID)); } else { IMMWMSWorklocation workLocation = node as IMMWMSWorklocation; if (workLocation != null) { this.SetProperty(element, _EdmRepository.WorkLocation, string.Format(CultureInfo.InvariantCulture, "{0} = {1}", Fields.WorkLocationID, workLocation.ID)); } else { IMMWMSCompatibleUnit compatibleUnit = node as IMMWMSCompatibleUnit; if (compatibleUnit != null) { this.SetProperty(element, _EdmRepository.CompatibleUnit, string.Format(CultureInfo.InvariantCulture, "{0} = {1}", Fields.CompatibleUnitID, compatibleUnit.ID)); } } } } }
static public void Main(string[] args) { if (args.Length == 0 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help"))) { Console.WriteLine(usage); } else { try { DOMDocumentClass xmlDoc = new DOMDocumentClass(); IXMLDOMElement rootElement = xmlDoc.createElement("memo"); IXMLDOMAttribute memoAttribute = xmlDoc.createAttribute("author"); IXMLDOMText memoAttributeText = xmlDoc.createTextNode("Pat Coleman"); IXMLDOMElement toElement = xmlDoc.createElement("to"); IXMLDOMText toElementText = xmlDoc.createTextNode("Carole Poland"); xmlDoc.appendChild(rootElement); memoAttribute.appendChild(memoAttributeText); rootElement.setAttributeNode(memoAttribute); rootElement.appendChild(toElement); toElement.appendChild(toElementText); xmlDoc.save("memo.xml"); } catch (Exception e) { Console.WriteLine(e); } } }
/// <summary> /// 在本地保存Xml文件 /// </summary> /// <param name="doc"></param> /// <param name="Aroottag"></param> /// <param name="Aysdh"></param> private void SaveLocalXml(DOMDocument doc, string Aroottag, string Aysdh) { try { IXMLDOMElement rootnode = doc.documentElement; IXMLDOMNode modelNode = rootnode.selectNodes(Aroottag + "/bill_body/item")[0].cloneNode(true); IXMLDOMNode NewNode; IXMLDOMNode NewSubNode; IXMLDOMNode Parentnode; IXMLDOMNode body = rootnode.selectSingleNode(Aroottag + "/bill_body"); for (int i = 0; i < body.childNodes.length; i++) { body.removeChild(body.childNodes[i]); } DataSet ds = PDParam.GetXmldata(Aysdh); if (ds != null) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { Parentnode = rootnode.selectSingleNode(Aroottag + "/bill_body"); if (i > 0) { modelNode = rootnode.selectNodes(Aroottag + "/bill_body/item")[0].cloneNode(true); } NewNode = Parentnode.appendChild(modelNode); NewSubNode = NewNode.selectSingleNode("cinventorycode"); NewSubNode.text = ds.Tables[0].Rows[i]["wlh"].ToString(); NewSubNode = NewNode.selectSingleNode("vbatchcode"); NewSubNode.text = ds.Tables[0].Rows[i]["pch"].ToString(); NewSubNode = NewNode.selectSingleNode("vfree1"); NewSubNode.text = ds.Tables[0].Rows[i]["sx"].ToString(); NewSubNode = NewNode.selectSingleNode("naccountastnum"); NewSubNode.text = ds.Tables[0].Rows[i]["sumzcsl"].ToString(); NewSubNode = NewNode.selectSingleNode("naccountnum"); NewSubNode.text = ds.Tables[0].Rows[i]["sumzczl"].ToString(); NewSubNode = NewNode.selectSingleNode("ncheckastnum"); NewSubNode.text = ds.Tables[0].Rows[i]["sumspsl"].ToString(); NewSubNode = NewNode.selectSingleNode("nchecknum"); NewSubNode.text = ds.Tables[0].Rows[i]["sumspzl"].ToString(); } string apppathxml = "../../webinfo/xml"; string pathName = Server.MapPath(apppathxml); if (!Directory.Exists(pathName)) { Directory.CreateDirectory(pathName); } string filename = "Wms-" + Aysdh + ".xml"; doc.save(pathName + "/" + filename); } } catch { this.PrintfError("本地保存Xml文件时出现错误,请重试"); return; } }
/// <summary> /// 获取元素中的属性值 /// </summary> /// <param name="xml"></param> /// <param name="nodeName">/inventory/cinvcode</param> /// <returns></returns> protected string GetNodeAttrib(IXMLDOMElement doc, string attrName) { try { return(doc.getAttribute(attrName).ToString()); } catch { return(""); } }
public string GetAttributeValue(IXMLDOMElement xnodCurrentNode, int iIndex) { try { return(xnodCurrentNode.attributes[iIndex].text); } catch { throw; } return(null); }
public void Check(int idSolicitud, Eventos evento, string xmlContent) { if (idSolicitud == _idSolicitud) { prevXmlData = xmlData; xmlData = xmlContent; DOMDocument Xml = new DOMDocument(); Xml.loadXML(xmlData); root = Xml.documentElement; Ejecutar(T(Estado_Actual, evento)); } }
public void AddAttribute(string newAttributeName, string Value, IXMLDOMElement Parent) { try { Parent.setAttribute(newAttributeName, Value); return; } catch { throw; } return; }
public XMLParser(string BaseNode) { try { IXMLDOMNode oNode = _root.createProcessingInstruction("xml", "version='1.0' encoding='windows-1256'"); oNode = _root.insertBefore(oNode, _root.childNodes[0]); IXMLDOMElement oRoot = _root.createElement(BaseNode); _root.documentElement = oRoot; } catch { throw; } return; }
protected override void EnviarNotifDeAprobacion() { _statusDoc = (int)Estatus.REVISADO; //_Observacion = _index + 1 < _ruta.Length ? root.childNodes[3].text : string.Empty; _Observacion = string.Empty; bool _fecha = _index + 1 < _ruta.Length ? true : false; DOMDocument Xml = new DOMDocument(); Xml.loadXML(prevXmlData); IXMLDOMElement _root = Xml.documentElement; if (_index < _ruta.Length) { _staff_from = int.Parse(_root.childNodes[2].text); DataSet ds = SqlHelper.ExecuteDataset(WinflowAC.ConnectionString.FormarStringConexion(), Queries.WF_BuscarEmpleadoEspecifico, _staff_from); _email_from = ds.Tables[0].Rows[0]["emp_str_email"].ToString(); } //string Mensaje = ConstruirMensaje(_idWorkflow,_Referencia,ENVIAR_NOTIF_DE_APROBACION,out _email_title, out _email_from_sys); //EmailHelper.SendEmail(ConfigurationSettings.AppSettings[WinflowAC.Global.CfgKeySmtpServer],_email_origen,_email_from_sys,_email_title,Mensaje,System.Web.Mail.MailFormat.Html); //===================================================== // NUEVO FORMA //===================================================== string Mensaje = ""; DataSet dstSolicitud = SqlHelper.ExecuteDataset(WinflowAC.ConnectionString.FormarStringConexion(), Queries.WF_CargarDatosSolicitud, _idWorkflow, _Referencia); if (Convert.ToInt16(dstSolicitud.Tables[0].Rows[0]["posicion"]) == Convert.ToInt16(dstSolicitud.Tables[0].Rows[0]["num_aprob"])) // SI ES LA PROBACION FINAL { Mensaje = ConstruirMensajeAprobacion(_idWorkflow, _Referencia, ENVIAR_NOTIF_DE_APROBACION, out _email_title, out _email_from_sys); } else { Mensaje = ConstruirMensaje(_idWorkflow, _Referencia, ENVIAR_NOTIF_DE_APROBACION, out _email_title, out _email_from_sys); } EmailHelper.SendEmail(ConfigurationSettings.AppSettings[WinflowAC.Global.CfgKeySmtpServer], _email_origen, _email_from_sys, _email_title, Mensaje, System.Web.Mail.MailFormat.Html); dstSolicitud = null; //===================================================== //===================================================== _index++; // Se sale de este estado con un evento automático [Neutro] GuardarHistorico(_idSolicitud, _statusDoc, ENVIAR_NOTIF_DE_APROBACION, _Observacion, _index, _staff_from, _staff_to, prevXmlData, xmlData, _fecha); }
public IXMLDOMNode AddChildFromNode(IXMLDOMNode newNode, IXMLDOMNode Parent) { try { IXMLDOMElement xnod = _root.createElement(newNode.nodeName); DOMDocument doc = new DOMDocument(); doc.loadXML(newNode.xml); IXMLDOMNode xnodReturn = Parent.appendChild(doc.documentElement); return(xnodReturn); } catch { throw; } return(null); }
/// <summary> /// 需要新增的数据 /// </summary> /// <param name="doc"></param> private void SetAddData(IXMLDOMElement doc) { lTmp = new List <BaseMode>(); lTmp.Add(new BaseMode("barcode", GetNodeAttrib(doc, "barcode"), "barcode", "MCARD", GetNodeAttrib(doc, "barcode"), null, null)); lTmp.Add(new BaseMode("cinvcode", GetNodeAttrib(doc, "cinvcode"), "cinvcode", "MITEMCODE", GetNodeAttrib(doc, "cinvcode"), null, null)); //lTmp.Add(new BaseMode("ccuscode", GetNodeValue(doc, "/customer/ccuscode"), "/customer/ccuscode", "VENDORITEMCODE", GetNodeValue(doc, "/customer/ccuscode"))); //lTmp.Add(new BaseMode("cvencode", GetNodeAttrib(doc, "cvencode"), "cvencode", "VENDORCODE", GetNodeAttrib(doc, "cvencode"))); //lTmp.Add(new BaseMode("ccuscode", GetNodeValue(doc, "/customer/ccuscode"), "/customer/ccuscode", "VenderLotNO", GetNodeValue(doc, "/customer/ccuscode"))); //lTmp.Add(new BaseMode("ccusname", GetNodeValue(doc, "/customer/ccusname"), "/customer/ccusname", "DATECODE", GetNodeValue(doc, "/customer/ccusname"))); //生产日期 //lTmp.Add(new BaseMode("ccuscode", GetNodeValue(doc, "/customer/ccuscode"), "/customer/ccuscode", "TransNO", GetNodeValue(doc, "/customer/ccuscode"))); //lTmp.Add(new BaseMode("ccusname", GetNodeValue(doc, "/customer/ccusname"), "/customer/ccusname", "TransLine", GetNodeValue(doc, "/customer/ccusname"))); lTmp.Add(new BaseMode("qty", GetNodeAttrib(doc, "qty"), "qty", "LOTQTY", GetNodeAttrib(doc, "qty"), null, null)); //生产数量 lTmp.Add(new BaseMode(null, null, null, "Flag", "W", null, null)); lTmp.Add(new BaseMode(null, null, null, "EDITPROP", "A", null, null)); lTmp.Add(new BaseMode(null, null, null, "FINISHFLAG", "0", null, null)); lTmp.Add(new BaseMode(null, null, null, "dModifyDate", System.DateTime.Now.ToString(), null, null)); lAdd.Add(lTmp); }
/// <summary> /// Given the <paramref name="element" /> and the <paramref name="edmTable" /> and /// all of the records that satsify the <paramref name="filter" /> will be added as EDMPROP elements in the document /// from the table. /// </summary> /// <param name="element">IXMLDOMElement of the current xml document.</param> /// <param name="edmTable">The edm table.</param> /// <param name="filter">Filter used to narrow down the table search.</param> private void SetProperty(IXMLDOMElement element, EdmTable edmTable, string filter) { // Obtain all of the rows the satisfy the given filter. IEnumerable <DataRow> rows = this.GetRows(edmTable, filter); if (rows == null) { return; } // Iterate through all of the rows. foreach (DataRow row in rows) { EDM edm = new EDM(row); IXMLDOMElement edmprop = element.ownerDocument.createElement("EDMPROP"); edmprop.setAttribute("Name", edm.Name); edmprop.setAttribute("Type", edm.Type); edmprop.text = edm.Value; element.appendChild(edmprop); } }
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { lock (msgQueue) { try { msg = msgQueue.Receive(new TimeSpan(0, 0, 3)); msg.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(objMensaje), typeof(Eventos) }); objM = (objMensaje)msg.Body; DOMDocument Xml = new DOMDocument(); bool exitoso = Xml.loadXML(objM._Input); if (exitoso) { IXMLDOMElement root = Xml.documentElement; // primer parámetro : cod_workflow - segundo parámetro : str_referencia DataSet ds = SqlHelper.ExecuteDataset(WinflowAC.ConnectionString.FormarStringConexion(), Queries.WF_ConsultarSolicitud, int.Parse(root.childNodes[0].text), root.childNodes[1].text); int nRows = ds.Tables[0].Rows.Count; int intCodCreador = 0; //+ Nuevo int intNumPosAct = 0; int intCodWF = 0; string strNumRef = string.Empty; string strDescRuta = string.Empty; int intEstatusWF = 0; int intEstatusDoc = 0; string strPrevXml = string.Empty; string strXml = string.Empty; int intCodEmpDesde = 0; int intCodEmpHasta = 0; bool blnActual = false; int intIndexActual = 0; //+ string strPrev = string.Empty; if (objM._Evento == Eventos.CREAR_SOLICITUD && nRows == 0) { CreateStateMachine(int.Parse(root.childNodes[0].text), root.childNodes[1].text, int.Parse(root.childNodes[2].text), root.childNodes[4].text); } else { SolicitudActual = Convert.ToInt32(ds.Tables[0].Rows[0]["swf_cod_solicitud"]); try { intCodCreador = Convert.ToInt32(ds.Tables[0].Rows[0]["hwf_cod_empleado_origen"]); strPrev = Convert.ToString(ds.Tables[0].Rows[0]["hwf_str_prevxmldata"]); } catch (Exception ee) { intCodCreador = 0; strPrev = string.Empty; System.Console.Write(ee.Message); } } IEnumerator arrayList = array.GetEnumerator(); if (objM._Evento == Eventos.CAMBIO_DE_DESTINATARIO) { //* Antes /* * bool blnActualCD=false; * int intIndexActualCD=0; * while ( arrayList.MoveNext() ) * { * blnActualCD=((StateMachine)arrayList.Current).Check(SolicitudActual); * intIndexActualCD++; * if(blnActualCD) * break; * * } */ //* ((StateProcSmpl)arrayList.Current).ActualizarAprobador(int.Parse(root.childNodes[2].text), SolicitudActual); ((StateMachine)arrayList.Current).Check(SolicitudActual, objM._Evento, objM._Input); // array.RemoveAt(intIndexActual-1); // StateMachine sMach = new StateProcSmpl(SolicitudActual,int.Parse(root.childNodes[0].text),root.childNodes[1].text,StateConst.ESPERAR_CORRECCION,root.childNodes[4].text,1,intCodCreador,strPrev); // array.Add(sMach); // sMach.Check(SolicitudActual,objM._Evento,objM._Input); } else { if (objM._Evento == Eventos.SOLICITUD_CORREGIDA) { blnActual = false; intIndexActual = 0; while (arrayList.MoveNext()) { blnActual = ((StateMachine)arrayList.Current).Check(SolicitudActual); intIndexActual++; if (blnActual) { break; } } array.RemoveAt(intIndexActual - 1); StateMachine sMach = new StateProcSmpl(SolicitudActual, int.Parse(root.childNodes[0].text), root.childNodes[1].text, StateConst.ESPERAR_CORRECCION, root.childNodes[4].text, 1, intCodCreador, strPrev); array.Add(sMach); // *Anterior //sMach.Check(SolicitudActual,objM._Evento,objM._Input); } // +Nuevo if ((objM._Evento == Eventos.SOLICITUD_APROBADA) || (objM._Evento == Eventos.RECHAZADO_PARCIAL) || (objM._Evento == Eventos.RECHAZADO_TOTAL)) { //+ Nuevo intNumPosAct = Convert.ToInt32(ds.Tables[0].Rows[0]["swf_num_posicion_actual"]); intCodWF = Convert.ToInt32(ds.Tables[0].Rows[0]["swf_cod_workflow"]); strNumRef = Convert.ToString(ds.Tables[0].Rows[0]["swf_str_referencia"]); strDescRuta = Convert.ToString(ds.Tables[0].Rows[0]["swf_desc_ruta"]); intEstatusWF = Convert.ToInt32(ds.Tables[0].Rows[0]["hwf_cod_estatuswkf"]); intEstatusDoc = Convert.ToInt32(ds.Tables[0].Rows[0]["hwf_cod_estatusdoc"]); strPrevXml = Convert.ToString(ds.Tables[0].Rows[0]["hwf_str_prevxmldata"]); strXml = Convert.ToString(ds.Tables[0].Rows[0]["hwf_str_xmldata"]); intCodEmpDesde = Convert.ToInt32(ds.Tables[0].Rows[0]["hwf_cod_empleado_origen"]); intCodEmpHasta = Convert.ToInt32(ds.Tables[0].Rows[0]["hwf_cod_empleado_destino"]); intCodCreador = Convert.ToInt32(ds.Tables[0].Rows[0]["swf_cod_empleado_creador"]); //+ blnActual = false; intIndexActual = 0; while (arrayList.MoveNext()) { blnActual = ((StateMachine)arrayList.Current).Check(SolicitudActual); intIndexActual++; if (blnActual) { break; } } if (blnActual) { array.RemoveAt(intIndexActual - 1); } StateMachine sMach = new StateProcSmpl((int)SolicitudActual, intCodWF, strNumRef, intEstatusWF, intEstatusDoc, strDescRuta, intNumPosAct, strPrevXml, strXml, intCodCreador, intCodEmpDesde, intCodEmpHasta); array.Add(sMach); } // + //*else //*{ arrayList = array.GetEnumerator(); while (arrayList.MoveNext()) { ((StateMachine)arrayList.Current).Check(SolicitudActual, objM._Evento, objM._Input); } //*} } } } catch { //arrayList = array.GetEnumerator(); EstadoActual = StateConst.INICIO; //while ( arrayList.MoveNext() ) //{ // ((StateMachine)arrayList.Current).Check(); // EstadoActual = ((StateMachine)arrayList.Current).EstadoActual; // if(EstadoActual == StateConst.FIN) // { // array.Remove(arrayList.Current); // } //} int i = 0, count = array.Count; while (i < count) { ((StateMachine)array[i]).Check(); EstadoActual = ((StateMachine)array[i]).EstadoActual; if (EstadoActual == StateConst.FIN) { array.RemoveAt(i); count--; } else { i++; } } arrayList = array.GetEnumerator(); } // end catch } }
protected void btndataUp_Click(object sender, ImageClickEventArgs e) { try { string YSDH = this.txtYSDH.Text.Trim(); DataSet dsYSDH = PDParam.GetPDDNC("YSDH = '" + YSDH + "'"); if (dsYSDH != null && dsYSDH.Tables[0].Rows.Count > 0) { string DJZT = dsYSDH.Tables[0].Rows[0]["DJZT"].ToString(); if (DJZT != "已盘") { this.PrintfError("只有审核过的单据才能上传"); return; } } else { this.PrintfError("没有可导出的数据"); return; } string Fdownweb = Common.RFWEBSERVER; // RF服务器地址 string Fuploadweb = Common.NCWERBSERVER; //NC服务器地址 string wmsserver = Common.INTERFACESERVER; //接口地址 //string Fdownweb = "http://192.168.1.171/";//测试地址 //string Fuploadweb = "http://localhost:800/WebSiteXML/Default.aspx"; //string wmsserver = "http://192.168.1.171/"; if ((string.IsNullOrEmpty(Fdownweb)) || (string.IsNullOrEmpty(Fuploadweb))) { this.PrintfError("服务器尚未正确设置"); } else { XmlDocument docC = new XmlDocument(); string filename = YSDH + ".xml"; docC.Load(Fdownweb + filename); //用XmlDocument类来下载Xml文件 DOMDocument doc = new DOMDocument(); XmlDocument resultdoc = new XmlDocument(); string xml = docC.InnerXml; doc.loadXML(docC.InnerXml); //将Xml文件赋给DOMDocument类型的doc IXMLDOMElement rootnode = doc.documentElement; bool XmlIsSended = PDParam.XmlIsSended(filename); if (XmlIsSended) { rootnode.setAttribute("replace", "Y"); rootnode.setAttribute("proc", "update"); } else { rootnode.setAttribute("replace", "N"); rootnode.setAttribute("proc", "add"); } string ArrSender = rootnode.getAttribute("sender").ToString(); string Aroottag = rootnode.getAttribute("roottag").ToString(); string ArrReceiver = rootnode.getAttribute("receiver").ToString(); rootnode.setAttribute("sender", ArrReceiver); rootnode.setAttribute("receiver", ArrSender); DataSet dsNCDetail = PDParam.GetNCDetail(YSDH, ""); string WLH; string PCH; string SX; string vfree1; string vfree2; string vfree3; string SPSL; string SPZL; IXMLDOMNode node; foreach (DataRow dr in dsNCDetail.Tables[0].Rows) { WLH = dr["barcode"].ToString(); PCH = dr["PCH"].ToString(); SX = dr["SX"].ToString(); vfree1 = dr["vfree1"].ToString(); vfree2 = dr["vfree2"].ToString(); vfree3 = dr["vfree3"].ToString(); SPSL = dr["SPSL"].ToString(); SPZL = dr["SPZL"].ToString(); //修改实盘数量 node = rootnode.selectSingleNode(Aroottag + "/bill_body/item[cinventorycode/text()='" + WLH + "'][vbatchcode/text()='" + PCH + "'][cqualitylevelname/text()='" + SX + "'][vfree1/text()='" + vfree1 + "'][vfree2/text()='" + vfree2 + "'][vfree3/text()='" + vfree3 + "']/ncheckastnum"); if (node != null) { node.text = SPSL; } node = rootnode.selectSingleNode(Aroottag + "/bill_body/item[cinventorycode/text()='" + WLH + "'][vbatchcode/text()='" + PCH + "'][cqualitylevelname/text()='" + SX + "'][vfree1/text()='" + vfree1 + "'][vfree2/text()='" + vfree2 + "'][vfree3/text()='" + vfree3 + "']/nchecknum"); if (node != null) { node.text = SPZL; } } //上传 MSXML2.XMLHTTP MyHttp = new MSXML2.XMLHTTPClass(); MyHttp.open("post", Fuploadweb, false, "", ""); MyHttp.send(doc); int ComResult = 0; string Comdes = string.Empty; if (MyHttp.status == 200) { resultdoc.LoadXml(MyHttp.responseText); XmlElement resultRootnode = resultdoc.DocumentElement; string Roottag = resultRootnode.GetAttribute("roottag"); XmlNode resultnode = resultRootnode.SelectSingleNode(Roottag + "/resultcode"); if (resultnode != null) { ComResult = Convert.ToInt32(resultnode.InnerText.Trim()); } resultnode = resultRootnode.SelectSingleNode(Roottag + "/resultdescription"); if (resultnode != null) { Comdes = resultnode.InnerText.Trim(); } } string CKID = dsYSDH.Tables[0].Rows[0]["CK"].ToString(); PDParam.AddXmlLog(CKID, filename, YSDH, Comdes, ComResult); if (ComResult == 1) { this.PrintfError("传输成功"); } else { this.PrintfError("传输失败"); } string apppathxml = "../../webinfo/xml"; string pathName = Server.MapPath(apppathxml); if (!Directory.Exists(pathName)) { Directory.CreateDirectory(pathName); } doc.save(pathName + "/" + filename); SaveLocalXml(doc, Aroottag, YSDH); } } catch { this.PrintfError("上传出现错误,请确认服务器地址是否正确"); return; } }
public static string InsertProduct(DataTable dthead, DataTable dtbody) { U8EnvContext envContext = new U8EnvContext(); envContext.U8Login = canshu.u8Login; //envContext.U8Login = u8Login; //第三步:设置API地址标识(Url) //当前API:添加新单据的地址标识为:U8API/MaterialOut/Add U8ApiAddress myApiAddress = new U8ApiAddress("U8API/ARClose/SaveVouch"); //第四步:构造APIBroker U8ApiBroker broker = new U8ApiBroker(myApiAddress, envContext); //第五步:API参数赋值 ////给普通参数sVouchType赋值。此参数的数据类型为System.String,此参数按值传递,表示单据类型:11 //broker.AssignNormalValue("sVouchType", "11"); ////该参数VouchId为INOUT型普通参数。此参数的数据类型为System.String,此参数按值传递。在API调用返回时,可以通过GetResult("VouchId")获取其值 //string vouid = ""; //broker.AssignNormalValue("VouchId", vouid); ////该参数domMsg为OUT型参数,由于其数据类型为MSXML2.IXMLDOMDocument2,非一般值类型,因此必须传入一个参数变量。在API调用返回时,可以直接使用该参数 MSXML2.IXMLDOMDocument2 domMsg = new MSXML2.DOMDocumentClass(); broker.AssignNormalValue("domMsg", domMsg); ////给普通参数bCheck赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否控制可用量。 //broker.AssignNormalValue("bCheck", true); ////给普通参数bBeforCheckStock赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示检查可用量 //broker.AssignNormalValue("bBeforCheckStock", true); ////给普通参数bIsRedVouch赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否红字单据 //broker.AssignNormalValue("bIsRedVouch", false); ////给普通参数sAddedState赋值。此参数的数据类型为System.String,此参数按值传递,表示传空字符串 //string sadd = ""; //broker.AssignNormalValue("sAddedState", sadd); ////给普通参数bReMote赋值。此参数的数据类型为System.Boolean,此参数按值传递,表示是否远程:转入false //broker.AssignNormalValue("bReMote", false); //打开adodb连接 Connection oCon = new ConnectionClass(); oCon.Open(envContext.U8Login.UfDbName); MSXML2.IXMLDOMDocument2 domhead = new DOMDocument(); MSXML2.IXMLDOMDocument2 dombody = new DOMDocument(); //表头赋值 //表头DOM赋值 string sqlt = "select cast(null as nvarchar(2)) as editprop,* from AR_CloseR where 1=2 "; Recordset rs = new Recordset(); rs.Open(sqlt, oCon, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly); rs.Save(domhead, PersistFormatEnum.adPersistXML); //插入表头信息 IXMLDOMElement eleHead = (IXMLDOMElement)domhead.selectSingleNode("//rs:data"); IXMLDOMElement ele = (IXMLDOMElement)domhead.createElement("z:row"); eleHead.appendChild(ele); try { ele.setAttribute("editprop", "A");//A代表增加,M代表修改 ele.setAttribute("dVouchDate", DateTime.Now.ToShortDateString()); ele.setAttribute("cdwcode", "0999"); //ele.setAttribute("id", rdid); ele.setAttribute("ccode", "100"); ele.setAttribute("VT_ID", "65"); ele.setAttribute("ddate", DateTime.Now.ToShortDateString()); //出库日期 ele.setAttribute("dnmaketime", DateTime.Now.ToString()); //制单日期 ele.setAttribute("cmemo", "下料生成"); //备注 ele.setAttribute("cmaker", canshu.u8Login.cUserName); //制单人 broker.AssignNormalValue("DomHead", domhead); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误发生", MessageBoxButtons.OK, MessageBoxIcon.Error); return("0"); } //表体赋值 string sqlw = "select cast(null as nvarchar(2)) as editprop,* from recordoutsq where 1=2 "; //Recordset rs = new Recordset(); rs.Close(); rs.Open(sqlw, oCon, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly); rs.Save(dombody, PersistFormatEnum.adPersistXML); //插入表体尾信息 //dombody.rowcount = IXMLDOMElement eleBody = (IXMLDOMElement)dombody.selectSingleNode("//rs:data"); for (int i = 0; i < dtbody.Rows.Count; i++) { ele = (IXMLDOMElement)dombody.createElement("z:row"); eleBody.appendChild(ele); // 表尾赋值 //string cinvcode = "01019002063"; //int autoid = 1000; //decimal sl = 4m; try { ele.setAttribute("editprop", "A"); //ele.setAttribute("autoid", autoid); ele.setAttribute("cinvcode", DbHelper.GetDbString(dtbody.Rows[i]["存货编码"])); if (string.IsNullOrEmpty(DbHelper.GetDbString(dtbody.Rows[i]["lotno"])) != true) { ele.setAttribute("cBatch", DbHelper.GetDbString(dtbody.Rows[i]["lotno"])); } ele.setAttribute("iquantity", DbHelper.GetDbString(dtbody.Rows[i]["本次下料"])); //MessageBox.Show(dtbody.Rows[i]["本次下料"].ToString()); ele.setAttribute("iMPoIds", DbHelper.GetDbInt(dtbody.Rows[i]["allocateid"])); ele.setAttribute("cmocode", DbHelper.GetDbString(dthead.Rows[0]["染料单号"])); ele.setAttribute("inquantity", DbHelper.GetDbdecimal(dtbody.Rows[i]["未下数量"])); //未下应下数量 //生产订单信息 ele.setAttribute("invcode", DbHelper.GetDbString(dthead.Rows[0]["色号"])); ele.setAttribute("imoseq", DbHelper.GetDbString(dthead.Rows[0]["sortseq"])); ele.setAttribute("iopseq", DbHelper.GetDbString(dtbody.Rows[i]["opseq"])); ele.setAttribute("copdesc", DbHelper.GetDbString(dtbody.Rows[i]["工序"])); ele.setAttribute("iExpiratDateCalcu", 0); ele.setAttribute("irowno", i + 1); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误发生", MessageBoxButtons.OK, MessageBoxIcon.Error); return("0"); } } broker.AssignNormalValue("DomBody", dombody); //测试结果 //domhead.save(@"d:\2xml"); //dombody.save(@"d:\3.xm.l"); //第六步:调用API if (!broker.Invoke()) { //错误处理 Exception apiEx = broker.GetException(); if (apiEx != null) { if (apiEx is MomSysException) { MomSysException sysEx = apiEx as MomSysException; MessageBox.Show("系统异常:" + sysEx.Message); //todo:异常处理 } else if (apiEx is MomBizException) { MomBizException bizEx = apiEx as MomBizException; MessageBox.Show("API异常:" + bizEx.Message); //todo:异常处理 } //异常原因 String exReason = broker.GetExceptionString(); if (exReason.Length != 0) { MessageBox.Show("异常原因:" + exReason); } } //结束本次调用,释放API资源 broker.Release(); return("0"); } //第七步:获取返回结果 //获取返回值 //获取普通返回值。此返回值数据类型为System.Boolean,此参数按值传递,表示返回值:true:成功,false:失败 System.Boolean result = Convert.ToBoolean(broker.GetReturnValue()); if (result == false) { //获取普通OUT参数errMsg。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空 System.String errMsgRet = broker.GetResult("errMsg") as System.String; if (errMsgRet != null) { MessageBox.Show(errMsgRet.ToString(), "错误提示1!"); } return("2"); //MessageBox.Show(result.ToString(), "导入成功提示"); } ////获取out/inout参数值 ////获取普通OUT参数errMsg。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空 //System.String errMsgRet = broker.GetResult("errMsg") as System.String; //if (errMsgRet != null) // MessageBox.Show(errMsgRet.ToString(), "错误提示1!"); ////获取普通INOUT参数VouchId。此返回值数据类型为System.String,在使用该参数之前,请判断是否为空 System.String VouchIdRet = broker.GetResult("VouchId") as System.String; ////获取普通OUT参数domMsg。此返回值数据类型为MSXML2.IXMLDOMDocument2,在使用该参数之前,请判断是否为空 //MSXML2.IXMLDOMDocument2 domMsgRet = (broker.GetResult("domMsg")) as MSXML2.IXMLDOMDocument2; //if (domMsgRet != null) // MessageBox.Show(domMsgRet.ToString(), "错误提示2!"); //结束本次调用,释放API资源 broker.Release(); return(VouchIdRet); }