Beispiel #1
0
        internal UserInfo Get(int id)
        {
            UserInfo user = null;

            SqlConnection conn   = null;
            SqlDataReader reader = null;

            try
            {
                conn = DBUtil.GetConn();
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("select *");
                sb.AppendLine("from userInfo");
                sb.AppendLine("where userid = {0}");
                string     sql = string.Format(sb.ToString(), id);
                SqlCommand cmd = new SqlCommand(sql, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    user           = new UserInfo();
                    user.Email     = reader["email"].ToString();
                    user.Pwd       = reader["userpwd"].ToString();
                    user.OnlineDay = Convert.ToDouble(reader["onlineDay"]);
                    user.Name      = reader["username"].ToString();
                    user.LevelId   = (int)reader["levelId"];
                    user.Id        = (int)reader["userid"];
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                DBUtil.CloseAll(conn, reader);
            }

            return(user);
        }
Beispiel #2
0
        public static List <UserInfo> FindAll()
        {
            List <UserInfo> list   = new List <UserInfo>();
            SqlConnection   conn   = null;
            SqlDataReader   reader = null;

            try
            {
                conn = DBUtil.GetConn();
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("select u.*, l.flag");
                sb.AppendLine("from userInfo u, level l");
                sb.AppendLine("where u.levelId = l.levelId");
                SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    UserInfo u = new UserInfo();
                    u.Email     = reader["email"].ToString();
                    u.Pwd       = reader["userpwd"].ToString();
                    u.OnlineDay = Convert.ToDouble(reader["onlineDay"]);
                    u.Name      = reader["username"].ToString();
                    u.LevelId   = (int)reader["levelId"];
                    u.Id        = (int)reader["userid"];
                    u.Flag      = reader["flag"].ToString();
                    list.Add(u);
                }
            }catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                DBUtil.CloseAll(conn, reader);
            }

            return(list);
        }
Beispiel #3
0
        public bool Login(string loginId, string loginPwd)
        {
            int           r    = 0;
            SqlConnection conn = DBUtil.GetConn();

            try
            {
                string sql = string.Format("select count(0) from admin " +
                                           "where loginId='{0}' and loginPwd = '{1}'",
                                           loginId, loginPwd);
                SqlCommand cmd = new SqlCommand(sql, conn);
                r = (int)cmd.ExecuteScalar();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                DBUtil.CloseAll(conn, null);
            }
            return(r > 0);
        }