using HH.YiDaSyncNC.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace HH.YiDaSyncNC.Helper
{
    class NCImportFunc
    {
        public static string NCImport(XElement tempHeader, XElement xElement, string url)
        {
            try
            {
                tempHeader.Add(xElement);

                //xElement.Element("voucher").Element("voucher_head").Element("details").Add(Bodydebit(body));//表体没有记录

                string xmlString = DBHelper.ToXmlElementMethod(tempHeader).OuterXml;//变成xml字符串

                xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + xmlString;

                DBHelper.WriteLog("传入参数：" + xmlString);

                string resultMsg = DBHelper.SendNsg(xmlString, url);//接收返回的数据

                DBHelper.WriteLog("返回参数：" + resultMsg);

                XElement xE = XElement.Parse(resultMsg);

                string resultcode = xE.Element("sendresult").Element("resultcode").Value;

                return resultMsg;//返回错误信息
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static string NCImport2(XElement xElement, string url)
        {
            try
            {
                string xmlString = DBHelper.ToXmlElementMethod(xElement).OuterXml;//变成xml字符串
                xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + xmlString;
                DBHelper.WriteLog("传入参数：" + xmlString);
                string resultMsg = DBHelper.SendNsg(xmlString, url);//接收返回的数据
                DBHelper.WriteLog("返回参数：" + resultMsg);
                XElement xE = XElement.Parse(resultMsg);
                string resultcode = xE.Element("sendresult").Element("resultcode").Value;
                return resultMsg;//返回错误信息
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
