dateTable和XmlDocument生成xml文件



  DataTable dt = helper.GetDataTable(ExamSql,pars);// params SqlParameter[] values)
                    //dt.TableName = "ReportInfo";
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        string returnV = "";
                        sqlRowCount = true;

                        foreach (DataRow item in dt.Rows)
                        {
                            XmlDocument xmlDoc = new XmlDocument();   //写入xml文件
                            //创建类型声明节点 
                            XmlDeclaration xdDec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                            xmlDoc.AppendChild(xdDec);

                            //创建根节点 
                            XmlElement xeRoot = xmlDoc.CreateElement("Request");
                            xmlDoc.AppendChild(xeRoot);

                            XmlElement MessageHeader = xmlDoc.CreateElement("MessageHeader");
                            XmlElement frontproviderId = xmlDoc.CreateElement("frontproviderId");//
                            frontproviderId.InnerText = frontprovider;
                            XmlElement inputCharset = xmlDoc.CreateElement("inputCharset");//
                            inputCharset.InnerText = "UTF-8";
                            MessageHeader.AppendChild(frontproviderId);
                            MessageHeader.AppendChild(inputCharset);
                            XmlNode xnXwsp = xmlDoc.SelectSingleNode("Request");
                            if (xnXwsp != null)
                            {
                                xnXwsp.AppendChild(MessageHeader);
                            }
                            //创建并添加节点                    
                            xeRoot = xmlDoc.CreateElement("ReportInfo");

                            if (xnXwsp != null)
                            {
                                xnXwsp.AppendChild(xeRoot);
                            }
                            if (!string.IsNullOrEmpty(item["JYSJ"].ToString()))
                            {//先这样吧,不判断格式了。。。。
                                nextDate = DateTime.Parse(item["JYSJ"].ToString()).ToString("yyyy-MM-dd HH:mm:ss.fff");
                            }

                            CreateNode(xmlDoc, xeRoot, "studyuid", item["StudyUid"].ToString());//检查好
                            CreateNode(xmlDoc, xeRoot, "instanceuid", item["InstanceUid"].ToString()); //报告流水号
                            CreateNode(xmlDoc, xeRoot, "yljgdm", item["YLJGDM"].ToString());//医疗机构代码
                            CreateNode(xmlDoc, xeRoot, "wsjgdm", item["WSJGDM"].ToString());//卫生机构代码
                            CreateNode(xmlDoc, xeRoot, "jzlsh", item["JZLSH"].ToString());//就诊流水号  DateTime.Now.ToString("yyyy-MM-dd"));//  日期类型的("yyyy-MM-dd HH:mm:ss:fff")
                            CreateNode(xmlDoc, xeRoot, "mzzybz", item["MZZYBZ"].ToString());//门诊 住院标志
                            CreateNode(xmlDoc, xeRoot, "kh", item["KH"].ToString());//卡号
                            CreateNode(xmlDoc, xeRoot, "klx", item["KLX"].ToString());//卡类型
                            CreateNode(xmlDoc, xeRoot, "brsfz", item["brsfz"].ToString());//病人身份证
                            CreateNode(xmlDoc, xeRoot, "brxm", item["BRXM"].ToString());//病人姓名

                            CreateNode(xmlDoc, xeRoot, "brxb", item["BRXB"].ToString());//病人性别
                            CreateNode(xmlDoc, xeRoot, "patientid", item["PatientID"].ToString());//影像号
                            CreateNode(xmlDoc, xeRoot, "jcxmdmyb", item["JCXMDMYB"].ToString());//项目标准代码
                            CreateNode(xmlDoc, xeRoot, "kdsj", item["KDSJ"].ToString());// //开单--时间DateTime.Now.ToString("yyyy-MM-dd"));
                            CreateNode(xmlDoc, xeRoot, "jysj", item["JYSJ"].ToString());//检查时间DateTime.Now.ToString("yyyy-MM-dd"));//

                            CreateNode(xmlDoc, xeRoot, "examtype", item["ExamType"].ToString());//   检查类型
                            CreateNode(xmlDoc, xeRoot, "sbbm", item["SBBM"].ToString());//检查仪器设备
                            CreateNode(xmlDoc, xeRoot, "yqbm", item["YQBM"].ToString());//检查仪器号
                            CreateNode(xmlDoc, xeRoot, "sqks", item["SQKS"].ToString());//申请科室编码
                            CreateNode(xmlDoc, xeRoot, "sqksmc", item["SQKSMC"].ToString());//申请科室名称
                            CreateNode(xmlDoc, xeRoot, "sqrgh", item["sqrgh"].ToString());//申请人工号
                            //、、  <sqrgh>11</sqrgh> "2018-08-08");//订单
                           //atd
                            CreateNode(xmlDoc, xeRoot, "sqrxm", item["SQRXM"].ToString());//   申请人姓名
                            CreateNode(xmlDoc, xeRoot, "sqrsfz", item["SQRSFZ"].ToString());//申请人身份证
                            CreateNode(xmlDoc, xeRoot, "jcksmc", item["JCKSMC"].ToString());//检查科室名称
                            CreateNode(xmlDoc, xeRoot, "bgrq", item["BGRQ"].ToString());//报告日期DateTime.Now.ToString("yyyy-MM-dd"));//
                            CreateNode(xmlDoc, xeRoot, "bgsj", item["BGSJ"].ToString());//报告时间,DateTime.Now.ToString("yyyy-MM-dd"));//
                            CreateNode(xmlDoc, xeRoot, "bgrxm", item["BGRXM"].ToString());//  报告人姓名
                            CreateNode(xmlDoc, xeRoot, "bgrsfz", item["BGRSFZ"].ToString());//报告人身份证号
                            CreateNode(xmlDoc, xeRoot, "shrxm", item["SHRXM"].ToString());//审核人姓名
                            CreateNode(xmlDoc, xeRoot, "shrsfz", item["SHRSFZ"].ToString());//审核人身份证号
                            CreateNode(xmlDoc, xeRoot, "jcbw", item["JCBW"].ToString());//检查部位

                            CreateNode(xmlDoc, xeRoot, "jcmc", item["JCMC"].ToString());//       检查名称
                            CreateNode(xmlDoc, xeRoot, "zyjcxx1", item["ZYJCXX1"].ToString());//专有检查信息1
                            CreateNode(xmlDoc, xeRoot, "tjsj", item["tjsj"].ToString());//提交时间DateTime.Now.ToString("yyyy-MM-dd"));//

                            //string date = DateTime.Now.ToString("yyyy-MM-dd");
                            //string time = DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "-" + DateTime.Now.Millisecond;
                            //string datetime = date + " " + time;
                            //xmlDoc.Save(Application.StartupPath + "\\功能测试" + datetime + ".xml");
                            //调用WebService服务
                            PortalServicesImplService ss = new PortalServicesImplService();
                            string argo = ConvertXmlToString(xmlDoc);
                            returnV = ss.pushRisReportService(argo);
                            //LogFiles LogFile = new LogFiles();
                            if (returnV.Contains("添加失败"))
                            {
                                LogFile.WriteLine("   " + argo + "   ");
                                LogFile.WriteLine("获取WebService返回信息:" + returnV);
                            }
                            else//成功
                            {
                                LogFile.WriteLine("检查时间:" + nextDate);
                                LogFile.WriteLine("获取WebService返回信息:" + returnV);
                            }


                            //MessageBox.Show(returnV);
                            //string haha = "";
                            //执行返回成功的信息,目前不确定是否只有添加成功,以后再读取xml判断code和desc的值
                            // "2018-08-08");//
                        }//foreach 外面结束了插入XML



                        if (returnV.Contains("添加成功") && sqlRowCount == true)
                        {
                            //添加xml Date节点,下次查询从此时间获取
                            AddDateFromDateXml(nextDateNum, nextDate);


                        }
                    }//row.count>0



-------------------------------------------------------------------------------------------------------------
       /// <summary>   
        /// 创建节点   
        /// </summary>   
        /// <param name="xmldoc"></param>  xml文档 
        /// <param name="parentnode"></param>父节点   
        /// <param name="name"></param>  节点名 
        /// <param name="value"></param>  节点值 
        ///  
        public static void CreateNode(XmlDocument xmlDoc, XmlNode parentNode, string name, string value)
        {
            try
            {
                string value2 = "";
                if (string.IsNullOrEmpty(value))//空值做处理
                    value = "1";
                if (name == "kdsj" || name == "jysj" || name == "bgrq" || name == "bgsj" || name == "tjsj")//日期类型的
                {
                    value2 = DateTime.Parse(value).ToString("yyyy-MM-dd");
                }
                XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null);
                if (value2 != "")
                {
                    node.InnerText = value2.Trim();
                }
                else
                {
                    node.InnerText = value.Trim();
                }
                parentNode.AppendChild(node);
            }
            catch (Exception ex)
            {
                LogFiles log = new LogFiles();
                log.WriteLine("异常信息:" + ex.ToString());

            }
        }
        /// <summary>
        /// 将XmlDocument转化为string
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <returns></returns>
        public string ConvertXmlToString(XmlDocument xmlDoc)
        {

            MemoryStream stream = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(stream, null);
            writer.Formatting = Formatting.Indented;
            xmlDoc.Save(writer);
            StreamReader sr = new StreamReader(stream, System.Text.Encoding.UTF8);
            stream.Position = 0;
            string xmlString = sr.ReadToEnd();
            sr.Close();
            stream.Close();
            return xmlString;
        }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值