/// <summary>
        /// 批量删除异常
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>数据表</returns>
        public int BatchDelete(BaseUserInfo userInfo, string[] ids)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseExceptionManager exceptionManager = new BaseExceptionManager(dbHelper, userInfo);
                    returnValue = exceptionManager.Delete(BaseExceptionEntity.FieldId, ids);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, serviceName, AppMessage.ExceptionService_BatchDelete, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
                BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return returnValue;
        }
 /// <summary>
 /// 设置评论处理
 /// </summary>
 /// <param name="id">评论主键数组</param>
 /// <param name="worked">处理状态</param>
 /// <returns>影响行数</returns>
 public int SetWorked(string[] ids, int worked)
 {
     int returnValue = 0;
     string id = string.Empty;
     try
     {
         DbHelper.BeginTransaction();
         for (int i = 0; i < ids.Length; i++)
         {
             id = ids[i];
             // returnValue += this.SetProperty(id, BaseCommentEntity.FieldWorked, worked.ToString());
         }
         DbHelper.CommitTransaction();
     }
     catch (Exception ex)
     {
         DbHelper.RollbackTransaction();
         BaseExceptionManager.LogException(DbHelper, UserInfo, ex);
         throw ex;
     }
     return returnValue;
 }
Beispiel #3
0
        /// <summary>
        /// 记录异常情况
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="userInfo">用户</param>
        /// <param name="Exception">异常</param>
        /// <returns>主键</returns>
        public static string LogException(IDbHelper dbHelper, BaseUserInfo userInfo, Exception ex)
        {
            // 在控制台需要输出错误信息
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(ex.InnerException);
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(string.Empty);

            string returnValue = string.Empty;

            // 系统里应该可以配置是否记录异常现象
            if (!BaseSystemInfo.LogException)
            {
                return(returnValue);
            }
            // Windows系统异常中
            if (BaseSystemInfo.EventLog)
            {
                if (!System.Diagnostics.EventLog.SourceExists(BaseSystemInfo.SoftName))
                {
                    System.Diagnostics.EventLog.CreateEventSource(BaseSystemInfo.SoftName, BaseSystemInfo.SoftFullName);
                }
                System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog();
                eventLog.Source = BaseSystemInfo.SoftName;
                eventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
            }
            // 判断一下数据库是否打开状态,若数据库都没能打开,还记录啥错误,不是又抛出另一个错误了?
            if (dbHelper != null && dbHelper.GetDbConnection() != null)
            {
                if (dbHelper.GetDbConnection().State == ConnectionState.Open)
                {
                    BaseExceptionManager exceptionManager = new BaseExceptionManager(dbHelper, userInfo);
                    returnValue = exceptionManager.AddEntity(ex);
                }
            }
            return(returnValue);
        }
        /// <summary>
        /// 获取异常列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            DataTable dataTable = new DataTable(BaseExceptionEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseExceptionManager Exception = new BaseExceptionManager(dbHelper, userInfo);
                    dataTable = Exception.GetDataTable();
                    dataTable.TableName = BaseExceptionEntity.TableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, serviceName, AppMessage.ExceptionService_GetDataTable, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
                BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return dataTable;
        }
        /// <summary>
        /// 记录异常情况
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="userInfo">用户</param>
        /// <param name="Exception">异常</param>
        /// <returns>主键</returns>
        public static string LogException(IDbHelper dbHelper, BaseUserInfo userInfo, Exception ex)
        {
            // 在控制台需要输出错误信息
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(ex.InnerException);
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(string.Empty);

            string returnValue = string.Empty;
            // 系统里应该可以配置是否记录异常现象
            if (!BaseSystemInfo.LogException)
            {
                return returnValue;
            }
            // Windows系统异常中
            if (BaseSystemInfo.EventLog)
            {
                if (!System.Diagnostics.EventLog.SourceExists(BaseSystemInfo.SoftName))
                {
                    System.Diagnostics.EventLog.CreateEventSource(BaseSystemInfo.SoftName, BaseSystemInfo.SoftFullName);
                }
                System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog();
                eventLog.Source = BaseSystemInfo.SoftName;
                eventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
            }
            // 判断一下数据库是否打开状态,若数据库都没能打开,还记录啥错误,不是又抛出另一个错误了?
            if (dbHelper != null && dbHelper.GetDbConnection() != null)
            {
                if (dbHelper.GetDbConnection().State == ConnectionState.Open)
                {
                    BaseExceptionManager exceptionManager = new BaseExceptionManager(dbHelper, userInfo);
                    returnValue = exceptionManager.AddEntity(ex);
                }
            }
            return returnValue;
        }