예제 #1
0
        /// <summary>
        /// 序列化用户对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private static User SerializeToUser(MySqlDataReader reader)
        {
            #region 用户基本信息

            var user = new User();
            user.Id          = EvaluationHelper.ObjectToInt(reader["UserID"]);
            user.Name        = reader["UserName"].ToString();
            user.Password    = reader["Password"].ToString();
            user.DisplayName = reader["DisplayName"].ToString();
            user.RegTime     = EvaluationHelper.ObjectToDateTime(reader["RegTime"]);
            user.UserType    = EvaluationHelper.ObjectToInt(reader["UserType"]);
            user.IsLogin     = EvaluationHelper.ObjectToInt2(reader["IsLogin"]);
            user.LoginTime   = EvaluationHelper.ObjectToDateTime(reader["LoginTime"]);
            user.Avater      = null;
            if (reader["Avatar"] != DBNull.Value)
            {
                try
                {
                    BitmapImage img = ImageHelper.Bytearraytobitmapimage(reader["Avatar"] as byte[]);
                    img.Freeze(); //冻结bitmap,使其可以跨线程访问
                    user.Avater = img;
                }
                catch (Exception ex)
                {
                    LogHelper.MainLog(
                        string.Format("Convert To BitmapImage produce error!UserName={0},ex={1}",
                                      user.Name, ex));
                }
            }
            //角色
            user.UserRole.RoleId   = EvaluationHelper.ObjectToInt(reader["RoleID"]);
            user.UserRole.RoleName = reader["GroupName"].ToString();

            #region 用户对应的员工信息

            var us = new Staff();
            us.Department     = reader["Department"].ToString();
            us.EmployeeNumber = reader["StaffNO"].ToString();
            us.Id             = EvaluationHelper.ObjectToInt(string.IsNullOrEmpty(reader["StaffID"].ToString()) ? "0" : reader["StaffID"]);
            us.Name           = reader["StaffName"].ToString();
            us.Phone          = reader["Telephone"].ToString();
            us.Sex            = EvaluationHelper.ObjectToInt2(string.IsNullOrEmpty(reader["Sex"].ToString()) ? "false" : reader["Sex"]);
            //职位
            us.StaffPosition.PositionId   = EvaluationHelper.ObjectToInt(string.IsNullOrEmpty(reader["PositionID"].ToString()) ? "0" : reader["PositionID"]);
            us.StaffPosition.PositionName = reader["PositionName"].ToString();

            #endregion

            user.UserStaff = us; //用户对应的员工信息对象赋值

            #endregion

            return(user);
        }
예제 #2
0
        /// <summary>
        /// 获取日志
        /// </summary>
        /// <param name="type">日志类型</param>
        /// <param name="logs"></param>
        public static void GetLogs(LogTypeEnum type, out List <LogMessage> logs)
        {
            logs = new List <LogMessage>();
            if (HaveDb())
            {
                int num = 0;
                switch (type)
                {
                case LogTypeEnum.System:     //系统日志10
                    num = 10;
                    break;

                case LogTypeEnum.Operation:     //操作日志11
                    num = 11;
                    break;

                case LogTypeEnum.Call:     //呼叫日志12
                    num = 12;
                    break;

                case LogTypeEnum.Video:     //视频日志13
                    num = 13;
                    break;

                case LogTypeEnum.Alarm:     //报警日志14
                    num = 14;
                    break;

                case LogTypeEnum.OrdinaryMsg:     //普通消息
                    num = 15;
                    break;

                case LogTypeEnum.MissedCalled:     //未接来电16
                    num = 16;
                    break;

                case LogTypeEnum.PanelMsg:     //面板消息17
                    num = 17;
                    break;
                }
                if (num != 0)
                {
                    SQLiteDataReader reader = null;
                    try
                    {
                        string sql = "select * from log where logtype=@type order by RowID DESC";
                        reader = SqLiteHelper.ExcuteReader(SqLiteHelper.Open(_dbPath), sql, new SQLiteParameter("@type", num));
                        while (reader.Read())
                        {
                            LogMessage log = new LogMessage();
                            log.LogTime    = EvaluationHelper.ObjectToDateTime(reader["logtime"]);
                            log.LogMsg     = EvaluationHelper.ObjectToString(reader["logmsg"]);
                            log.LogType    = EvaluationHelper.ObjectToInt(reader["logtype"]);
                            log.OperaterId = EvaluationHelper.ObjectToString(reader["username"]);
                            log.FromNo     = EvaluationHelper.ObjectToString(reader["caller"]);
                            log.PanelNum   = EvaluationHelper.ObjectToInt(reader["callpanel"]);
                            logs.Add(log);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.MainLog(ex.Message);
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                }
            }
        }