/// <summary> /// 执行事务 /// </summary> /// <param name="accessParameter">数据层参数对象</param> /// <returns>成功则返回True,失败则返回False</returns> public bool RunTransaction(AccessParameter accessParameter) { Hashtable[] parms = null; return(DataBuilder.GetDBOperate(m_dbName) .RunTransaction(accessParameter.StoredProcedures, accessParameter.StoredParams, ref parms)); }
/// <summary> /// 操作任务日志 /// </summary> /// <typeparam name="T">操作数据类型</typeparam> /// <param name="listInfo">实体集列表</param> /// <param name="dataOperator">数据库操作类型</param> /// <param name="error">错误信息</param> bool SystemLog <T>(List <T> listInfo, 数据库操作 dataOperator, out string error) { error = null; if (listInfo == null || listInfo.Count == 0) { error = "操作失败: 数据为空"; return(false); } try { AccessParameter acc = new AccessParameter(); if (!SystemLog <T>(acc, listInfo, dataOperator, out error)) { return(false); } if (!RunTransaction(acc)) { error = "操作失败:存储过程操作失败"; return(false); } return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 向事务中添加更新存储过程 /// </summary> /// <typeparam name="T">操作数据的类型</typeparam> /// <param name="items">实体列表</param> /// <param name="accessParameter">数据层参数对象</param> /// <param name="error">错误信息</param> public bool Delete <T>(List <T> items, AccessParameter accessParameter, out string error) { error = null; try { if (!GetObject <T>().Delete <T>(items, accessParameter, out error)) { return(false); } if (!typeof(T).ToString().Contains("PRJ_SystemLog")) { if (!SystemLog <T>(accessParameter, items, 数据库操作.除, out error)) { return(false); } } return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 操作任务日志 /// </summary> /// <typeparam name="T">操作数据类型</typeparam> /// <typeparam name="accessParameter">数据上下文</typeparam> /// <param name="listInfo">实体集列表</param> /// <param name="dataOperator">数据库操作类型</param> /// <param name="error">错误信息</param> bool SystemLog <T>(AccessParameter accessParameter, List <T> listInfo, 数据库操作 dataOperator, out string error) { error = null; if (listInfo == null || listInfo.Count == 0) { error = "操作失败: 数据为空"; return(false);; } try { List <ServiceEntity.DataBaseOperatorParmeters> listOperator = GetOperatorInfo <T>(listInfo, dataOperator); foreach (ServiceEntity.DataBaseOperatorParmeters item in listOperator) { string strPrimary = ""; string strWhere = "主键:"; foreach (KeyValuePair <string, object> primaryKey in item.PrimaryKey) { string strValue = ""; if (primaryKey.Value != null) { strValue = primaryKey.Value.ToString(); } strWhere += " 【 " + primaryKey.Key + " 字段, 值: " + strValue + " 】"; } foreach (KeyValuePair <string, DataValueType> info in item.OperatorInfo) { if (info.Key != null) { strWhere += "【 " + info.Key + " 字段,"; string strOld = info.Value.OldValue == null ? "" : info.Value.OldValue.ToString(); string strNew = info.Value.NewValue == null ? "" : info.Value.NewValue.ToString(); if (info.Value.NewValue != null) { strWhere += " 值: " + strNew; } if (item.DataOperator == 数据库操作.修改) { strWhere += " 原值: " + strNew; } strWhere += " 】"; } } DataEntity.PRJ_SystemLog sysLog = new DataEntity.PRJ_SystemLog(); sysLog.Content = "操作表: {[" + item.TableName + "]},操作类型:{" + item.DataOperator.ToString() + "}, {" + strPrimary + "}, 操作内容: {" + strWhere + "}"; sysLog.RecordTime = DateTime.Now; sysLog.Recorder = ""; List <DataEntity.PRJ_SystemLog> list = new List <DataEntity.PRJ_SystemLog>(); list.Add(sysLog); if (!Insert <DataEntity.PRJ_SystemLog>(list, accessParameter, out error)) { return(false); } } return(true); } catch (Exception ex) { error = ex.Message; return(false); } }