コード例 #1
0
        private bool LoadText(string str, ref StringDictionary typeDict)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(str);

                if (xmlDoc != null)
                {
                    /*XmlNodeList nodeList_pri = xmlDoc.SelectNodes("//PRI_TABLE_DATA");
                     * if (!parseXmlListp(nodeList_pri))
                     * {
                     *  MessageBox.Show("未能全部正确解析主记录!");
                     *  return false;
                     * }*/

                    /*  XmlNodeList nodeList_pri = xmlDoc.SelectNodes("//PRI_TABLE_DATA");
                     * if (!parseXmlListInsert(nodeList_pri, ref typeDict, str))
                     * {
                     *    //ZTDialog.ztMessageBox.Messagebox("未能全部正确解析附记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     *    MessageBox.Show("未能全部正确解析主记录!");
                     *    return false;
                     * }*/

                    XmlNodeList nodeList_sub1 = xmlDoc.SelectNodes("//SUB_TABLE_DATA");
                    Tool.WriteLogToFile("---------------------");
                    Tool.WriteLogToFile("file name:" + xmlDoc.BaseURI);
                    Tool.WriteLogToFile("---------------------");
                    if (!parseXmlListInsert(nodeList_sub1, ref typeDict, str))
                    {
                        //ZTDialog.ztMessageBox.Messagebox("未能全部正确解析附记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        // MessageBox.Show("未能全部正确解析sub记录!");
                        Tool.WriteLogToFile("---------------------");
                        Tool.WriteLogToFile("未能全部正确解析sub记录!");
                        Tool.WriteLogToFile("---------------------");
                        return(false);
                    }
                    //MessageBox.Show("数据插入成功!");

                    //ZTDialog.ztMessageBox.Messagebox("数据入库成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                Tool.WriteLogToFile("---------------");
                //MessageBox.Show("解析xml数据文件的过程中发生异常!");
                Toolp.WriteLogToFile("详细错误信息:" + ex.Message);
                Tool.WriteLogToFile("---------------");
                return(false);
            }
            MessageBox.Show("执行完毕!");
            return(true);
        }
コード例 #2
0
        private bool parseXmlListp(XmlNodeList nodeList)
        {
            try
            {
                if (nodeList != null && nodeList.Count != 0)
                {
                    for (int i = 0; i < nodeList.Count; i++)
                    {
                        string table_Name = string.Empty;
                        if (nodeList[i].Attributes["tableName"] != null)
                        {
                            table_Name = nodeList[i].Attributes["tableName"].Value.Trim();
                        }

                        string query_Fields = string.Empty;
                        //if (nodeList[i].Attributes["queryFields"] != null)
                        //{
                        //    query_Fields = nodeList[i].Attributes["queryFields"].Value.Trim();
                        //}

                        //if (string.IsNullOrEmpty(table_Name) || string.IsNullOrEmpty(query_Fields))
                        //{
                        //    Tool.WriteLogToFile("表名或字段系列为空");
                        //    return false;
                        //}
                        query_Fields = "PHQYGZ_GUID,XZQ_DM,YGC_HJ,YGC_CSPHQ,YGC_CZCPHQ,XM_ZT,SH_ZT,CREATE_DATE,CREATE_USER,SB_SJ,PHQGZ_GUID,MKPHQ_Y,KQPHQ_Y,GKPHQ_Y,LQPHQ_Y";
                        string[] fields = query_Fields.Split(',');
                        if (fields.Length == 0)
                        {
                            Toolp.WriteLogToFile("无字段系列");
                            return(false);
                        }

                        if (nodeList[i].HasChildNodes)
                        {
                            XmlNodeList list = nodeList[i].SelectNodes("RECORD");

                            if (list != null && list.Count != 0)
                            {
                                for (int j = 0; j < list.Count; j++)
                                {
                                    List <string> sList = new List <string>();
                                    foreach (string f in fields)
                                    {
                                        sList.Add(list[j].Attributes[f].Value.Trim());
                                    }

                                    if (!Toolp.UpDateToOracle(query_Fields, sList, table_Name))
                                    {
                                        Toolp.WriteLogToFile("更新数据库过程出错");
                                        return(false);
                                    }
                                }
                            }
                            else
                            {
                                Toolp.WriteLogToFile("无record子节点");
                                return(false);
                            }
                        }
                        else
                        {
                            Toolp.WriteLogToFile("无子节点");
                            return(false);
                        }
                    }

                    return(true);
                }
                else
                {
                    Toolp.WriteLogToFile("无主记录或附记录");
                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                Toolp.WriteLogToFile("详细错误信息:" + ex.Message);
                return(false);
            }
        }