/// <summary> /// 同步Oracle数据 /// </summary> /// <param name="dbORA">Oracle数据库连接</param> /// <param name="dbMDB">mdb数据库连接</param> /// <returns></returns> public static bool SynORA(DatabaseORC dbORA, DatabaseOledb dbMDB) { try { bool b = true; string mdbSQL = "select * from 采矿申请登记 where 签发时间 is not null"; DataTable dt = dbMDB.GetDataSet(mdbSQL).Tables[0]; DataRow dr = null; string oraSQL = string.Empty; string upSQL = string.Empty; #region 更新『采矿申请登记』表 for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; oraSQL = "select * from 采矿申请登记 where 项目档案号='" + dr["项目档案号"] + "' and 签发时间=to_date('" + dr["签发时间"] + "','yyyy-mm-dd hh24:mi:ss')"; DataSet ds = dbORA.GetDataSet(oraSQL); if (!(ds.Tables[0].Rows.Count > 0)) { upSQL = UpdateSQL(dr, "采矿申请登记"); dbORA.ExecuteSql(upSQL); } } #endregion #region 更新『项目档案』表 mdbSQL = "select * from 项目档案 where 签发时间 is not null"; dt = dbMDB.GetDataSet(mdbSQL).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; //oraSQL = "select * from 采矿申请登记 where 项目档案号='" + dr["项目档案号"] + "' and 签发时间 is not null and to_char(签发时间,'yyyy-mm-dd,hh:mi:ss')='" + dr["签发时间"] + "'"; oraSQL = "select * from 项目档案 where 项目档案号='" + dr["项目档案号"] + "' and 签发时间=to_date('" + dr["签发时间"] + "','yyyy-mm-dd hh24:mi:ss')"; DataSet ds = dbORA.GetDataSet(oraSQL); if (!(ds.Tables[0].Rows.Count > 0)) { upSQL = UpdateSQL(dr, "项目档案"); dbORA.ExecuteSql(upSQL); } } #endregion return(b); } catch (Exception ex) { Log.WriteLog("SynORA同步错误>>>>" + ex.Message); errorMsg = "同步MapGIS一张图数据库时出错,请检查相关配置信息!"; return(false); throw ex; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_MDBDbTest_Click(object sender, EventArgs e) { try { string sMessage = ""; bool b = DatabaseOledb.TestAccessConn(txt_MDB_DBPATH.Text, ref sMessage); if (b) { MessageBox.Show(sMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(sMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 同步图形中的CKSQDJ图层数据 /// </summary> /// <param name="dbMDB">MDB数据库对象</param> /// <param name="IGSUri">IGS服务地址</param> /// <returns></returns> public static bool SynIGS(DatabaseOledb dbMDB, string IGSUri) { try { bool b = true; //CM.Map.Feature f = new CM.Map.Feature("http://" + IGSUri + "/IGSLandService/Feature.asmx"); WebFeature.Feature f = new WebFeature.Feature(); f.Url = "http://" + IGSUri + "/IGSLandService/Feature.asmx";; string mdbSQL = "select * from 采矿申请登记 where 签发时间 is not null"; DataTable dt = new DataTable(); #region 判断是否查询到数据,若未查询到数据则不需要进行后面的判断 if (dbMDB.GetDataSet(mdbSQL).Tables.Count > 0) { try { dt = dbMDB.GetDataSet(mdbSQL).Tables[0]; DebugInfo("查询到数据"); } catch (Exception ex) { errorMsg = "同步错误,请检查采矿权数据库设置!"; return(false); throw ex; } } else { errorMsg = "同步错误,采矿权数据库(MDB)中未查询到数据!"; return(false); } #endregion DataRow dr = null; #region 遍历采矿申请登记表,更新采矿权图层 for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; try { b = UpdateFeature(f, dr) && b; //Log.WriteLog(string.Format(b.ToString() + "循环第{0}次", i + 1)); if (!b) { DebugInfo("UpdateFeature()失败!"); return(b); } //else // continue; } catch (Exception ex) { Log.WriteLog("UpdateFeature()>>>>" + ex.Message); return(false); throw ex; } } #endregion #region 查询项目档案中已注销矿权信息 #region 重新初始化数据对象 mdbSQL = string.Empty; dt = null; dr = null; #endregion mdbSQL = "select * from 项目档案 where 项目类型=1070"; if (dbMDB.GetDataSet(mdbSQL).Tables.Count > 0) { try { //Log.WriteLog(mdbSQL); dt = dbMDB.GetDataSet(mdbSQL).Tables[0]; } catch (Exception ex) { errorMsg = "同步错误,请检查采矿权数据库设置!"; return(false); throw ex; } } else { b = b && true; } #endregion #region 遍历项目档案登记表,删除已注销矿权 for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; try { b = DelFeature(f, dr) && b; //Log.WriteLog(string.Format("DelFeature()>>>>"+b.ToString() + "循环第{0}次", i + 1)); if (!b) { return(b); } //else // continue; } catch (Exception ex) { Log.WriteLog("DelFeature()>>>>" + ex.Message); return(false); throw ex; } } #endregion return(b); } catch (Exception ex) { Log.WriteLog("SynIGS错误>>>>" + ex.Message); errorMsg = "同步图形错误!"; return(false); throw ex; } }
private void SyncData() { try { DialogResult ret = MessageBox.Show("同步之前请检查、测试各项设置并保存!", "注意", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (ret == DialogResult.Yes) { //Log.WriteDebug("确认"); //Log.WriteLog("确认"); DatabaseOledb dbMDB = new DatabaseOledb(Config.GetConfigValue("MDB_ConnectString"));//MDB连接 #region Oracle连接串StringBuilder ora_Conn StringBuilder ora_Conn = new StringBuilder("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST="); ora_Conn.Append(Config.GetConfigValue("OA_DBIP")); ora_Conn.Append(")(PORT="); ora_Conn.Append(Config.GetConfigValue("OA_DBPort")); ora_Conn.Append(")))(CONNECT_DATA=(SERVICE_NAME="); ora_Conn.Append(Config.GetConfigValue("OA_DBName")); ora_Conn.Append(")));User Id="); ora_Conn.Append(Config.GetConfigValue("OA_DBUserName")); ora_Conn.Append(";Password="******"OA_DBPassword")); ora_Conn.Append(";"); #endregion DatabaseORC dbORA = new DatabaseORC(ora_Conn.ToString()); #region 步数据 string IGSUri = Config.GetConfigValue("IGS_PATH"); #region MDBSyn=false if (Config.GetConfigValue("MDBSyn") == "false") { MessageBox.Show("请检查采矿权数据库配置并保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } #endregion #region OASyn=true else if (Config.GetConfigValue("OASyn") == "true") { #region OASyn/IGSSyn都为true if (Config.GetConfigValue("IGSSyn") == "true") { if (Sync.SynORA(dbORA, dbMDB) && Sync.SynIGS(dbMDB, IGSUri)) { MessageBox.Show("成功!", "同步成功", MessageBoxButtons.OK, MessageBoxIcon.None); return; } else { MessageBox.Show(Sync.errorMsg.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } #endregion #region IGSSyn为false else { if (Sync.SynORA(dbORA, dbMDB)) { MessageBox.Show("成功!", "同步成功", MessageBoxButtons.OK, MessageBoxIcon.None); return; } else { MessageBox.Show(Sync.errorMsg.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } #endregion } #endregion #region OASyn=false/IGSSyn=true else if (Config.GetConfigValue("IGSSyn") == "true") { if (Sync.SynIGS(dbMDB, IGSUri)) { MessageBox.Show("成功!", "同步成功", MessageBoxButtons.OK, MessageBoxIcon.None); return; } else { MessageBox.Show("图形同步失败,请检查配置并保存!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); //Log.WriteLog("IGSSyn错误『OASyn=false/IGSSyn=true』>>>>" + errorMsg); return; } } #endregion #region MDBSyn=true&&OASyn=false&&IGSSyn=false else { MessageBox.Show("请检查MapGIS一张图政务/图形同步设置并保存!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Question); return; } #endregion #endregion } } catch (Exception ex) { throw ex; } }