QQ管理器

news/2024/11/21 1:39:28/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace QQ信息管理系统
{class UserManager{public void Login(){int count = 0;do{string strUserName = string.Empty;//初始化管理员登录名string strPwd = string.Empty;//初始化管理员密码count++;Console.WriteLine("请输入用户名:");strUserName = Console.ReadLine();Console.WriteLine("请输入密码:");strPwd = Console.ReadLine();//非空验证if (strUserName.Equals(string.Empty) || strPwd.Equals(string.Empty)){Console.WriteLine("输入错误,请重新输入!\n");continue;//重新输入用户名和密码}else{// 需返回的结果信息string strMsg = string.Empty;//数据库验证bool bRet = a.CheckAdminInfo(strUserName, strPwd, ref strMsg);if (bRet){Console.WriteLine("登录成功!");// 显示菜单ShowMenu();                           //在此处添加菜单名break;//退出程序}else{Console.WriteLine("登录失败:" + strMsg + "\n");continue;//重新输入用户名和密码}}} while (count < 3);if (count == 3)Console.WriteLine("\n连续三次登录失败,退出本系统!\n");}private DBHandle a = new DBHandle();                   //创建DBHandle的实例const String EXCEPT = "出现异常。请与系统管理员联系!";private void ShowMenu(){DBHandle a = new DBHandle();string option = "";do{Console.WriteLine("");Console.WriteLine("=======欢迎登录QQ用户信息管理系统======");Console.WriteLine("----------------请选择菜单项----------");Console.WriteLine("1、显示用户清单");Console.WriteLine("2、更新在线天数");Console.WriteLine("3、添加用户新记录");Console.WriteLine("4、更新用户等级");Console.WriteLine("5、删除用户记录");Console.WriteLine("0、退出");Console.WriteLine("=======================================");option = Console.ReadLine();switch (option){case "1"://显示用户信息a.GetUserList();continue;case "2"://更新在线天数   UpdateOnLineDay();continue;case "3"://添加用户     InsertUserInfo();continue;case "4"://更新用户等级 UpdateUserLevel();continue;case "5"://删除用户continue;case "0":if (IsExit()){break;//退出}else{continue;}default:continue;}break;} while (true);}private bool IsExit(){bool flag = true;Console.WriteLine("是否退出?(Y/N)");string strRet = Console.ReadLine();strRet = strRet.Trim().ToUpper();if (strRet.Equals("Y")){flag= true;}else{flag= false;}return flag;}//public string showDesign(string strLeve) {//    string strDesign = string.Empty;//    switch (strLeve)//    {//        case "无等级"://            strDesign = "―";//            break;//        case "星星"://            strDesign = "☆";//            break;//        case "月亮"://            strDesign = "€";//            break;//        case "太阳"://            strDesign = "◎";//            break;//        default://            strDesign = "-----";//            break;//    }//    return strDesign;//}public string showDesign(string strLevel){string strDesign = string.Empty;switch (strLevel){case "无等级":strDesign = "_";break;case "星星":strDesign = "☆";break;case "月亮":strDesign = "#";break;case "太阳":strDesign = "@";break;//default: strDesign = "◎";//    break;}return strDesign;}//private void ShowUserInfo()//{//    SqlDataReader reader =a.GetUserList();//    if (reader == null)//    {//        Console.WriteLine(EXCEPT);//        return;//    }//    DisplayUserInfo(reader);//    Console.ReadLine();//}private void UpdateOnLineDay(){try{Console.WriteLine("请输入用户编号:");string strUserId = Console.ReadLine();int iUserId = Convert.ToInt32(strUserId);Console.WriteLine("请输入新的在线天数");string strNewOnlineDay = Console.ReadLine();double iNewOnlineDay = Convert.ToDouble(strNewOnlineDay);int iRet = a.UpdateOnlineDay(iUserId, iNewOnlineDay);if (iRet == -1)Console.WriteLine("");else if (iRet == 0){Console.WriteLine("用户记录不存在");}else{Console.WriteLine("修改成功!");}}catch (Exception){Console.WriteLine(EXCEPT);}}private void InsertUserInfo(){Console.WriteLine("请输入用户昵称:");string strUserName = Console.ReadLine();Console.WriteLine("请输入用户密码:");string strUserPwd = Console.ReadLine();Console.WriteLine("请输入用户邮箱地址:");string strUserEmail = Console.ReadLine();int iRet = Convert.ToInt32(a.InsertUserInfo(strUserName, strUserPwd, strUserEmail));if (iRet == 1){Console.WriteLine(EXCEPT);}else if (iRet == 0){Console.WriteLine("用户记录不存在");}else{Console.WriteLine("插入成功!用户编号是:" + iRet);}}private int JudgeLevelByOnLineDay(double iOnlineDay){const int LEVEL1 = 5;const int LEVEL2 = 32;const int LEVEL3 = 320;int iNewLevel = 0;//计算后的等级if (iOnlineDay >= LEVEL1 && iOnlineDay < LEVEL2)//5<=在线天数<32更新为星星{iNewLevel = 2;}else if (iOnlineDay >= LEVEL2 && iOnlineDay < LEVEL3)//32<=在线天数<320更新为月亮{iNewLevel = 3;}else if (iOnlineDay >= LEVEL3)//在线天数>=320更新为太阳{iNewLevel = 4;}else{iNewLevel = 1;}return iNewLevel;}private void UpdateUserLevel(){//取得所有用户的用户编号和在线天数SqlDataReader reader = a.GetUserIdAndOnlineDay();if (reader == null){Console.WriteLine(EXCEPT);return;}//Console.WriteLine("----------------------开始更新--------------------------------");int iUserId = 0;     //用户编号double iLineDay = 0; //用户在线天数int iLevelId = 0;    //用户等级int count = 0;       //更新记录数//循环取得每行的用户编号和用户等级while (reader.Read()){iUserId = Convert.ToInt32(reader["UserId"]);//用户编号的类型转换iLineDay = Convert.ToDouble(reader["OnLineDay"]);//用户在线天数的类型转换iLevelId = JudgeLevelByOnLineDay(iLineDay);//根据在线天数判定用户等级a.UpdateUserLevel(iUserId, iLevelId);count++;}Console.WriteLine("本次共更新用户记录数:", count);Console.WriteLine("更新成功!");//Console.WriteLine("----------------------更新结束---------------------------------");}}}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace QQ信息管理系统
{class DBHandle{public bool CheckAdminInfo(string userName, string pwd, ref string strMsg){//数据库连接字符串string strconn = "Data Source=.;Initial Catalog=QQDB;Integrated Security=True";//创建数据库连接SqlConnection conn = new SqlConnection(strconn);try{//创建Sql语句string strSql = "select count(*) from Admin where LoginId='" + userName + "' and LoginPwd='" + pwd + "'";//打开数据库conn.Open();//创建Command命令SqlCommand comm = new SqlCommand(strSql, conn);int iRet =(int) comm.ExecuteScalar();if (iRet != 1){strMsg = "输入无效!";return false;}else{return true;}}catch (Exception){strMsg = "发生异常!";return false;}finally{//关闭数据库连接conn.Close();}}public void GetUserList() {UserManager b = new UserManager();string strconn = "Data Source=.;Initial Catalog=QQDB;Integrated Security=True";                                     //连接数据库SqlConnection conn = new SqlConnection(strconn);                                                                     //创建连接类try{conn.Open();StringBuilder sb = new StringBuilder();sb.AppendLine("SELECT");sb.AppendLine("           a.UserId");sb.AppendLine("           ,a.UserName");sb.AppendLine("           ,b.levename");sb.AppendLine("           ,a.Email");sb.AppendLine("           ,a.OnLineDay");sb.AppendLine("FROM");sb.AppendLine("                [UserInfo] a,Leve b");sb.AppendLine("  where  ");sb.AppendLine("        a.LeveId=b.LeveId");Console.WriteLine(sb.ToString());SqlCommand comm = new SqlCommand(sb.ToString(), conn);Console.WriteLine("-------------------------------------------------------------------------");Console.WriteLine("编号\t昵称\t\t等级\t\t邮箱\t\t在线天数");Console.WriteLine("-------------------------------------------------------------------------");SqlDataReader w= comm.ExecuteReader();while (w.Read()){string o =b.showDesign(w["LeveName"].ToString());Console.WriteLine(w);//Console.WriteLine(showDesign((string)reader["LeveName"]));Console.WriteLine(w["UserId"].ToString() + "\t" + w["UserName"].ToString() + "\t" + o + "\t" + w["Email"].ToString() + "\t" + w["OnLineDay"].ToString());}}catch (Exception ex){Console.WriteLine(ex.Message);Console.WriteLine("数据库操作失败!");}finally {//conn.Close();                                  //关闭连接}}public int UpdateOnlineDay(int userId, double newOnlineDay){string strconn = "Data Source=.;Initial Catalog=QQDB;Integrated Security=True";try{SqlConnection conn = new SqlConnection(strconn);conn.Open();StringBuilder sb = new StringBuilder();sb.AppendLine("UPDATE");sb.AppendLine("           [UserInfo]");sb.AppendLine(" SET ");sb.AppendLine("          [OnLineDay]=" + newOnlineDay);sb.AppendLine(" WHERE ");sb.AppendLine("          [UserId]=" + userId);Console.WriteLine(sb);SqlCommand comm = new SqlCommand(sb.ToString(), conn);return comm.ExecuteNonQuery();}catch (Exception){return -1;}}public object InsertUserInfo(string userName, string userPwd, string email){string strconn = "Data Source=.;Initial Catalog=QQDB;Integrated Security=True";SqlConnection conn = new SqlConnection(strconn);try{conn.Open();StringBuilder sb = new StringBuilder();//插入用户记录sb.AppendLine(" INSERT INTO");sb.AppendLine("          [UserInfo]");sb.AppendLine(" VALUES");sb.AppendLine("          ('" + userName + "','" + userPwd + "',1,'" + email + "',0);");//获得插入记录的用户编号sb.AppendLine(" SELECT @@Identity;");Console.WriteLine(sb);SqlCommand comm = new SqlCommand(sb.ToString(), conn);return comm.ExecuteScalar();}catch (Exception){               return -1;}}public SqlDataReader GetUserIdAndOnlineDay(){string strconn = "Data Source=.;Initial Catalog=QQDB;Integrated Security=True";try{SqlConnection conn = new SqlConnection(strconn);conn.Open();StringBuilder sb = new StringBuilder();sb.AppendLine(" SELECT");sb.AppendLine("           [UserId]");sb.AppendLine("          ,[OnLineDay]");sb.AppendLine(" FROM");sb.AppendLine("           [UserInfo] ");SqlCommand comm = new SqlCommand(sb.ToString(), conn);return comm.ExecuteReader();}catch (Exception){return null;}}public int UpdateUserLevel(int userId, int iLevel){string strconn = "Data Source=.;Initial Catalog=QQDB;Integrated Security=True";try{SqlConnection conn = new SqlConnection(strconn);conn.Open();StringBuilder sb = new StringBuilder();sb.AppendLine(" UPDATE");sb.AppendLine("          from [UserInfo]");sb.AppendLine(" SET");sb.AppendLine("           [LevelId]=" + iLevel);sb.AppendLine(" WHERE");sb.AppendLine("           [UserId]=" + userId);SqlCommand comm = new SqlCommand(sb.ToString(), conn);return comm.ExecuteNonQuery();}catch (Exception){return -1;}}}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace QQ信息管理系统
{class Program{static void Main(string[] args){UserManager manger = new UserManager();Console.WriteLine();manger.showDesign("星星");manger.Login();}}
}


http://www.ppmy.cn/news/803554.html

相关文章

android 消息管理器,腾讯TIM消息管理器在哪 腾讯TIM打开消息管理器的教程

腾讯TIM最新简介 tim最新版主要是在“日程”方面进行了改进&#xff0c;比如在聊天界面点击日程时&#xff0c;可以新建日程和分享我的日程、日程界面支持周视图展示等。另外&#xff0c;更新还精简代码&#xff0c;缩减安装包大小&#xff0c;屏蔽了送礼物等功能和动画。 腾讯…

Debezium日常分享系列之:Debezium 信号发送和通知 - 第 1 部分

Debezium日常分享系列之&#xff1a;Debezium 信号发送和通知 - 第 1 部分 一、背景二、Debezium 中的信号发送三、Debezium 中的通知四、结论 一、背景 本系列文章将介绍 Debezium 提供的信号和通知功能&#xff0c;并讨论与平台交互的可用渠道。在本系列的后续部分中&#x…

学习推荐

编程类 类Unix系统的编程书籍里&#xff0c;最经典的莫过于简称为APUE的《Advanced Programming in the UNIX Environment》&#xff08;中译名是“Unix环境高级编程”&#xff09;&#xff0c;这本书被广大Unix程序员&#xff08;包括Linux&#xff09;捧为“圣经”。借用葛大…

js的数组解构

数组解构&#xff08;Array Destructuring&#xff09;时&#xff0c;有几个重要的概念需要了解&#xff1a; 基本数组解构&#xff1a; 可以使用方括号&#xff08;[]&#xff09;来定义解构模式。解构模式将数组中的值分配给对应的变量。解构是基于位置的&#xff0c;变量的…

推荐一款Python 代码自动补全神器

是时候跟你说说这个能让你撸代码撸得舒服得不要不要的神器了——kite。 简单来说&#xff0c;它是一款 IDE 的插件&#xff0c;能做到代码自动补全&#xff0c;可能你会说了&#xff0c;这有什么牛逼的&#xff1f;一般的编辑器不都有这个功能么&#xff1f; 它虽然是一个插件&…

【推荐架构day9】推荐领域的基本问题:什么是信息茧房

什么是信息茧房 信息茧房其实是现在社会一个很可怕的现象&#xff0c;从字面意思来看的话其实比喻的是信息被虫茧一般封锁住。这个问题反映了现在随着个性化推荐的普及衍射的一个社会问题。 平时在浏览新闻或者淘宝的时候&#xff0c;平台会自动根据用户的浏览记录获取用户的偏…

王欣回应微信封禁,解释为何取名叫马桶MT

1月15日&#xff0c;真是个“黄道吉日”&#xff1a;快播创始人王欣宣布上线马桶MT、罗永浩站台快如科技、字节跳动张一鸣发布社交新品。3款APP宣战微信&#xff0c;成为今天互联网上最热的话题。 要知道&#xff0c;距离张小龙4小时的微信公开课逆天演讲才仅仅过去整整一周时…

linux下推荐书籍

工作几年来&#xff0c;一直从事Linux内核驱动方面的开发。从接触Linux到现在&#xff0c;读过不少Linux方面的书籍&#xff0c;现把认为很不错的一部分列出来和大家分享一下。 入门类 一直认为&#xff0c;在一个系统上学习开发之前&#xff0c;首先需要熟悉这个系统的使用。鉴…