//以业务行政区划为主,添加到数据库中 private void WriteToDatabaseByMIS() { string strTableName = "T_BUSI_XZQH"; string strTableName2 = "t_base_013_district"; int iIndex = 0; try { //using (conn = new OracleConnection(connString)) { string strQuery = string.Format("select t.district_code,t.district_name,t.district_parent,t.district_level from {0} t where t.district_parent is not null order by t.district_level", strTableName2); DataSet dtSet = DbHelperOra.Query(DbHelperOra.connectionString_Local, strQuery); DataTable dtTable = dtSet.Tables[0]; foreach (DataRow dr in dtTable.Rows) { iIndex++; string strBM = string.Format("{0}", dr[0]); string strName = string.Format("{0}", dr[1]); string strPCODE = string.Format("{0}", dr[2]); string strRLEVEL = string.Format("{0}", dr[3]); double dTolerance = 0.0002; { dTolerance = GetTolerance(strBM); } Recordset recdst2 = GetRecordsetByCode(strBM); Lib.Base.Define.csCenter c = new Lib.Base.Define.csCenter(); Lib.Base.Define.csBounds b = new Lib.Base.Define.csBounds(); if (recdst2 != null && recdst2.RecordCount > 0) { GeoLine geoLine1 = recdst2.GetGeometry() as GeoLine; //c.center = geoLine1.Bounds.Center; c.center = GetCenterPoint(strBM); strName = string.Format("{0}", recdst2.GetFieldValue("NAME")); while (!recdst2.IsEOF) { try { GeoLine geoLine2 = recdst2.GetGeometry() as GeoLine; for (int i = 0; i < geoLine2.PartCount; i++) { GeoLine geoL = new GeoLine(geoLine2[i]); GeoLine geoLine = null; if (geoL[0].Count < 400) { geoLine = geoL; } else { geoLine = Geometrist.Resample(geoL, ResampleType.RTGeneral, dTolerance) as GeoLine; } b.bounds.Add(geoLine[0].Clone()); } } catch (SystemException sysEx) { string strErr = sysEx.Message; } recdst2.MoveNext(); } string strCenter = JSONHelper.ObjectToJSON(c.center); if (strBM.Length > 0) { string strGUID = Guid.NewGuid().ToString("N").ToUpper(); string strPoints = JSONHelper.ObjectToJSON(b); string strSQL = string.Format("insert into {0}(ID,QHMC,QHBM,PID,CENTER,QHJB,VIEWBOUNDS) values('{1}','{2}','{3}','{4}','{5}',{6},empty_blob())", strTableName, strGUID, strName, strBM, strPCODE, strCenter, strRLEVEL); string strROWID = DbHelperOra.ExecuteOracleSql(DbHelperOra.connectionString_172, strSQL); string strFilter = string.Format("rowid = '{0}'", strROWID); DbHelperOra.RwiteRegionBoundsBlobToTable(DbHelperOra.connectionString_172, strTableName, "VIEWBOUNDS", strFilter, strPoints); } } else { try { string strLogFile = string.Format("{0}Undolog.txt", AppDomain.CurrentDomain.BaseDirectory); if (File.Exists(strLogFile)) { StreamWriter sw = new StreamWriter(strLogFile, true); string strContext = string.Format("未能找到图元的编码,{0}:{1}", strBM, strName); sw.WriteLine(strContext); sw.Close(); } else { StreamWriter sw = File.CreateText(strLogFile); string strContext = string.Format("未能找到图元的编码,{0}:{1}", strBM, strName); sw.WriteLine(strContext); sw.Close(); } } catch { } } } MessageBox.Show("入库完毕"); } } catch (SystemException sysEx) { string strErr = sysEx.Message; } }
//更新XZQH的边界线 private void Update_XZQH_Boundary() { string strTableName = "T_BUSI_XZQH"; int iIndex = 0; try { string strWhere = "qhjb=1"; { string strSQL = string.Format("select id,qhmc,qhbm,pid,qhjb from {0} where {1}", strTableName, strWhere); DataSet dtSet = DbHelperOra.Query(DbHelperOra.connectionString_Local, strSQL); DataTable dtTable = dtSet.Tables[0]; foreach (DataRow dr in dtTable.Rows) { iIndex++; string strID = string.Format("{0}", dr[0]); string strQHMC = string.Format("{0}", dr[1]); string strQHBM = string.Format("{0}", dr[2]); string strPID = string.Format("{0}", dr[3]); string strQHJB = string.Format("{0}", dr[4]); double dTolerance = 0.0002; { dTolerance = GetTolerance(strQHBM); } Recordset recdst2 = GetRecordsetByCode(strQHBM); Lib.Base.Define.csBounds b = new Lib.Base.Define.csBounds(); if (recdst2 != null && recdst2.RecordCount > 0) { GeoLine geoLine1 = recdst2.GetGeometry() as GeoLine; while (!recdst2.IsEOF) { try { GeoLine geoLine2 = recdst2.GetGeometry() as GeoLine; for (int i = 0; i < geoLine2.PartCount; i++) { GeoLine geoL = new GeoLine(geoLine2[i]); GeoLine geoLine = null; if (geoL[0].Count < 400) { geoLine = geoL; } else { geoLine = Geometrist.Resample(geoL, ResampleType.RTGeneral, dTolerance) as GeoLine; } b.bounds.Add(geoLine[0].Clone()); } } catch (SystemException sysEx) { string strErr = sysEx.Message; } recdst2.MoveNext(); } if (strQHBM.Length > 0) { string strPoints = JSONHelper.ObjectToJSON(b.bounds); string strFilter = string.Format("qhbm = '{0}'", strQHBM); DbHelperOra.RwiteRegionBoundsBlobToTable(DbHelperOra.connectionString_Local, strTableName, "VIEWBOUNDS", strFilter, strPoints); } } else { try { string strLogFile = string.Format("{0}Undolog.txt", AppDomain.CurrentDomain.BaseDirectory); if (File.Exists(strLogFile)) { StreamWriter sw = new StreamWriter(strLogFile, true); string strContext = string.Format("未能找到图元的编码,{0}:{1}", strQHBM, strQHMC); sw.WriteLine(strContext); sw.Close(); } else { StreamWriter sw = File.CreateText(strLogFile); string strContext = string.Format("未能找到图元的编码,{0}:{1}", strQHBM, strQHMC); sw.WriteLine(strContext); sw.Close(); } } catch { } } } MessageBox.Show("入库完毕"); } } catch (SystemException sysEx) { string strErr = sysEx.Message; } }
//以GIS地图为主,添加到数据库中 private void WriteToDatabaseByGIS() { string strTableName = "t_busi_xzqh_bygis"; string strTableName2 = "t_gov_region"; int iIndex = 0; try { //using (conn = new OracleConnection(connString)) //先删除原来数据 { { string strSQL = string.Format("delete {0}", strTableName); DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL); } } //插入第一条数据“中国” { { string strSQL = string.Format("insert into {0}(id,qhmc,qhbm,pid,qhjb,center,viewbounds,qhpy) values('E312A4C4B6F9416283B7E4052A27C031','中国','000000','0',0,null,empty_blob(),'zhongguo')", strTableName); DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL); } } { //拿到所有区划 string strQuery = string.Format("select t.r_code,t.r_name,t.r_pcode,t.r_level from {0} t where t.r_pcode is not null order by t.r_level", strTableName2); DataSet dtSet = DbHelperOra.Query(DbHelperOra.connectionString_Local, strQuery); DataTable dtTable = dtSet.Tables[0]; foreach (DataRow dr in dtTable.Rows) { iIndex++; //获取区划代码 string strBM = string.Format("{0}", dr[0]); if (strBM.Length < 6) { continue; } string strName = string.Format("{0}", dr[1]); string strPCODE = string.Format("{0}", dr[2]); string strRLEVEL = string.Format("{0}", dr[3]); csGovRegion csGR = new csGovRegion(strName, strBM, strPCODE); SetRegionInfo(csGR); if (csGR.RegionCenter != null) { if (strBM.Length > 0) { string strGUID = Guid.NewGuid().ToString("N").ToUpper(); string strCenter = JSONHelper.ObjectToJSON(csGR.RegionCenter.center); string strPoints = JSONHelper.ObjectToJSON(csGR.RegionBounds.bounds); string strSQL = string.Format("insert into {0}(ID,QHMC,QHBM,PID,CENTER,QHJB,VIEWBOUNDS) values('{1}','{2}','{3}','{4}','{5}',{6},empty_blob())", strTableName, strGUID, strName, strBM, strPCODE, strCenter, strRLEVEL); string strROWID = DbHelperOra.ExecuteOracleSql(DbHelperOra.connectionString_172, strSQL); string strFilter = string.Format("rowid = '{0}'", strROWID); DbHelperOra.RwiteRegionBoundsBlobToTable(DbHelperOra.connectionString_172, strTableName, "VIEWBOUNDS", strFilter, strPoints); } } } MessageBox.Show("入库完毕"); } } catch (SystemException sysEx) { string strErr = sysEx.Message; } }