/// <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(""); } }
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; } }