C#下ArcSDE(Oracle)图层数据变化监控实现

因业务需要对ArcSDE中单个图层的变化进行监控,在出现图形插入、删除,图形和属性修改时及时获取到发生变化的要素。

研究了一下可以通过C#进行监控。

核心代码如下:

string sqlSelect = "select TBID, TBBH, st_astext(shape) as shp  from YSWFTB_2000 ";
OracleConnection con = new OracleConnection(constr);
OracleCommand cmd = new OracleCommand(sql, con);
con.Open();

cmd.AddRowid = true;
OracleDependency dep = new OracleDependency(cmd);
cmd.Notification.IsNotifiedOnce = false;
//是否在一次Notification后立即移除此次注册
cmd.Notification.IsNotifiedOnce = false;
//此次注册的超时时间(秒),超过此时间,注册将被自动移除。0表示不超时。
cmd.Notification.Timeout = 0;
//False表示Notification将被存于内存中,True表示存于数据库中,选择True可以保证即便数据库重启之后,消息仍然不会丢失
cmd.Notification.IsPersistent = true;

dep.OnChange += new OnChangeEventHandler(OnMyNotificaton);


public void OnMyNotificaton(object src, OracleNotificationEventArgs args) 
{
            
            if (args.Info == OracleNotificationInfo.Insert)
            {
                DataTable changeDetails = args.Details;
                 MessageBox.Show("要素插入.", "Notification Alert",
                 MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (args.Info == OracleNotificationInfo.Update)
            {
                MessageBox.Show("要素修改", "变化监控",
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            else if (args.Info == OracleNotificationInfo.Delete)
            {
                MessageBox.Show("要素删除", "变化监控",
              MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

}

  

posted @ 2023-01-06 09:55  伸手不见五趾  阅读(64)  评论(0编辑  收藏  举报