Example #1
0
 public override void SaveTraceToDb()
 {
     LoggingService.Info("开始保存痕迹记录...");
     DBConnection connection = new DBConnection(base.SMDataSource);
     connection.Open();
     try
     {
         if (LoggingService.IsDebugEnabled)
         {
             LoggingService.DebugFormatted("共有修改或添加的痕迹记录:{0}条,删除记录:{1}条", new object[] { this.TraceTable.Rows.Count, (this._RecDelTable == null) ? 0 : this._RecDelTable.Rows.Count });
         }
         DbTransaction transaction = connection.BeginTrasaction() as DbTransaction;
         DbDataAdapter adapter = this.TraceTable.ExtendedProperties["da"] as DbDataAdapter;
         adapter.InsertCommand.Connection = connection.Connection as DbConnection;
         adapter.InsertCommand.Transaction = transaction;
         adapter.Update(this.TraceTable);
         if (TraceUtil.CanTraceLevel(TraceLevel.Deleted))
         {
             DbDataAdapter adapter2 = this._RecDelTable.ExtendedProperties["da"] as DbDataAdapter;
             adapter2.InsertCommand.Connection = connection.Connection as DbConnection;
             adapter2.InsertCommand.Transaction = transaction;
             adapter2.Update(this._RecDelTable);
         }
         connection.CommitTransaction();
     }
     catch (DbException exception)
     {
         connection.RollBackTransaction();
         string dataSetName = "TraceDb" + DateTimeHelper.GetNow().ToString();
         DataSet set = new DataSet(dataSetName);
         set.Tables.Add(this.TraceTable);
         set.Tables.Add(this._RecDelTable);
         set.WriteXml(Environment.CurrentDirectory + @"\" + dataSetName + ".xml");
         throw new DataFormException("数据修改日志记录保存不成功能(数据已成功能保存)!", exception);
     }
     finally
     {
         connection.Close();
         this.TraceTable.Rows.Clear();
         if (this._RecDelTable != null)
         {
             this._RecDelTable.Rows.Clear();
         }
     }
 }
Example #2
0
 public static void Delete(IDictionary<DAODataSet, string> deletes)
 {
     Exception exception;
     try
     {
         string str = string.Empty;
         DAODataSet key = null;
         List<string> list = new List<string>(deletes.Count);
         List<string> list2 = new List<string>(deletes.Count);
         foreach (KeyValuePair<DAODataSet, string> pair in deletes)
         {
             key = pair.Key;
             foreach (DAODataTable table in key.DAODataTables)
             {
                 str = str + "delete from " + table.Name + " where ";
                 if (table.Level)
                 {
                     str = str + table.RelKey;
                 }
                 else
                 {
                     str = str + table.Key;
                     list.Add(table.Name);
                     list2.Add(pair.Value.ToString().Replace("'", ""));
                 }
                 str = str + " in (" + pair.Value + ");\r";
             }
         }
         if (str != string.Empty)
         {
             DBConnection connection = new DBConnection(key.DataSource);
             connection.Open();
             IDbTransaction transaction = connection.BeginTrasaction();
             try
             {
                 IDbCommand command = connection.Connection.CreateCommand();
                 command.Transaction = transaction;
                 command.CommandText = str;
                 command.CommandType = CommandType.Text;
                 command.ExecuteNonQuery();
                 connection.CommitTransaction();
             }
             catch (Exception exception1)
             {
                 exception = exception1;
                 connection.RollBackTransaction();
                 throw exception;
             }
             finally
             {
                 connection.Close();
             }
             try
             {
                 ITraceDb traceDB = GetTraceDB(key.DataSource);
                 if (TraceUtil.CanTraceLevel(TraceLevel.Deleted) && (traceDB != null))
                 {
                     traceDB.TraceOuterRemove(list.ToArray(), list2.ToArray(), "经由系统(可能是前台工作流完全删除)操作删除进行的记录,注意它并没有对子表的删除进行记录.");
                     traceDB.SaveTraceToDb();
                 }
             }
             catch (Exception exception2)
             {
                 exception = exception2;
                 log.Error("进行删除的痕迹记录出错:", exception);
             }
         }
     }
     catch (Exception exception3)
     {
         exception = exception3;
         throw new DataFormException("delete data raise error!", exception);
     }
 }
Example #3
0
 private void SaveDataToSQlDB(SMDataSource smDS, ref DataTable dt)
 {
     DBConnection connection = new DBConnection(smDS);
     connection.Open();
     try
     {
         IDbTransaction transaction = connection.BeginTrasaction();
         DataTable dataTable = dt;
         if (dataTable.GetChanges() != null)
         {
             string strSelect = (string) dataTable.ExtendedProperties["selectsql"];
             DbDataAdapter adapter = connection.GetDataAdapter(strSelect, true, true, true);
             try
             {
                 adapter.Update(dataTable);
             }
             catch (DBConcurrencyException exception)
             {
                 throw new DataFormException(exception.Message, exception);
             }
         }
         connection.CommitTransaction();
     }
     catch (Exception exception2)
     {
         connection.RollBackTransaction();
         throw exception2;
     }
     finally
     {
         connection.Close();
     }
     dt = this.RefreshDataset(smDS, dt);
 }
Example #4
0
 private void SaveDataToSQlDB(SMDataSource smDS, ref DataSet ds)
 {
     int count = ds.Tables.Count;
     DBConnection connection = new DBConnection(smDS);
     connection.Open();
     string str = null;
     if (ds.ExtendedProperties.ContainsKey("CascadeSql"))
     {
         str = (string) ds.ExtendedProperties["CascadeSql"];
     }
     try
     {
         IDbTransaction transaction = connection.BeginTrasaction();
         for (int i = 0; i < count; i++)
         {
             DataTable dataTable = ds.Tables[i];
             if (dataTable.GetChanges() != null)
             {
                 string strSelect = (string) dataTable.ExtendedProperties["selectsql"];
                 DbDataAdapter adapter = connection.GetDataAdapter(strSelect, true, true, true);
                 try
                 {
                     adapter.Update(dataTable);
                 }
                 catch (DBConcurrencyException exception)
                 {
                     LoggingService.Error("数据可能被其他人修改了,不能保存...");
                     throw exception;
                 }
             }
         }
         connection.CommitTransaction();
         try
         {
             if (!string.IsNullOrEmpty(str))
             {
                 if (LoggingService.IsDebugEnabled)
                 {
                     LoggingService.DebugFormatted("将执行级联SQL:{0}", new object[] { str });
                 }
                 connection.ExecuteSql(str);
             }
         }
         catch (Exception exception2)
         {
             LoggingService.ErrorFormatted("执行级联更新语句:{0},发生错语:{1}\r\n{2}", new object[] { str, exception2.Message, exception2.StackTrace });
         }
     }
     catch (Exception exception3)
     {
         connection.RollBackTransaction();
         throw exception3;
     }
     finally
     {
         connection.Close();
     }
 }