Exemplo n.º 1
0
        static Role()
        {
            Sqlite           sqlite           = new Sqlite();
            SQLiteDataReader sQLiteDataReader = sqlite.Query("select * from role;");

            while (sQLiteDataReader.Read())
            {
                int    key   = sQLiteDataReader.GetInt32(0);
                string value = sQLiteDataReader.GetString(1);
                dicRole.Add(key, value);
            }
            sqlite.Close();
        }
Exemplo n.º 2
0
        public static void Delete(string loglevel, string eventType, DateTime?startDate, DateTime?endDate, string user)
        {
            StringBuilder stringBuilder = new StringBuilder("delete from log ");
            ArrayList     arrayList     = new ArrayList();

            if (!string.IsNullOrEmpty(loglevel))
            {
                arrayList.Add("loglevel = '" + loglevel + "'");
            }
            if (!string.IsNullOrEmpty(eventType))
            {
                arrayList.Add("eventtype = '" + eventType + "'");
            }
            if (!string.IsNullOrEmpty(user))
            {
                arrayList.Add("user = '******'");
            }
            DateTime value;

            if (startDate.HasValue && startDate.HasValue)
            {
                ArrayList arrayList2 = arrayList;
                value = startDate.Value;
                arrayList2.Add("logtime > datetime('" + value.ToString("yyyy-MM-dd HH:mm:ss") + "')");
            }
            if (endDate.HasValue && endDate.HasValue)
            {
                ArrayList arrayList3 = arrayList;
                value = endDate.Value;
                arrayList3.Add("logtime < datetime('" + value.ToString("yyyy-MM-dd HH:mm:ss") + "')");
            }
            string text = "";

            if (arrayList.Count > 0)
            {
                string[] value2 = (string[])arrayList.ToArray(typeof(string));
                text = string.Join(" and ", value2);
            }
            if (!string.IsNullOrEmpty(text))
            {
                stringBuilder.Append(" where " + text);
            }
            Sqlite sqliteHelper = new Sqlite();

            sqliteHelper.Query(stringBuilder.ToString());
            sqliteHelper.Close();
        }
Exemplo n.º 3
0
 /// <summary>
 /// 记录操作日志到sqlite.
 /// </summary>
 /// <param name="log">The log.</param>
 public static void Log2Sqlite(Log log)
 {
     if (log != null)
     {
         try
         {
             string strSql = string.Format("INSERT INTO log (loglevel,logtime,message,eventtype,user) VALUES ('{0}','{1}','{2}','{3}','{4}');", log.LogLevel, log.LogTime.ToString(ConstDef.longDate), log.Message, log.EventType, log.User);
             Sqlite sqlite = new Sqlite();
             sqlite.ExecuteNonQuery(strSql);
             sqlite.Close();
         }
         catch (Exception ex)
         {
             Log2File(null, ex);
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Finds the specified where.
        /// </summary>
        /// <param name="where">The where.</param>
        /// <returns>Role.</returns>
        public static Role Find(string where)
        {
            Role   role   = new Role();
            Sqlite sqlite = new Sqlite();
            string text   = "select * from role ";

            if (!string.IsNullOrEmpty(where))
            {
                text = text + " where " + where;
            }
            SQLiteDataReader sQLiteDataReader = sqlite.Query(text);

            while (sQLiteDataReader.Read())
            {
                role.Id   = sQLiteDataReader.GetInt32(0);
                role.Name = sQLiteDataReader.GetString(1);
            }
            sqlite.Close();
            return(role);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Queries the specified where.
        /// </summary>
        /// <param name="where">The where.</param>
        /// <returns>List&lt;Role&gt;.</returns>
        public static List <Role> Query(string where)
        {
            List <Role> list = new List <Role>();
            string      text = "select id,name from role ";

            if (!string.IsNullOrEmpty(where))
            {
                text = text + " where " + where;
            }
            Sqlite           sqlite           = new Sqlite();
            SQLiteDataReader sQLiteDataReader = sqlite.Query(text);

            while (sQLiteDataReader.Read())
            {
                Role role = new Role();
                role.Id   = sQLiteDataReader.GetInt32(0);
                role.Name = sQLiteDataReader.GetString(1);
                list.Add(role);
            }
            sqlite.Close();
            return(list);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Finds the specified username.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <returns>User.</returns>
        public static User Find(string username)
        {
            User             user             = null;
            string           sql              = "SELECT U.ID,U.USERNAME,U.PASSWORD,R.ID,R.NAME FROM user U,role R WHERE R.ID=U.ROLEID AND U.USERNAME ='******'";
            Sqlite           sqlite           = new Sqlite();
            SQLiteDataReader sQLiteDataReader = sqlite.Query(sql);

            while (sQLiteDataReader.Read())
            {
                user          = new User();
                user.Id       = sQLiteDataReader.GetInt32(0);
                user.UserName = sQLiteDataReader.GetString(1);
                user.Password = sQLiteDataReader.GetString(2);
                Role role = new Role();
                role.Id     = sQLiteDataReader.GetInt32(3);
                role.Name   = sQLiteDataReader.GetString(4);
                user.Role   = role;
                user.RoleId = role.Id;
            }
            sqlite.Close();
            return(user);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Finds the specified Authority.
        /// </summary>
        /// <param name="where">The where.</param>
        /// <returns>Authority.</returns>
        public static Authority Find(string where)
        {
            Authority auth   = new Authority();
            Sqlite    sqlite = new Sqlite();
            string    text   = "SELECT A.id,A.name,R.id,R.name FROM auth A,role R WHERE A.roleid=R.id ";

            if (!string.IsNullOrEmpty(where))
            {
                text = text + " AND A." + where;
            }
            SQLiteDataReader reader = sqlite.Query(text);

            while (reader.Read())
            {
                auth.Id   = reader.GetInt32(0);
                auth.Name = reader.GetString(1);
                Role role = new Role();
                role.Id   = reader.GetInt32(2);
                role.Name = reader.GetString(3);
                auth.Role = role;
            }
            sqlite.Close();
            return(auth);
        }