/// <summary>
 /// 获取组织日志信息列表
 /// </summary>
 /// <param name="sql">查询SQL</param>
 /// <returns>日志信息列表</returns>
 public static List<ALog> GetAgentLogList(string sql)
 {
     SqlConnection sqlconn = null;
     SqlCommand sqlcmd = null;
     SqlDataReader sqldr = null;
     List<ALog> list = new List<ALog>();
     try
     {
         sqlconn = new SqlConnection(SqlConnectionString);
         sqlconn.Open();
         sqlcmd = sqlconn.CreateCommand();
         sqlcmd.CommandText = sql;
         sqldr = sqlcmd.ExecuteReader();
         while (sqldr.Read())
         {
             ALog aLog = new ALog();
             aLog.Account = sqldr["AgentId"].ToString();
             aLog.OperTime = Convert.ToDateTime(sqldr["OperTime"]);
             aLog.Desc = sqldr["Desc"].ToString();
             list.Add(aLog);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex);
     }
     finally
     {
         if (null != sqlconn)
         {
             sqlconn.Close();
         }
         if (null != sqldr)
         {
             sqldr.Close();
         }
     }
     return list;
 }
        /// <summary>
        /// 日志记录分页查询
        /// </summary>
        /// <param name="Logqc">查询条条</param>
        /// <param name="pageindex">第几页,从1开始</param>
        /// <param name="pagesize">每页多少条</param>
        /// <param name="page">输出参数(总页数)</param>
        /// <returns>日志信息</returns>
        public TradeALogInfo GetTradeALogInfoWithPage(LogQueryCon Logqc, int pageindex, int pagesize, ref int page)
        {
            TradeALogInfo tradeALogInfo = new TradeALogInfo();

            System.Data.Common.DbDataReader dbreader = null;
            TradeUser TdUser = new TradeUser();
            System.Data.Common.DbParameter OutputParam = DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@PageCount", DbParameterType.Int, 0, ParameterDirection.Output);
            try
            {
                #region 判断登陆标识是否过期

                if (!ComFunction.ExistUserLoginID(Logqc.LoginID, ref TdUser))
                {
                    tradeALogInfo.Result = false;
                    tradeALogInfo.Desc = ResCode.UL003Desc;
                    return tradeALogInfo;
                }
                if (UserType.NormalType == TdUser.UType || UserType.OrgType == TdUser.UType)
                {
                    tradeALogInfo.Result = false;
                    tradeALogInfo.Desc = ComFunction.NotRightUser;
                    return tradeALogInfo;
                }
                #endregion
                string andstr = " and Account<>'admin' and remark not like'%手工调帐%' ";

                if ("ROOT" != TdUser.Account.ToUpper())
                {
                    andstr += " and Account<>'root'";
                }
                if (!string.IsNullOrEmpty(Logqc.Account))
                {
                    andstr += string.Format(" and Account like'{0}%'", Logqc.Account);
                }
                string SearchCondition = string.Format("where a.opertime >= '{0}' and a.opertime <='{1}' and UserType in(0,1,2,3) {2} ", Logqc.StartTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), Logqc.EndTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), andstr);

                dbreader = DbHelper.RunProcedureGetDataReader("GetRecordFromPage",
                      new System.Data.Common.DbParameter[]{
                         DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@selectlist",DbParameterType.String,"[OperTime],[Account],[UserType],[Remark]",ParameterDirection.Input),
                      DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@SubSelectList",DbParameterType.String,"[OperTime],[Account],[UserType],[Remark]",ParameterDirection.Input),
                       DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@TableSource",DbParameterType.String,"Base_OperrationLog a",ParameterDirection.Input), //表名或视图表
                        DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@TableOrder",DbParameterType.String,"a",ParameterDirection.Input), //排序后的表名称 即子查询结果集的别名
                         DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@SearchCondition",DbParameterType.String,SearchCondition,ParameterDirection.Input),
                          DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@OrderExpression",DbParameterType.String,"order by a.opertime desc",ParameterDirection.Input),//排序 表达式
                           DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@PageIndex",DbParameterType.Int,pageindex,ParameterDirection.Input),
                           DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type,
                    "@PageSize",DbParameterType.Int,pagesize,ParameterDirection.Input),
                            OutputParam});
                tradeALogInfo.ALogList = new List<ALog>();
                while (dbreader.Read())
                {
                    ALog aLog = new ALog();
                    aLog.Account = System.DBNull.Value != dbreader["Account"] ? dbreader["Account"].ToString() : string.Empty;
                    aLog.OperTime = System.DBNull.Value != dbreader["OperTime"] ? Convert.ToDateTime(dbreader["OperTime"]) : DateTime.MinValue;
                    aLog.Desc = System.DBNull.Value != dbreader["Remark"] ? dbreader["Remark"].ToString() : string.Empty;
                    aLog.UType = System.DBNull.Value != dbreader["UserType"] ? (UserType)dbreader["UserType"] : UserType.AdminType;
                    tradeALogInfo.ALogList.Add(aLog);
                }

                tradeALogInfo.Result = true;
                tradeALogInfo.Desc = "查询成功";
            }
            catch (Exception ex)
            {
                ComFunction.WriteErr(ex);
                tradeALogInfo.Result = false;
                tradeALogInfo.Desc = "查询日志失败";
            }
            finally
            {
                if (null != dbreader)
                {
                    dbreader.Close();
                    dbreader.Dispose();
                    page = Convert.ToInt32(OutputParam.Value);
                }
            }
            return tradeALogInfo;
        }