Пример #1
0
 /// <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;
     }
 }
Пример #2
0
    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;
        }
    }