//清空日志 public static void ClearLog(ListView lv) { if (m_sysTable == null) { return; } Exception err; ITable pTable = m_sysTable.OpenTable(m_LogNAME, out err); if (pTable == null) { MessageBox.Show(err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return;//若日志表不存在,返回null } //for (int i = 0; i < lv.Items.Count;i++ ) //{ // ListViewItem lvi = lv.Items[i]; // IQueryFilter pQF = new QueryFilterClass(); // pQF.WhereClause = "logTime = '" + lvi.SubItems[0].Text // + "' AND logUser = '******' AND logIP = '" + lvi.SubItems[1].Text // + "' AND logEVENT = '" + lvi.SubItems[3].Text+"'"; IWorkspace pWorkspace = m_gisDb.WorkSpace; ITransactions pTransactions = (ITransactions)pWorkspace; try { if (!pTransactions.InTransaction) { pTransactions.StartTransaction(); } } catch (Exception eX) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eX.Message); return; } Exception exError; if (!m_sysTable.DeleteRows(m_LogNAME, "", out exError)) { ErrorHandle.ShowFrmErrorHandle("提示", "清空日志失败!" + exError.Message); return; } try { if (pTransactions.InTransaction) { pTransactions.CommitTransaction(); } } catch (Exception eX) { } //} }
private void buttonOK_Click(object sender, EventArgs e) { Exception exError = null; ITransactions pTransactions = null; //保存查询配置文件(由本地向数据库保存) try { IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass(); pBlobStream.LoadFromFile(_QueryConfigPath); //启动事务 pTransactions = (ITransactions)_TmpWorkSpace; if (!pTransactions.InTransaction) { pTransactions.StartTransaction(); } SysGisTable sysTable = new SysGisTable(_TmpWorkSpace); Dictionary <string, object> dicData = new Dictionary <string, object>(); dicData.Add("SETTINGVALUE2", pBlobStream); dicData.Add("SETTINGNAME", "统计配置"); //判断是更新还是添加 //不存在则添加,已存在则更新 if (!sysTable.ExistData("SYSSETTING", "SETTINGNAME='统计配置'")) { if (!sysTable.NewRow("SYSSETTING", dicData, out exError)) { MessageBox.Show(exError.Message); return; } } else { if (!sysTable.UpdateRow("SYSSETTING", "SETTINGNAME='统计配置'", dicData, out exError)) { MessageBox.Show(exError.Message); return; } } //提交事务 if (pTransactions.InTransaction) { pTransactions.CommitTransaction(); } } catch (Exception ex) { //出错则放弃提交 if (pTransactions.InTransaction) { pTransactions.AbortTransaction(); } MessageBox.Show(exError.Message); return; } this.DialogResult = DialogResult.OK; }
public void StartTransaction() { ITransactions workspace = (this.itable_0 as IDataset).Workspace as IWorkspaceEdit as ITransactions; if (workspace != null && !workspace.InTransaction) { workspace.StartTransaction(); } }
//删除记录菜单响应 public override void OnClick() { if (m_Hook.GridCtrl == null) { return; } FaceControl pfacecontrol = (FaceControl)m_Hook.MainUserControl; DataGridView pGridControl = m_Hook.GridCtrl; if (pfacecontrol.getEditable() == false) { return; } string connstr, Tablename; //获取数据库连接串和表名 connstr = pfacecontrol.m_connstr; Tablename = pfacecontrol.m_TableName; if (Tablename.Contains(".")) { Tablename = Tablename.Split('.')[1];//处理SDE表 } FaceControl pFaceControl = (FaceControl)(m_Hook.MainUserControl); if (pGridControl.DataSource == null) { return; } //如果未选中记录... if (pGridControl.SelectedRows.Count == 0) { DevComponents.DotNetBar.MessageBoxEx.Show("未选中记录!"); return; } int k = pGridControl.SelectedRows.Count; //删除数据时,要询问一次 if (pGridControl.SelectedRows.Count > 0) { if (DevComponents.DotNetBar.MessageBoxEx.Show("确定要删除选中的记录吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } //OleDbConnection mycon = new OleDbConnection(connstr); //定义OleDbConnection对象实例并连接数据库 //string strExp = ""; //OleDbCommand aCommand = new OleDbCommand(strExp, mycon); //mycon.Open(); //int i = 0, j = 0; if (GeoDataCenterFunLib.LogTable.m_sysTable == null) { return; } Exception err; ITable pTable = LogTable.m_sysTable.OpenTable(Tablename, out err); if (pTable == null) { //MessageBox.Show(err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); ErrorHandle.ShowFrmErrorHandle("提示", err.Message); return;//若日志表不存在,返回null } if (pGridControl.SelectedRows.Count > 0) { string objectID = pTable.OIDFieldName; string strExp = objectID + " IN ("; for (int h = 0; h < pGridControl.SelectedRows.Count; h++) { //构造删除记录的语句 for (int i = 0; i < pGridControl.ColumnCount; i++) { if (pGridControl.Columns[i].Name.ToUpper().Equals("ID")) { strExp += pGridControl.SelectedRows[h].Cells[i].Value.ToString() + ","; } } } strExp = strExp.Substring(0, strExp.Length - 1); strExp += ")"; //执行删除记录的语句段 IWorkspace pWorkspace = LogTable.m_gisDb.WorkSpace; ITransactions pTransactions = (ITransactions)pWorkspace; try { if (!pTransactions.InTransaction) { pTransactions.StartTransaction(); } } catch (Exception eX) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eX.Message); return; } Exception exError; if (!LogTable.m_sysTable.DeleteRows(Tablename, strExp, out exError)) { ErrorHandle.ShowFrmErrorHandle("提示", "删除记录失败!" + exError.Message); return; } try { if (pTransactions.InTransaction) { pTransactions.CommitTransaction(); } } catch (Exception eX) { } } //再次初始化datagridview控件 pfacecontrol.InitDataInfoList(Tablename); ////ZQ 20111017 add 及时更新数据字典 switch (Tablename) { case "属性对照表": SysCommon.ModField.InitNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicFieldName, "属性对照表"); break; case "标准图层代码表": SysCommon.ModField.InitLayerNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicLayerName); break; //default: // ///ZQ 20111020 add 增加重启提示 // MessageBox.Show("删除的记录只有应用系统重启以后才能生效!", "提示!"); // break; } ///// if (this.WriteLog) { Plugin.LogTable.Writelog(Caption);//xisheng 2011.07.09 增加日志 } /* Exception eError; * AddGroup frmGroup = new AddGroup(); * if (frmGroup.ShowDialog() == DialogResult.OK) * { * ModuleOperator.DisplayRoleTree("", m_Hook.RoleTree, ref ModData.gisDb, out eError); * if (eError != null) * { * ErrorHandle.ShowFrmError("提示", eError.Message); * return; * } * } */ }
public long unversionedEdit(IQueryFilter qFilterGen, int sequenceColumnNum, int idxSeqField, int curLoop, ref ITransactions transactions) { long sequenceValue = -1; using (ComReleaser comReleaser = new ComReleaser()) { if (AAState._gentabWorkspace.IsInEditOperation) { // throw new Exception("Cannot use ITransactions during an edit operation."); } // Begin a transaction. if (transactions == null) { transactions = (ITransactions)AAState._gentabWorkspace; } transactions.StartTransaction(); try { // Use ITable.Update to create an update cursor. ICursor seq_updateCursor = AAState._gentab.Update(qFilterGen, true); comReleaser.ManageLifetime(seq_updateCursor); IRow seq_row = null; seq_row = seq_updateCursor.NextRow(); int sequenceInt = 1; if (seq_row != null) { if (idxSeqField > 0) { object seqInt = seq_row.get_Value(idxSeqField); if (seqInt != null) { if (seqInt != DBNull.Value) try { sequenceInt = Convert.ToInt32(seqInt); } catch { } } } object seqValue = seq_row.get_Value(sequenceColumnNum); if (seqValue == null) { sequenceValue = 0; } else if (seqValue.ToString() == "") { sequenceValue = 0; } else try { sequenceValue = Convert.ToInt64(seqValue); } catch { sequenceValue = 0; } AAState.WriteLine(" " + sequenceValue + " is the existing value and the interval is " + sequenceInt + ": " + DateTime.Now.ToString("h:mm:ss tt")); sequenceValue = sequenceValue + sequenceInt; seq_row.set_Value(sequenceColumnNum, sequenceValue); AAState.WriteLine(" " + seq_row.Fields.get_Field(sequenceColumnNum).AliasName + " changed to " + sequenceValue + ": " + DateTime.Now.ToString("h:mm:ss tt")); seq_updateCursor.UpdateRow(seq_row); transactions.CommitTransaction(); seq_updateCursor = AAState._gentab.Search(qFilter, true); if (seq_row != null) { seqValue = seq_row.get_Value(sequenceColumnNum); if (seqValue == null) { return sequenceValue; } else if (seqValue.ToString() == "") { return sequenceValue; } else try { if (sequenceValue == Convert.ToInt64(seqValue)) { return sequenceValue; } else { if (curLoop > 30) { MessageBox.Show("A unique ID could not be generated after 30 attempts: " + DateTime.Now.ToString("h:mm:ss tt")); } else { return unversionedEdit(qFilterGen, sequenceColumnNum, idxSeqField, curLoop + 1, ref transactions); } } } catch { return sequenceValue; } } return sequenceValue; } else { AAState.WriteLine(" No records found in Generate ID table" + ": " + DateTime.Now.ToString("h:mm:ss tt")); transactions.AbortTransaction(); return -1; } } catch (COMException comExc) { AAState.WriteLine(" Error saving transaction to DB" + ": " + DateTime.Now.ToString("h:mm:ss tt")); // If an error occurs during the inserts and updates, rollback the transaction. transactions.AbortTransaction(); return -1; } } }
//本地向数据库保存图层目录 private bool ImportEagleEyset(IWorkspace pWorkspace, string strPath) { //判断各个参数是否有效 if (pWorkspace == null) { return(false); } Exception exError = null; ITransactions pTransactions = null; //保存图层树(由本地向数据库保存) try { IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass(); ///读取路径下的mxd文件 // System.IO.FileStream pFileStream = File.Create(strPath); //if (pFileStream == null) { return false; } // byte[] bytes = new byte[pFileStream.Length]; // pBlobStream.ImportFromMemory(ref bytes[0], (uint)bytes.GetLength(0)); // pFileStream.Close(); // pFileStream.Dispose(); ///读取路径下的mxd文件转化成MemoryBlobStreamClass pBlobStream.LoadFromFile(strPath); //启动事务 pTransactions = (ITransactions)pWorkspace; if (!pTransactions.InTransaction) { pTransactions.StartTransaction(); } SysGisTable sysTable = new SysGisTable(pWorkspace); Dictionary <string, object> dicData = new Dictionary <string, object>(); dicData.Add("SETTINGVALUE2", pBlobStream); dicData.Add("SETTINGNAME", "鹰眼图"); //判断是更新还是添加 //不存在则添加,已存在则更新 if (!sysTable.ExistData("SYSSETTING", "SETTINGNAME='鹰眼图'")) { if (!sysTable.NewRow("SYSSETTING", dicData, out exError)) { ErrorHandle.ShowFrmErrorHandle("提示", "添加失败!"); return(false); } } else { if (!sysTable.UpdateRow("SYSSETTING", "SETTINGNAME='鹰眼图'", dicData, out exError)) { ErrorHandle.ShowFrmErrorHandle("提示", "更新失败!"); return(false); } } //提交事务 if (pTransactions.InTransaction) { pTransactions.CommitTransaction(); } return(true); } catch (Exception ex) { //出错则放弃提交 if (pTransactions.InTransaction) { pTransactions.AbortTransaction(); } ErrorHandle.ShowFrmErrorHandle("提示", "更新失败!"); return(false); } }
/// <summary> /// 记录一个要素的编辑信息(针对删除) guozheng added /// </summary> /// <param name="in_OID">删除要素的OID</param> /// <param name="in_DateTime">编辑的时间</param> /// <param name="in_iVersion">版本</param> /// <param name="in_sLayerName">要素所在的图层名</param> /// <param name="ex"></param> private static void RecordLOG(IWorkspace pSDEWS, int in_OID, DateTime in_DateTime, int in_iVersion, string in_sLayerName, out Exception ex) { ex = null; if (in_DateTime == null) { ex = new Exception("输入的编辑时间为空"); return; } ///////////////获取必要信息///////////////// //////去掉sde图层带的用户名 if (in_sLayerName.Contains(".")) { in_sLayerName = in_sLayerName.Substring(in_sLayerName.LastIndexOf('.') + 1); } int iOID = in_OID; /////////////////////////////要素OID string sLayerName = string.Empty; //////////要素图层名 int iVersion = -1; /////////////////////////版本信息 sLayerName = in_sLayerName; iVersion = in_iVersion;/////////////获取版本 if (ex != null) { return; } //////////////////写入日志//////////////////////////// try { ITransactions LOGTran = pSDEWS as ITransactions; LOGTran.StartTransaction(); ////////写入更新日志表/////// WriteLog(pSDEWS, iOID, sLayerName, iVersion, in_DateTime, 3, null, out ex); if (ex != null) { LOGTran.AbortTransaction(); return; } ////////写入数据库版本表///// //WriteDBVersion(iVersion, in_DateTime, this.m_Con, out ex); //if (ex != null) { myTrans.Rollback(); } ///////修改过程库//////////// //WriteHisDB(sLayerName, this.m_HisWS, null, in_DateTime, 3, iVersion, out ex); WriteHisDB(sLayerName, pSDEWS, in_OID, in_DateTime, in_iVersion, out ex); if (ex != null) { LOGTran.AbortTransaction(); return; } LOGTran.CommitTransaction(); } catch (Exception eError) { //******************************************************************* //Exception Log if (ModData.SysLog == null) { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); } ModData.SysLog.Write(eError, null, DateTime.Now); //******************************************************************** ex = new Exception("编辑要素记录失败。\n原因:" + eError.Message); return; } }
//写日志 传提示框重载 added by xisheng 2011.07.08 public static void Writelog(string logstr, RichTextBox richtextbox) { if (!CreateLogTable()) { return; } Dictionary <string, object> dicData = new Dictionary <string, object>(); string strHostName = Dns.GetHostName(); //得到本机的主机名 IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP string timestr = ""; switch (Mod.dbType) { case "SDE": string connstr = "Provider=OraOLEDB.Oracle;Data Source=" + Mod.Database + ";User Id=" + Mod.User + ";Password="******";OLEDB.NET=True;"; OleDbConnection pConn = new OleDbConnection(connstr); pConn.Open(); OleDbCommand pCommand = pConn.CreateCommand(); OleDbDataReader pReader = GetReader(pConn, "SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:Mi:SS') FROM dual"); if (pReader.Read()) { timestr = pReader.GetValue(0).ToString(); } pReader.Close(); pConn.Close(); break; default: timestr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); break; } //SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:Mi:SS') FROM dual dicData.Add("logTime", timestr); dicData.Add("logUser", user); dicData.Add("logIP", ipEntry.AddressList[0].ToString()); dicData.Add("logEVENT", logstr); if (richtextbox != null) { richtextbox.AppendText(timestr + "/当前用户:" + user + "/在进行-->" + logstr + "\r\n"); } IWorkspace pWorkspace = m_gisDb.WorkSpace; ITransactions pTransactions = (ITransactions)pWorkspace; try { if (!pTransactions.InTransaction) { pTransactions.StartTransaction(); } } catch (Exception eX) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eX.Message); return; } Exception exError; if (!m_sysTable.NewRow(m_LogNAME, dicData, out exError)) { ErrorHandle.ShowFrmErrorHandle("提示", "添加失败!" + exError.Message); return; } try { if (pTransactions.InTransaction) { pTransactions.CommitTransaction(); } } catch (Exception eX) { } }
public long unversionedEdit(IQueryFilter qFilterGen, int sequenceColumnNum, int idxSeqField, int curLoop, ref ITransactions transactions) { long sequenceValue = -1; using (ComReleaser comReleaser = new ComReleaser()) { if (AAState._gentabWorkspace.IsInEditOperation) { // throw new Exception("Cannot use ITransactions during an edit operation."); } // Begin a transaction. if (transactions == null) { transactions = (ITransactions)AAState._gentabWorkspace; } transactions.StartTransaction(); try { // Use ITable.Update to create an update cursor. ICursor seq_updateCursor = AAState._gentab.Update(qFilterGen, true); comReleaser.ManageLifetime(seq_updateCursor); IRow seq_row = null; seq_row = seq_updateCursor.NextRow(); int sequenceInt = 1; if (seq_row != null) { if (idxSeqField > 0) { object seqInt = seq_row.get_Value(idxSeqField); if (seqInt != null) { if (seqInt != DBNull.Value) { try { sequenceInt = Convert.ToInt32(seqInt); } catch { } } } } object seqValue = seq_row.get_Value(sequenceColumnNum); if (seqValue == null) { sequenceValue = 0; } else if (seqValue.ToString() == "") { sequenceValue = 0; } else { try { sequenceValue = Convert.ToInt64(seqValue); } catch { sequenceValue = 0; } } AAState.WriteLine(" " + sequenceValue + " is the existing value and the interval is " + sequenceInt + ": " + DateTime.Now.ToString("h:mm:ss tt")); sequenceValue = sequenceValue + sequenceInt; seq_row.set_Value(sequenceColumnNum, sequenceValue); AAState.WriteLine(" " + seq_row.Fields.get_Field(sequenceColumnNum).AliasName + " changed to " + sequenceValue + ": " + DateTime.Now.ToString("h:mm:ss tt")); seq_updateCursor.UpdateRow(seq_row); transactions.CommitTransaction(); seq_updateCursor = AAState._gentab.Search(qFilter, true); if (seq_row != null) { seqValue = seq_row.get_Value(sequenceColumnNum); if (seqValue == null) { return(sequenceValue); } else if (seqValue.ToString() == "") { return(sequenceValue); } else { try { if (sequenceValue == Convert.ToInt64(seqValue)) { return(sequenceValue); } else { if (curLoop > 30) { MessageBox.Show("A unique ID could not be generated after 30 attempts: " + DateTime.Now.ToString("h:mm:ss tt")); } else { return(unversionedEdit(qFilterGen, sequenceColumnNum, idxSeqField, curLoop + 1, ref transactions)); } } } catch { return(sequenceValue); } } } return(sequenceValue); } else { AAState.WriteLine(" No records found in Generate ID table" + ": " + DateTime.Now.ToString("h:mm:ss tt")); transactions.AbortTransaction(); return(-1); } } catch (COMException comExc) { AAState.WriteLine(" Error saving transaction to DB" + ": " + DateTime.Now.ToString("h:mm:ss tt")); // If an error occurs during the inserts and updates, rollback the transaction. transactions.AbortTransaction(); return(-1); } } }
/// <summary> /// 记录一个要素的编辑信息 /// </summary> /// <param name="in_Row">编辑要素的IRow</param> /// <param name="in_iState">编辑状态:1、新增,2、修改,3、删除</param> /// <param name="in_DateTime">编辑的时间</param> /// <param name="in_iVersion">版本</param> /// <param name="in_sLayerName">要素所在的图层名</param> /// <param name="ex"></param> public void RecordLOG(IRow in_Row, int in_iState, DateTime in_DateTime, int in_iVersion, string in_sLayerName, out Exception ex) { ex = null; if (in_Row == null) { ex = new Exception("输入要素为空"); return; } if (in_DateTime == null) { ex = new Exception("输入的编辑时间为空"); return; } IFeature getFea = in_Row as IFeature; if (getFea == null) { ex = new Exception("获取要素失败"); return; } ///////////////获取必要信息///////////////// //////去掉sde图层带的用户名 if (in_sLayerName.Contains(".")) { in_sLayerName = in_sLayerName.Substring(in_sLayerName.LastIndexOf('.') + 1); } int iOID = -1; /////////////////////////////要素OID string sLayerName = string.Empty; //////////要素图层名 int iVersion = -1; /////////////////////////版本信息 if (getFea.HasOID) { iOID = getFea.OID; } sLayerName = in_sLayerName; iVersion = in_iVersion;/////////////获取版本 if (ex != null) { return; } //////////////////写入日志//////////////////////////// try { ITransactions LOGTran = this.m_HisWS as ITransactions; LOGTran.StartTransaction(); ////////写入更新日志表/////// WriteLog(iOID, sLayerName, iVersion, in_DateTime, in_iState, getFea.Shape.Envelope, out ex); if (ex != null) { LOGTran.AbortTransaction(); return; } ////////写入数据库版本表///// //WriteDBVersion(iVersion, in_DateTime, this.m_Con, out ex); //if (ex != null) { myTrans.Rollback(); } ///////修改过程库//////////// WriteHisDB(sLayerName, this.m_HisWS, getFea, in_DateTime, in_iState, iVersion, out ex); if (ex != null) { LOGTran.AbortTransaction(); return; } LOGTran.CommitTransaction(); } catch (Exception eError) { //****************************************** //guozheng added System Exception log if (SysCommon.Log.Module.SysLog == null) { SysCommon.Log.Module.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); } SysCommon.Log.Module.SysLog.Write(eError); //****************************************** ex = eError; return; } }