c#小系统开发之登录 注册
2014-12-26 21:27
239 查看
欢迎来到unity脚本学习社区
今天来回顾一下控制台交互的登录与注册
一、注册(数据库的插入操作)
public int Registered (string name,string password,int age,string sex)
{
SqlConnection con = new SqlConnection("server=.;database=school;Trusted_Connection=SSPI");
con.Open();
SqlCommand com = new SqlCommand("insert into student (name,password,age,sex)values('"+name +"','"+password +"',"+age+",'"+sex+"')", con);
int i = com.ExecuteNonQuery();
con.Close();
return i;
}
二、登录(数据库查询操作)
public Student Login(string name,string password) {
Student s=new Student ();
SqlConnection con = new SqlConnection("server=.;database=school;Trusted_Connection=SSPI");
con.Open();
SqlCommand com = new SqlCommand("select name,password from student where name='" + name + "'and password='" + password + "'", con);
SqlDataReader re = com.ExecuteReader();
while (re.Read())
{
Student s1=new Student ();
s1.Name = (string)re.GetValue(0);
s1.password = (string)re.GetValue(1);
s = s1;
}
return s;
}
}
三、控制台界面(这里拿一个学生登录 注册来举例)
public void Student()
{
Console.WriteLine("*******************************************");
Console.WriteLine("*******************************************");
Console.WriteLine("************ 输入1 请登录 ***********");
Console.WriteLine("************ 输入2 请注册 ***********");
Console.WriteLine("*******************************************");
Console.WriteLine("*******************************************");
string a = Console.ReadLine();
switch (a)
{
case "1":
Console.WriteLine("输入学生姓名");
string name1 = Console.ReadLine();
Console.WriteLine("输入学生密码");
string password1 = Console.ReadLine();
s = new Student().Login(name1,password1 );
if (s.Name != null)
{
Console.WriteLine("登录成功");
StudentCourse();
}
else {
Console.WriteLine("登录失败 请重新登录");
}
break;
case "2":
Console.WriteLine("输入学生姓名");
string name = Console.ReadLine();
Console.WriteLine("输入学生密码");
string password = Console.ReadLine();
Console.WriteLine("输入学生年龄");
int age = int.Parse (Console.ReadLine());
Console.WriteLine("输入学生性别");
string sex = Console.ReadLine();
int i
4000
= new Student().Insert(name,password ,age,sex);
if (i == 1)
{
Console.WriteLine("注册成功");
Student();
}
else
{
Console.WriteLine("注册失败 请重新注册");
Student();
}
break;
default:
Console.WriteLine("请重新输入");
break;
}
}
今天来回顾一下控制台交互的登录与注册
一、注册(数据库的插入操作)
public int Registered (string name,string password,int age,string sex)
{
SqlConnection con = new SqlConnection("server=.;database=school;Trusted_Connection=SSPI");
con.Open();
SqlCommand com = new SqlCommand("insert into student (name,password,age,sex)values('"+name +"','"+password +"',"+age+",'"+sex+"')", con);
int i = com.ExecuteNonQuery();
con.Close();
return i;
}
二、登录(数据库查询操作)
public Student Login(string name,string password) {
Student s=new Student ();
SqlConnection con = new SqlConnection("server=.;database=school;Trusted_Connection=SSPI");
con.Open();
SqlCommand com = new SqlCommand("select name,password from student where name='" + name + "'and password='" + password + "'", con);
SqlDataReader re = com.ExecuteReader();
while (re.Read())
{
Student s1=new Student ();
s1.Name = (string)re.GetValue(0);
s1.password = (string)re.GetValue(1);
s = s1;
}
return s;
}
}
三、控制台界面(这里拿一个学生登录 注册来举例)
public void Student()
{
Console.WriteLine("*******************************************");
Console.WriteLine("*******************************************");
Console.WriteLine("************ 输入1 请登录 ***********");
Console.WriteLine("************ 输入2 请注册 ***********");
Console.WriteLine("*******************************************");
Console.WriteLine("*******************************************");
string a = Console.ReadLine();
switch (a)
{
case "1":
Console.WriteLine("输入学生姓名");
string name1 = Console.ReadLine();
Console.WriteLine("输入学生密码");
string password1 = Console.ReadLine();
s = new Student().Login(name1,password1 );
if (s.Name != null)
{
Console.WriteLine("登录成功");
StudentCourse();
}
else {
Console.WriteLine("登录失败 请重新登录");
}
break;
case "2":
Console.WriteLine("输入学生姓名");
string name = Console.ReadLine();
Console.WriteLine("输入学生密码");
string password = Console.ReadLine();
Console.WriteLine("输入学生年龄");
int age = int.Parse (Console.ReadLine());
Console.WriteLine("输入学生性别");
string sex = Console.ReadLine();
int i
4000
= new Student().Insert(name,password ,age,sex);
if (i == 1)
{
Console.WriteLine("注册成功");
Student();
}
else
{
Console.WriteLine("注册失败 请重新注册");
Student();
}
break;
default:
Console.WriteLine("请重新输入");
break;
}
}
相关文章推荐
- 单机版简易考试系统开发过程讲解(C#注册机、用户注册、考试系统、有偿提供全部源码)
- 注册登录系统的基本逻辑与结构——ASP.NET(C#)源代码
- MD5算法原理简要介绍并采用C#应用在桌面应用系统的用户登录与注册中
- 实验四 系统登录/注册模块(Android app)的开发
- C# .NET 可灵活配置登录窗体、主窗体的快速信息管理系统开发架构参考
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 检查版本升级、检查登录超时
- 老程序员边学习C#边开发智慧医疗系统---系统登录001
- C#_会员管理系统:开发五(用户注册)
- C# .NET 可灵活配置登录窗体、主窗体的快速信息管理系统开发架构参考
- C#系统开发登录窗体在MDI窗体之前显示
- C# .NET 可灵活配置登录窗体、主窗体的快速信息管理系统开发架构参考
- 小型bbs论坛系统开发6 前台注册/登录页
- 单机版简易考试系统开发过程讲解(C#注册机、用户注册、考试系统、有偿提供全部源码)
- 注册登录系统的基本逻辑与结构——ASP.NET(C#)源代码
- C#开发中Windows域认证登录2(扩展吉日嘎拉GPM系统)
- 使用Eclipse+MyEclipse+MySql开发一个用户注册登录系统
- J2EE初级学习项目——JSP+Servlet+JavaBean开发模式+Filter+(Listener)+Jdbc的用户登录注册系统
- C# 分层开发的案例 学生管理系统 实现用户的登录和修改密码
- C#开发中Windows域认证登录2016(扩展吉日嘎拉GPM系统V4.2)
- C#_会员管理系统:开发一(用户登录)