测试:
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { UserManager manger = new UserManager(); manger.Login(); } } }
DB类 :DB类 :DB类 :
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; namespace ConsoleApplication1 { class DBHandle { string strConn = "Data Source=.;Initial Catalog=QQDB;Integrated Security=True"; public bool CheckAdminInfo(string userName, string pwd, ref string strMsg) { SqlConnection conn = new SqlConnection(strConn); try { string strSql = "select count(*) from Admin where LoginId='" + userName + "' and LoginPwd='" + pwd + "'"; conn.Open(); SqlCommand comm = new SqlCommand(strSql, conn); int iRet = (int)comm.ExecuteScalar(); if (iRet != 1) { strMsg = "输入无效!"; return false; } else { return true; } } catch (Exception ex) { Console.WriteLine(ex.Message); strMsg = "发生异常!"; return false; } finally { conn.Close(); } } public SqlDataReader GetUserList() { try { SqlConnection conn = new SqlConnection(strConn); conn.Open(); StringBuilder sb = new StringBuilder(); sb.AppendLine(" SELECT"); sb.AppendLine(" a.[UserId]"); sb.AppendLine(" ,a.[UserName]"); sb.AppendLine(" ,b.[LevelName]"); sb.AppendLine(" ,a.[Email]"); sb.AppendLine(" ,a.[OnLineDay]"); sb.AppendLine(" FROM"); sb.AppendLine(" [UserInfo] a, [Level] b "); sb.AppendLine(" WHERE"); sb.AppendLine(" a.[LevelId] = b.[LevelId]"); SqlCommand comm = new SqlCommand(sb.ToString(), conn); return comm.ExecuteReader(); } catch (Exception) { return null; } } public SqlDataReader GetUserIdAndOnlineDay() { try { SqlConnection conn = new SqlConnection(strConn); conn.Open();
C# ,十七章 项目案例: QQ用户信息管理系统
最新推荐文章于 2016-12-02 19:01:56 发布