123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using ESRI.ArcGIS.esriSystem;
- using ESRI.ArcGIS.Geodatabase;
- using ESRI.ArcGIS.DataManagementTools;
- namespace FindIdentical.Win
- {
- public partial class FormFindIdentical : Form
- {
-
-
-
- private string _strLastExcuteDate = "";
- private System.Object thisLock = new System.Object();
- private List<string> _lstIdenticalName = new List<string>() {"BOOSTER_FindIdentical", "BOOSTER_GW_FindIdentical", "PIPESECTION_FindIdentical", "PIPESECTION_GW_FindIdentical" };
- private int _excuteDateEnum = 6;
-
-
-
- private IWorkspace _wsProcessing;
- public FormFindIdentical()
- {
- InitializeComponent();
- }
- private void FormTrayCompress_Load(object sender, EventArgs e)
- {
- this.timerMonitor.Interval = 1 * 10 * 1000;
- this.tsbtnStartService.Enabled = true;
- this.tsbtnStopService.Enabled = false;
- string _identicalName = ConfigurationManager.AppSettings["DataName"];
- _lstIdenticalName = _identicalName.Split(',').ToList();
- _excuteDateEnum = Convert.ToInt32(ConfigurationManager.AppSettings["RunDate"]);
- }
- private void TimerMonitor_Tick(object sender, EventArgs e)
- {
- try
- {
- DateTime __dtimeNow = DateTime.Now;
- string __strCompressStartTime = ConfigurationManager.AppSettings["CompressStartTime"];
- if (string.IsNullOrEmpty(__strCompressStartTime))
- {
- throw new System.Exception("未读取到有效起始时间.");
- }
- DateTime __dtimeMin = Convert.ToDateTime(string.Format("{0} {1}", __dtimeNow.ToString("yyyy-MM-dd"), __strCompressStartTime));
- DateTime __dtimeMax = __dtimeMin.AddHours(1.0);
- if (__dtimeNow > __dtimeMin && __dtimeNow < __dtimeMax && __dtimeNow.DayOfWeek == (DayOfWeek)_excuteDateEnum)
- {
- if (__dtimeNow.ToString("yyyy-MM-dd") == this._strLastExcuteDate)
- {
- return;
- }
- this.timerMonitor.Stop();
- this.ShowProcessMesssage("开始进行查找重复数据……");
- this._strLastExcuteDate = __dtimeNow.ToString("yyyy-MM-dd");
- string __strServer = ConfigurationManager.AppSettings["ServerName"];
- string __strService = @"sde:oracle11g:" + ConfigurationManager.AppSettings["ServerName"];
- string __strDataBase = ConfigurationManager.AppSettings["DatabaseName"];
- string __strVersion = ConfigurationManager.AppSettings["DataVersion"];
- string __strSDEUser = ConfigurationManager.AppSettings["SDEUser"];
- string __strPassword = ConfigurationManager.AppSettings["Password"];
- string __strConnection = ConfigurationManager.AppSettings["ConnectionStr"];
- this._wsProcessing = ConnectToTransactionalVersion(__strServer, __strService, __strSDEUser, __strPassword, __strDataBase, "SDE.DEFAULT");
- for (int i = 0; i < _lstIdenticalName.Count; i++)
- {
- string _identicalName = _lstIdenticalName[i];
- try
- {
- ITable _table = (_wsProcessing as IFeatureWorkspace).OpenTable(_identicalName);
- if (_table is IDataset && (_table as IDataset).CanDelete())
- {
- (_table as IDataset).Delete();
- }
- }
- catch { }
-
-
- ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
- ESRI.ArcGIS.DataManagementTools.FindIdentical _findIdentical = new ESRI.ArcGIS.DataManagementTools.FindIdentical();
- _findIdentical.in_dataset = __strConnection + string.Format(@"{0}.GASDATASET\{0}.{1}", __strSDEUser, _identicalName.Replace("_FindIdentical", ""));
- _findIdentical.out_dataset = __strConnection + string.Format(@"{0}.{1}", __strSDEUser, _identicalName);
- _findIdentical.fields = "SHAPE";
- _findIdentical.output_record_option = "true";
- _findIdentical.z_tolerance = 0;
- gp.Execute(_findIdentical, null);
- }
- Marshal.FinalReleaseComObject(_wsProcessing);
- _wsProcessing = null;
- GC.Collect();
- CreateIdentifyFile();
- this.ShowProcessMesssage("完成查找重复数据.");
- this.ShowProcessMesssage("");
- this.timerMonitor.Start();
- }
- }
- catch (System.Exception ex)
- {
- this._strLastExcuteDate = "";
- this.timerMonitor.Start();
- this.ShowProcessMesssage(ex.Message);
- }
- }
- private void tsbtnStartService_Click(object sender, EventArgs e)
- {
- this._strLastExcuteDate = "";
- this.timerMonitor.Start();
- this.tsbtnStartService.Enabled = false;
- this.tsbtnStopService.Enabled = true;
- this.ShowProcessMesssage("成功启动查找重复数据服务……");
- }
- private void tsbtnStopService_Click(object sender, EventArgs e)
- {
- this._strLastExcuteDate = "";
- this.timerMonitor.Stop();
- this.tsbtnStartService.Enabled = true;
- this.tsbtnStopService.Enabled = false;
- this.ShowProcessMesssage("成功停止查找重复数据服务……");
- }
- private void tsbtnExit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void notifyIconCompress_DoubleClick(object sender, EventArgs e)
- {
- if (this.WindowState == System.Windows.Forms.FormWindowState.Minimized)
- {
- this.WindowState = System.Windows.Forms.FormWindowState.Normal;
-
- }
- }
- private void FormTrayCompress_SizeChanged(object sender, EventArgs e)
- {
- this.ShowInTaskbar = (this.WindowState != System.Windows.Forms.FormWindowState.Minimized);
- }
-
-
-
-
- private void ShowProcessMesssage(string message)
- {
- if (string.IsNullOrEmpty(message) == false)
- {
- this.lboxMessage.Items.Add(string.Format("{0} {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), message));
- }
- else
- {
- this.lboxMessage.Items.Add(message);
- }
- this.lboxMessage.TopIndex = this.lboxMessage.Items.Count - 1;
- }
- private IWorkspace ConnectToTransactionalVersion(string server, string instance, string user, string password, string database, string version)
- {
- IPropertySet propertySet = new PropertySet();
- propertySet.SetProperty("SERVER", server);
- propertySet.SetProperty("INSTANCE", instance);
- propertySet.SetProperty("DATABASE", database);
- propertySet.SetProperty("USER", user);
- propertySet.SetProperty("PASSWORD", password);
- propertySet.SetProperty("VERSION", version);
- Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
- IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
- return workspaceFactory.Open(propertySet, 0);
- }
- private void CreateIdentifyFile()
- {
- lock (thisLock)
- {
- string __strIdentifyLogFolder = string.Format(@"{0}\Log", Application.StartupPath);
- if (Directory.Exists(__strIdentifyLogFolder) == false)
- {
- Directory.CreateDirectory(__strIdentifyLogFolder);
- }
- string __strIdentifyFile = string.Format(@"{0}\FindIdenticalSuccess{1}.idf", __strIdentifyLogFolder, DateTime.Now.ToString("yyyyMMdd"));
- File.Create(__strIdentifyFile);
- Application.DoEvents();
- }
- }
- }
- }
|