You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							677 lines
						
					
					
						
							33 KiB
						
					
					
				
			
		
		
	
	
							677 lines
						
					
					
						
							33 KiB
						
					
					
				using ESRI.ArcGIS.Carto; | 
						|
using ESRI.ArcGIS.Geodatabase; | 
						|
using KGIS.Framework.DBOperator; | 
						|
using KGIS.Framework.Maps; | 
						|
using KGIS.Framework.Platform; | 
						|
using KGIS.Framework.Utils; | 
						|
using Kingo.PluginServiceInterface; | 
						|
using Kingo.PluginServiceInterface.Model; | 
						|
using System; | 
						|
using System.Collections.Generic; | 
						|
using System.Data; | 
						|
using System.Linq; | 
						|
using System.Runtime.InteropServices; | 
						|
 | 
						|
namespace Kingo.Plugin.DataLoad.Helper | 
						|
{ | 
						|
    public class SetDicManageHelper | 
						|
    { | 
						|
        private static List<QSDWinformation> ListQsdwEntity = null; | 
						|
        private static List<QSDWinformation> ListQsdm = null; | 
						|
        private static string XJFid = null; | 
						|
        private static string FJFid = null; | 
						|
        private static string QsdmID = null; | 
						|
 | 
						|
        private static string txt_CJDMCD = string.Empty; | 
						|
        private static string txt_XianJDMCD = string.Empty; | 
						|
        private static string txt_ShengJMC = string.Empty; | 
						|
        private static string txt_ShiJMC = string.Empty; | 
						|
        private static string txt_XJMC = string.Empty; | 
						|
        private static string txt_XJDM = string.Empty; | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 设置字典 | 
						|
        /// </summary> | 
						|
        public static void SetDicManage() | 
						|
        { | 
						|
            IFeatureCursor featureCursor = null; | 
						|
            IFeature feature = null; | 
						|
            try | 
						|
            { | 
						|
                ListQsdwEntity = new List<QSDWinformation>(); | 
						|
                IFeatureClass jcdltbFC = MapsManager.Instance.MapService.GetFeatureClassByName("DLTB"); | 
						|
                if (jcdltbFC != null && jcdltbFC.FeatureCount(null) > 0) | 
						|
                { | 
						|
                    var idx_QSDWDM = jcdltbFC.FindField("QSDWDM"); | 
						|
                    var idx_QSDWMC = jcdltbFC.FindField("QSDWMC"); | 
						|
                    var idx_ZLDWDM = jcdltbFC.FindField("ZLDWDM"); | 
						|
                    var idx_ZLDWMC = jcdltbFC.FindField("ZLDWMC"); | 
						|
 | 
						|
                    featureCursor = jcdltbFC.Search(null, true); | 
						|
                    while ((feature = featureCursor.NextFeature()) != null) | 
						|
                    { | 
						|
                        QSDWinformation QsdwEntity = new QSDWinformation(); | 
						|
                        if (idx_QSDWDM > -1) | 
						|
                        { | 
						|
                            var tempQsdwdm = feature.get_Value(idx_QSDWDM).ToString(); | 
						|
                            QsdwEntity.Qsdwdm = tempQsdwdm; | 
						|
                        } | 
						|
                        if (idx_QSDWMC > -1) | 
						|
                        { | 
						|
                            QsdwEntity.Qsdwmc = feature.get_Value(idx_QSDWMC).ToString(); | 
						|
                            if (QsdwEntity.Qsdwmc == "部队") { } | 
						|
                        } | 
						|
                        if (idx_ZLDWDM > -1) | 
						|
                        { | 
						|
                            var tempZLDWDM = feature.get_Value(idx_ZLDWDM).ToString(); | 
						|
                            QsdwEntity.ZLDWDM = tempZLDWDM; | 
						|
                        } | 
						|
                        if (idx_ZLDWMC > -1) | 
						|
                        { | 
						|
                            QsdwEntity.Zldwmc = feature.get_Value(idx_ZLDWMC).ToString(); | 
						|
                        } | 
						|
                        QsdwEntity.HasCheck = true; | 
						|
                        if (ListQsdwEntity != null && ListQsdwEntity.Where(x => x.ZLDWDM == QsdwEntity.ZLDWDM).Count() == 0) | 
						|
                        { | 
						|
                            ListQsdwEntity.Add(QsdwEntity); | 
						|
                        } | 
						|
                    } | 
						|
                    AnalysisCode(); | 
						|
                    Run(); | 
						|
                    OrderBy(txt_CJDMCD, txt_XJMC); | 
						|
                    CheckExist(); | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug("设置字典发生异常:" + ex); | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
                if (featureCursor != null) | 
						|
                    Marshal.ReleaseComObject(featureCursor); | 
						|
                if (feature != null) | 
						|
                    Marshal.ReleaseComObject(feature); | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private static void AnalysisCode() | 
						|
        { | 
						|
            IRDBHelper rdbHelper = null; | 
						|
            try | 
						|
            { | 
						|
                //去除坐落单位代码 | 
						|
                if (ListQsdwEntity != null && ListQsdwEntity.Count > 0) | 
						|
                { | 
						|
                    var first = ListQsdwEntity.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.ZLDWDM) && (new[] { 12, 19 }).Contains(x.ZLDWDM.Length)); | 
						|
                    if (first != null) | 
						|
                    { | 
						|
                        txt_XJDM = first.ZLDWDM.Substring(0, 2).ToString(); | 
						|
                        txt_XianJDMCD = first.ZLDWDM.Substring(0, 4).ToString(); | 
						|
                        txt_CJDMCD = first.ZLDWDM.Substring(0, 6).ToString(); | 
						|
 | 
						|
                        string systemPath = SysAppPath.GetDataBasePath() + "System.mdb"; | 
						|
                        if (System.IO.File.Exists(systemPath)) | 
						|
                        { | 
						|
                            string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection"); | 
						|
                            connStr = string.Format(connStr, systemPath); | 
						|
                            rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess); | 
						|
                            string strSQL = String.Format("select XZQMC, XZQ,SDM,SMC,SHDM,SHMC from XZQ Where XZQ ='{0}' ", txt_CJDMCD); | 
						|
                            DataTable dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true); | 
						|
                            if (dt != null && dt.Rows.Count != 0) | 
						|
                            { | 
						|
                                DataRow row = dt.Rows[0]; | 
						|
                                txt_ShengJMC = row["SHMC"].ToString();//省级名称 | 
						|
                                txt_ShiJMC = row["SMC"].ToString();//市级名称 | 
						|
                                txt_XJMC = row["XZQMC"].ToString();//县级名称 | 
						|
                            } | 
						|
                        } | 
						|
                    } | 
						|
                    else | 
						|
                    { | 
						|
                        txt_XJDM = ""; | 
						|
                        txt_XianJDMCD = ""; | 
						|
                        txt_CJDMCD = ""; | 
						|
                        txt_ShengJMC = "";//省级名称 | 
						|
                        txt_ShiJMC = "";//市级名称 | 
						|
                        txt_XJMC = "";//县级名称 | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                throw ex; | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
                rdbHelper?.DisConnect(); | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private static void Run() | 
						|
        { | 
						|
            ListQsdwEntity.ForEach(item => | 
						|
            { | 
						|
                if (string.IsNullOrWhiteSpace(item.ZLDWDM) == false && string.IsNullOrWhiteSpace(item.Qsdwdm) == false) | 
						|
                { | 
						|
                    if (item.ZLDWDM.Length == 12) | 
						|
                    { | 
						|
                        item.ZLDWDM = item.ZLDWDM.PadRight(19, '0'); | 
						|
                    } | 
						|
                    if (item.ZLDWDM.Length != 19) | 
						|
                    { | 
						|
                        item.HasCheck = false; | 
						|
                    } | 
						|
                    if (item.Qsdwdm.Length == 12) | 
						|
                    { | 
						|
                        item.Qsdwdm = item.Qsdwdm.PadRight(19, '0'); | 
						|
                    } | 
						|
                    if (item.Qsdwdm.Length != 19) | 
						|
                    { | 
						|
                        item.HasCheck = false; | 
						|
                    } | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    item.HasCheck = false; | 
						|
                } | 
						|
            }); | 
						|
            //处理验证失败的数据 | 
						|
            for (var i = 0; i < ListQsdwEntity.Count; i++) | 
						|
            { | 
						|
                if (ListQsdwEntity[i].HasCheck == false) | 
						|
                { | 
						|
                    ListQsdwEntity.Remove(ListQsdwEntity[i]); | 
						|
                    if (i > 0) | 
						|
                    { | 
						|
                        i = i - 1; | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private static void OrderBy(string XJCode, string XJName) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                if (ListQsdwEntity != null && ListQsdwEntity.Count > 0) | 
						|
                { | 
						|
                    ListQsdm = new List<QSDWinformation>(); | 
						|
                    var GroupEntity = ListQsdwEntity.Where(x => x.ZLDWDM.Length == 19).GroupBy(x => x.ZLDWDM.Substring(0, 9)).Select(x => x.Key).ToList();//获取村级坐落获取镇级权属代码前九位 | 
						|
                    var Temp = ListQsdwEntity.FirstOrDefault(x => x.Qsdwdm == XJCode.PadRight(19, '0')); | 
						|
                    if (Temp != null && Temp.Qsdwmc != XJName) | 
						|
                        GroupEntity.Add(Temp.Qsdwdm.Substring(0, 9)); | 
						|
                    foreach (var item in GroupEntity)//截取乡镇权属代码 | 
						|
                    { | 
						|
                        QSDWinformation Qsdm = new QSDWinformation(); | 
						|
                        Qsdm.ZLDWDM = item; | 
						|
                        Qsdm.Qsdwdm = item; | 
						|
                        BasicDataModel[] xzqDic = GetXZQDic(2); | 
						|
                        if (xzqDic == null) | 
						|
                            return; | 
						|
                        var xzqInfo = xzqDic.Where(x => x.Code == item).ToList(); | 
						|
                        if (xzqInfo.Count == 0) | 
						|
                            xzqInfo = xzqDic.Where(x => x.Code == item.Replace(item.Substring(0, 6), xzqDic[0].Code.Substring(0, 6))).ToList(); | 
						|
                        foreach (var xzq in xzqInfo) | 
						|
                        { | 
						|
                            Qsdm.Qsdwmc = xzq.Name; | 
						|
                            Qsdm.Zldwmc = xzq.Name; | 
						|
                        } | 
						|
                        List<QSDWinformation> ListCjQsdm = new List<QSDWinformation>(); | 
						|
                        if (item == XJCode.PadRight(9, '0'))//特殊案例-与县级同权属代码的镇一级(并且为非飞入地) | 
						|
                        { | 
						|
                            Qsdm.ZLDWDM = XJCode.PadRight(9, '0'); | 
						|
                            Qsdm.Qsdwdm = XJCode.PadRight(9, '0'); | 
						|
                            Qsdm.Qsdwmc = Temp.Qsdwmc; | 
						|
                            Qsdm.Zldwmc = Temp.Qsdwmc; | 
						|
                            QSDWinformation CjQsdm = new QSDWinformation(); | 
						|
                            CjQsdm.Qsdwdm = XJCode.PadRight(12, '0'); | 
						|
                            CjQsdm.ZLDWDM = XJCode.PadRight(12, '0'); | 
						|
                            CjQsdm.Qsdwmc = Temp.Qsdwmc; | 
						|
                            CjQsdm.Zldwmc = Temp.Qsdwmc; | 
						|
                            List<QSDWinformation> ListCjDMQsdm = new List<QSDWinformation>(); | 
						|
                            QSDWinformation CjDMQsdm = new QSDWinformation(); | 
						|
                            CjDMQsdm.Qsdwdm = ""; | 
						|
                            CjDMQsdm.Qsdwmc = ""; | 
						|
                            ListCjDMQsdm.Add(CjDMQsdm); | 
						|
                            CjQsdm.ListQsdwInfor = null;//权属村级子级 | 
						|
                            ListCjQsdm.Add(CjQsdm); | 
						|
                            Qsdm.ListQsdwInfor = null;//权属镇级子级 | 
						|
                            ListQsdm.Add(Qsdm); | 
						|
                            continue; | 
						|
                        } | 
						|
                        #region | 
						|
                        var CJGroupEntity = ListQsdwEntity.Where(x => x.HasCheck).GroupBy(x => x.ZLDWDM).OrderBy(x => x.Key).Select(x => x.Key).Distinct().ToList(); | 
						|
                        var tmpcjglist = CJGroupEntity.Where(x => x.Substring(0, 9) == item).ToList(); | 
						|
                        foreach (var CJitem in tmpcjglist)//截取村级权属代码 | 
						|
                        { | 
						|
                            QSDWinformation CjQsdm = new QSDWinformation(); | 
						|
                            CjQsdm.Qsdwdm = CJitem; | 
						|
                            CjQsdm.ZLDWDM = CJitem; | 
						|
                            #region | 
						|
 | 
						|
                            var cjlist = ListQsdwEntity.Where(x => x.ZLDWDM.StartsWith(CJitem)).ToList(); | 
						|
                            var keylist = cjlist.Select(x => x.ZLDWDM).Distinct().ToList(); | 
						|
                            foreach (var citem in keylist) | 
						|
                            { | 
						|
                                CjQsdm.Zldwmc = ListQsdwEntity.FirstOrDefault(x => x.ZLDWDM == citem).Zldwmc; | 
						|
                                List<QSDWinformation> ListCjDMQsdm = new List<QSDWinformation>(); | 
						|
                                var CJDMGroupEntity = ListQsdwEntity.Where(x => x.HasCheck).GroupBy(x => x.ZLDWDM).Select(x => x.Key).Distinct().ToList();//.Select(n => n); | 
						|
                                var tmpglist = CJDMGroupEntity.Where(x => x.Substring(0, 12) == CJitem.Substring(0, 12)).ToList(); | 
						|
                                foreach (var CJDMitem in tmpglist)//获取村级代码 | 
						|
                                { | 
						|
                                    #region | 
						|
                                    var cjkeylist = ListQsdwEntity.Where(x => x.HasCheck && x.ZLDWDM == CJDMitem).Distinct().ToList(); | 
						|
                                    foreach (var itemsD in cjkeylist)//获取村级小组权属代码名称 | 
						|
                                    { | 
						|
                                        var cu = ListCjDMQsdm.Count(x => x.Qsdwdm == itemsD.Qsdwdm && x.Qsdwmc == itemsD.Qsdwmc); | 
						|
                                        if (cu == 0) | 
						|
                                        { | 
						|
                                            QSDWinformation CjDMQsdm = new QSDWinformation(); | 
						|
                                            CjDMQsdm.Qsdwdm = itemsD.Qsdwdm; | 
						|
                                            CjDMQsdm.Qsdwmc = itemsD.Qsdwmc; | 
						|
                                            ListCjDMQsdm.Add(CjDMQsdm); | 
						|
                                        } | 
						|
                                    } | 
						|
                                    #endregion | 
						|
                                } | 
						|
                                CjQsdm.ListQsdwInfor = ListCjDMQsdm; | 
						|
                            } | 
						|
                            ListCjQsdm.Add(CjQsdm); | 
						|
                            #endregion | 
						|
                        } | 
						|
                        Qsdm.ListQsdwInfor = ListCjQsdm; | 
						|
                        ListQsdm.Add(Qsdm); | 
						|
                        #endregion | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                throw ex; | 
						|
            } | 
						|
        } | 
						|
        private static BasicDataModel[] GetXZQDic(int pLevel) | 
						|
        { | 
						|
            List<BasicDataModel> result = new List<BasicDataModel>(); | 
						|
            if (pLevel == 1) | 
						|
            { | 
						|
                IRDBHelper helper = null; | 
						|
                DataTable dtData = null; | 
						|
                try | 
						|
                { | 
						|
                    string strConn = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection"); | 
						|
                    strConn = string.Format(strConn, SysAppPath.GetDataBaseRoot() + "System.mdb"); | 
						|
                    if (string.IsNullOrWhiteSpace(strConn)) | 
						|
                    { | 
						|
                        result = null; | 
						|
                    } | 
						|
                    helper = RDBFactory.CreateDbHelper(strConn, DatabaseType.MSAccess); | 
						|
                    string strSQL = string.Format("SELECT * FROM {0} where XZQ ='{1}'", "XZQ", ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) as ProjectInfo).CODE); | 
						|
                    dtData = helper.ExecuteDatatable("dtData", strSQL, true); | 
						|
                    if (dtData != null) | 
						|
                    { | 
						|
                        foreach (DataRow row in dtData.Rows) | 
						|
                        { | 
						|
                            BasicDataModel node = new BasicDataModel(); | 
						|
                            node.Name = row["XZQMC"] is DBNull ? "" : row["XZQMC"].ToString(); | 
						|
                            node.Code = row["XZQ"].ToString(); | 
						|
                            node.DisplayName = string.Format("({0}){1}", node.Code, node.Name); | 
						|
                            node.Attribures = new Dictionary<string, object>(); | 
						|
                            foreach (DataColumn col in dtData.Columns) | 
						|
                            { | 
						|
                                node.Attribures.Add(col.ColumnName, row[col]); | 
						|
                            } | 
						|
                            result.Add(node); | 
						|
                        } | 
						|
                    } | 
						|
                    return result.ToArray(); | 
						|
                } | 
						|
                catch (Exception ex) | 
						|
                { | 
						|
                    LogAPI.Debug(ex); | 
						|
                } | 
						|
                finally | 
						|
                { | 
						|
                    if (dtData != null) | 
						|
                    { | 
						|
                        dtData.Clear(); | 
						|
                        dtData.Dispose(); | 
						|
                    } | 
						|
                    if (helper != null) | 
						|
                    { | 
						|
                        helper.DisConnect(); | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            else if (pLevel == 2) | 
						|
            { | 
						|
                ICursor pCur = null; | 
						|
                try | 
						|
                { | 
						|
                    IFeatureLayer fcLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("行政区"); | 
						|
                    if (fcLayer == null) | 
						|
                    { | 
						|
                        return result.ToArray(); | 
						|
                    } | 
						|
                    //获取基础mdb中的tbmj之和 | 
						|
                    IQueryDef pQDef = ((fcLayer.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace).CreateQueryDef(); | 
						|
                    pQDef.Tables = (fcLayer.FeatureClass as FeatureClass).Name; | 
						|
                    pQDef.SubFields = "*"; | 
						|
                    pCur = pQDef.Evaluate(); | 
						|
                    IRow pRow = null; | 
						|
                    while ((pRow = pCur.NextRow()) != null) | 
						|
                    { | 
						|
                        BasicDataModel node = new BasicDataModel(); | 
						|
                        node.Name = pRow.get_Value(pRow.Fields.FindField("XZQMC")) is DBNull ? "" : pRow.get_Value(pRow.Fields.FindField("XZQMC")).ToString(); | 
						|
                        node.Code = pRow.get_Value(pRow.Fields.FindField("XZQDM")).ToString(); | 
						|
                        node.DisplayName = string.Format("({0}){1}", node.Code, node.Name); | 
						|
                        node.Attribures = new Dictionary<string, object>(); | 
						|
                        for (int i = 0; i < pRow.Fields.FieldCount; i++) | 
						|
                        { | 
						|
                            IField field = pRow.Fields.get_Field(i); | 
						|
                            if (field.Name.ToUpper() != "SHAPE") | 
						|
                            { | 
						|
                                node.Attribures.Add(field.Name, pRow.get_Value(pRow.Fields.FindField(field.Name))); | 
						|
                            } | 
						|
                        } | 
						|
                        result.Add(node); | 
						|
                    } | 
						|
 | 
						|
                    return result.ToArray(); | 
						|
                } | 
						|
                catch (Exception ex) | 
						|
                { | 
						|
                    LogAPI.Debug(ex); | 
						|
                } | 
						|
                finally | 
						|
                { | 
						|
                    if (pCur != null) | 
						|
                    { | 
						|
                        Marshal.ReleaseComObject(pCur); | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            else if (pLevel == 3) | 
						|
            { | 
						|
                ICursor pCur = null; | 
						|
                try | 
						|
                { | 
						|
                    IFeatureLayer fcLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("村级调查区"); | 
						|
 | 
						|
                    //获取基础mdb中的tbmj之和 | 
						|
                    IQueryDef pQDef = ((fcLayer.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace).CreateQueryDef(); | 
						|
                    pQDef.Tables = (fcLayer.FeatureClass as FeatureClass).Name; | 
						|
                    pQDef.SubFields = "distinct ZLDWDM,ZLDWMC"; | 
						|
                    pCur = pQDef.Evaluate(); | 
						|
                    IRow pRow = null; | 
						|
                    while ((pRow = pCur.NextRow()) != null) | 
						|
                    { | 
						|
                        BasicDataModel node = new BasicDataModel(); | 
						|
                        node.Name = pRow.get_Value(pRow.Fields.FindField("ZLDWMC")) is DBNull ? "" : pRow.get_Value(pRow.Fields.FindField("ZLDWMC")).ToString(); | 
						|
                        node.Code = pRow.get_Value(pRow.Fields.FindField("ZLDWDM")).ToString().Substring(0, 12); | 
						|
                        node.DisplayName = string.Format("({0}){1}", node.Code, node.Name); | 
						|
                        node.Attribures = new Dictionary<string, object>(); | 
						|
                        result.Add(node); | 
						|
                    } | 
						|
                    return result.ToArray(); | 
						|
                } | 
						|
                catch (Exception ex) | 
						|
                { | 
						|
                    LogAPI.Debug(ex); | 
						|
                } | 
						|
                finally | 
						|
                { | 
						|
                    if (pCur != null) | 
						|
                    { | 
						|
                        Marshal.ReleaseComObject(pCur); | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            else if (pLevel == 4) | 
						|
            { | 
						|
                ICursor pCur = null; | 
						|
                try | 
						|
                { | 
						|
                    IFeatureLayer fcLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("村级调查区"); | 
						|
 | 
						|
                    //获取基础mdb中的tbmj之和 | 
						|
                    IQueryDef pQDef = ((fcLayer.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace).CreateQueryDef(); | 
						|
                    pQDef.Tables = (fcLayer.FeatureClass as FeatureClass).Name; | 
						|
                    pQDef.SubFields = "distinct ZLDWDM,HDMC"; | 
						|
                    pCur = pQDef.Evaluate(); | 
						|
                    IRow pRow = null; | 
						|
                    while ((pRow = pCur.NextRow()) != null) | 
						|
                    { | 
						|
                        BasicDataModel node = new BasicDataModel(); | 
						|
                        node.Name = pRow.get_Value(pRow.Fields.FindField("HDMC")) is DBNull ? "" : pRow.get_Value(pRow.Fields.FindField("HDMC")).ToString(); | 
						|
                        node.Code = pRow.get_Value(pRow.Fields.FindField("ZLDWDM")).ToString().Substring(0, 12); | 
						|
                        node.DisplayName = string.Format("({0}){1}", node.Code, node.Name); | 
						|
                        node.Attribures = new Dictionary<string, object>(); | 
						|
                        result.Add(node); | 
						|
                    } | 
						|
                    return result.ToArray(); | 
						|
                } | 
						|
                catch (Exception ex) | 
						|
                { | 
						|
                    LogAPI.Debug(ex); | 
						|
                } | 
						|
                finally | 
						|
                { | 
						|
                    if (pCur != null) | 
						|
                    { | 
						|
                        Marshal.ReleaseComObject(pCur); | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            return null; | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 检查数据库是否已经存在权属单位代码字典 | 
						|
        /// </summary> | 
						|
        private static void CheckExist() | 
						|
        { | 
						|
            IRDBHelper rdbHelper = null; | 
						|
            try | 
						|
            { | 
						|
 | 
						|
                string Path = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite"; | 
						|
                rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + Path, DatabaseType.SQLite); | 
						|
                if (rdbHelper == null) | 
						|
                { | 
						|
                    throw new Exception("打开数据库连接失败!"); | 
						|
                } | 
						|
                DataTable dtDict = rdbHelper.ExecuteDatatable("Sys_DicType", "select * from Sys_DicManage where NAME='权属代码'", true); | 
						|
                //数据库已存在 | 
						|
                if (dtDict != null && dtDict.Rows.Count > 0) | 
						|
                { | 
						|
                    QsdmID = dtDict.Rows[0]["ID"].ToString(); | 
						|
                    DataTable dtDetail = rdbHelper.ExecuteDatatable("Sys_DicDetail", "select * from Sys_DicDetail where OWNERDIC='" + QsdmID + "'", true); | 
						|
                    if (dtDetail != null && dtDetail.Rows.Count > 0) | 
						|
                    { | 
						|
                        //先删除数据库已存在的字典 | 
						|
                        int insertCount = rdbHelper.ExecuteSQL("DELETE FROM Sys_DicManage WHERE NAME = '权属代码' AND TYPE=1"); | 
						|
                        if (insertCount < 0) | 
						|
                            throw new Exception("删除已存在字典失败!"); | 
						|
                        insertCount = rdbHelper.ExecuteSQL("DELETE FROM Sys_DicDetail WHERE OWNERDIC = '" + QsdmID + "'"); | 
						|
                        if (insertCount < 0) | 
						|
                            throw new Exception("删除已存在字典失败!"); | 
						|
                        //插入Sys_DicManage表 | 
						|
                        insertCount = rdbHelper.ExecuteSQL("INSERT INTO Sys_DicManage (NAME,ALIASNAME,TYPE,REMARK,PAIXU)" + "VALUES ('权属代码','QSDM',1,'',0)"); | 
						|
                        if (insertCount < 0) | 
						|
                            throw new Exception("插入字典失败!"); | 
						|
                    } | 
						|
                } | 
						|
                else//数据库不存在权属单位代码字典 | 
						|
                { | 
						|
                    //插入Sys_DicManage表 | 
						|
                    int insertCount = rdbHelper.ExecuteSQL("INSERT INTO Sys_DicManage (NAME,ALIASNAME,TYPE,REMARK,PAIXU)" + "VALUES ('权属代码','QSDM',1,'',0)"); | 
						|
                    if (insertCount < 0) | 
						|
                        throw new Exception("插入字典失败!"); | 
						|
                } | 
						|
                InserDataDic(rdbHelper); | 
						|
                if (InserDataLsitSon()) | 
						|
                { | 
						|
                    return; | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                throw ex; | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
                if (rdbHelper != null) | 
						|
                    rdbHelper.DisConnect(); | 
						|
            } | 
						|
        } | 
						|
        private static void InserDataDic(IRDBHelper rdbHelper) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                DataTable QuerySon = rdbHelper.ExecuteDatatable("QuerySon", "SELECT ID FROM Sys_DicManage WHERE NAME='权属代码'", false); | 
						|
                string strSql = string.Empty; | 
						|
                if (QuerySon == null || QuerySon.Rows.Count <= 0) | 
						|
                    return; | 
						|
                if (!string.IsNullOrWhiteSpace(txt_XJDM)) | 
						|
                    strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", "", txt_ShengJMC, txt_XJDM, QuerySon.Rows[0]["ID"].ToString(), "", 0); | 
						|
                else | 
						|
                    strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", "", txt_ShengJMC, txt_ShengJMC, QuerySon.Rows[0]["ID"].ToString(), "", 0); | 
						|
                int insertCount = rdbHelper.ExecuteSQL(strSql); | 
						|
                if (insertCount <= 0) | 
						|
                    return; | 
						|
                DataTable QueryQSSon = null; | 
						|
                if (!string.IsNullOrWhiteSpace(txt_XJDM)) | 
						|
                { | 
						|
                    QueryQSSon = rdbHelper.ExecuteDatatable("QueryQS", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='' AND CODE='{1}' AND OWNERDIC='{2}'", txt_ShengJMC, txt_XJDM, QuerySon.Rows[0]["ID"].ToString()), false); | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    QueryQSSon = rdbHelper.ExecuteDatatable("QueryQS", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='' AND CODE='{1}' AND OWNERDIC='{2}'", txt_ShengJMC, txt_ShengJMC, QuerySon.Rows[0]["ID"].ToString()), false); | 
						|
                } | 
						|
                if (QueryQSSon == null || QueryQSSon.Rows.Count <= 0) | 
						|
                { | 
						|
                    return; | 
						|
                } | 
						|
                if (!string.IsNullOrWhiteSpace(txt_XianJDMCD)) | 
						|
                { | 
						|
                    strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", QueryQSSon.Rows[0]["ID"].ToString(), txt_ShiJMC, txt_XianJDMCD, QuerySon.Rows[0]["ID"].ToString(), "", 0); | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", QueryQSSon.Rows[0]["ID"].ToString(), txt_ShiJMC, txt_ShiJMC, QuerySon.Rows[0]["ID"].ToString(), "", 0); | 
						|
                } | 
						|
                insertCount = rdbHelper.ExecuteSQL(strSql); | 
						|
                if (insertCount <= 0) | 
						|
                    return; | 
						|
                DataTable QueryQSSons = null; | 
						|
                if (txt_XianJDMCD != "") | 
						|
                { | 
						|
                    QueryQSSons = rdbHelper.ExecuteDatatable("QueryQSs", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", txt_ShiJMC, QueryQSSon.Rows[0]["ID"].ToString(), txt_XianJDMCD, QuerySon.Rows[0]["ID"].ToString()), false); | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    QueryQSSons = rdbHelper.ExecuteDatatable("QueryQSs", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", txt_ShiJMC, QueryQSSon.Rows[0]["ID"].ToString(), txt_ShiJMC, QuerySon.Rows[0]["ID"].ToString()), false); | 
						|
                } | 
						|
                if (QueryQSSons == null || QueryQSSons.Rows.Count <= 0) | 
						|
                    return; | 
						|
                if (!string.IsNullOrWhiteSpace(txt_CJDMCD)) | 
						|
                { | 
						|
                    strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", QueryQSSons.Rows[0]["ID"].ToString(), txt_XJMC, txt_CJDMCD, QuerySon.Rows[0]["ID"].ToString(), "", 0); | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", QueryQSSons.Rows[0]["ID"].ToString(), txt_XJMC, txt_XJMC, QuerySon.Rows[0]["ID"].ToString(), "", 0); | 
						|
                } | 
						|
                insertCount = rdbHelper.ExecuteSQL(strSql); | 
						|
                if (insertCount <= 0) | 
						|
                    return; | 
						|
                DataTable QueryQSSonsd = null; | 
						|
                if (txt_CJDMCD != "") | 
						|
                { | 
						|
                    QueryQSSonsd = rdbHelper.ExecuteDatatable("QueryQSsd", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", txt_XJMC, QueryQSSons.Rows[0]["ID"].ToString(), txt_CJDMCD, QuerySon.Rows[0]["ID"].ToString()), false); | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    QueryQSSonsd = rdbHelper.ExecuteDatatable("QueryQSsd", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", txt_XJMC, QueryQSSons.Rows[0]["ID"].ToString(), txt_XJMC, QuerySon.Rows[0]["ID"].ToString()), false); | 
						|
                } | 
						|
 | 
						|
                if (QueryQSSonsd != null && QueryQSSonsd.Rows.Count > 0) | 
						|
                { | 
						|
                    XJFid = QueryQSSonsd.Rows[0]["ID"].ToString(); | 
						|
                    FJFid = QuerySon.Rows[0]["ID"].ToString(); | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug("插入字典失败:" + ex.Message); | 
						|
                throw ex; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private static bool InserDataLsitSon() | 
						|
        { | 
						|
            string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite"; | 
						|
            if (string.IsNullOrWhiteSpace(dbPath)) | 
						|
                return false; | 
						|
            IRDBHelper rdbHelper = null; | 
						|
            try | 
						|
            { | 
						|
                rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite); | 
						|
                if (ListQsdm != null && ListQsdm.Count > 0) | 
						|
                { | 
						|
                    rdbHelper.BeginTransaction(); | 
						|
                    foreach (var item in ListQsdm) | 
						|
                    { | 
						|
                        string strSql = string.Format("insert into Sys_DicDetail(PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)  VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", XJFid, item.Zldwmc, item.ZLDWDM, FJFid, "", 0); | 
						|
                        if (rdbHelper.ExecuteSQL(strSql) > 0) | 
						|
                        { | 
						|
                            DataTable dts = rdbHelper.ExecuteDatatable("XjTable", string.Format("select id from Sys_DicDetail where  PID='{0}' and NAME='{1}' and CODE='{2}' and OWNERDIC='{3}'", XJFid, item.Zldwmc, item.ZLDWDM, FJFid), true); | 
						|
                            if (item.ListQsdwInfor == null) continue;//特殊状况(镇级权属代码与县级权属相同,且当前镇级无子级) | 
						|
                            foreach (var CJitem in item.ListQsdwInfor) | 
						|
                            { | 
						|
                                if (dts == null || dts.Rows.Count <= 0) | 
						|
                                { | 
						|
                                    continue; | 
						|
                                } | 
						|
                                string strSqlCJ = string.Format("insert into Sys_DicDetail(PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)  VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", dts.Rows[0]["ID"].ToString(), CJitem.Zldwmc, CJitem.ZLDWDM, FJFid, "", 0); | 
						|
                                if (rdbHelper.ExecuteSQL(strSqlCJ) <= 0) | 
						|
                                { | 
						|
                                    continue; | 
						|
                                } | 
						|
                                DataTable dtCJDM = rdbHelper.ExecuteDatatable("CJDMTables", string.Format("select id from Sys_DicDetail where  PID='{0}' and NAME='{1}' and CODE='{2}' and OWNERDIC='{3}'", dts.Rows[0]["ID"].ToString(), CJitem.Zldwmc, CJitem.ZLDWDM, FJFid), true); | 
						|
                                if (CJitem.ListQsdwInfor == null || CJitem.ListQsdwInfor.Count == 0) | 
						|
                                { | 
						|
                                    continue; | 
						|
                                } | 
						|
                                if (CJitem.ListQsdwInfor == null) continue;//特殊状况(镇级权属代码与县级权属相同,且当前镇级无子级) | 
						|
                                foreach (var CJDMitem in CJitem.ListQsdwInfor) | 
						|
                                { | 
						|
                                    string CJDMstrSql = string.Format("insert into Sys_DicDetail(PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)  VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", dtCJDM.Rows[0]["ID"].ToString(), CJDMitem.Qsdwmc, CJDMitem.Qsdwdm, FJFid, "", 0); | 
						|
                                    if (rdbHelper.ExecuteSQL(CJDMstrSql) < 1) | 
						|
                                        return false; | 
						|
                                } | 
						|
                            } | 
						|
                        } | 
						|
                    } | 
						|
                    rdbHelper.Commit(); | 
						|
                    return true; | 
						|
                } | 
						|
                return true; | 
						|
            } | 
						|
            catch (Exception e) | 
						|
            { | 
						|
                rdbHelper.Rollback(); | 
						|
                return false; | 
						|
                throw e; | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
                if (rdbHelper != null) | 
						|
                { | 
						|
                    rdbHelper.DisConnect(); | 
						|
                } | 
						|
            } | 
						|
        } | 
						|
    } | 
						|
}
 | 
						|
 |