电影记录管理系统5[用户注册]
2012-09-20 19:03
465 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
namespace 电影记录管理系统
{
public partial class FrmRegister1 : Form
{
public FrmRegister1()
{
InitializeComponent();
}
//连接到配置文件App.config
static string connStr = ConfigurationManager.ConnectionStrings["str"].ConnectionString;
private void btnOK_Click(object sender, EventArgs e)
{
//否则判断 当前用户名在数据库中是否存在
//使用sql select语句 按 用户文本框中的文本内容 来选取数据库中的用户名
string sql = "select MUserName from MovieAccount where MUserName='" + txtUid.Text + "'";
//使用sql语句来连接数据库
SqlConnection conn = new SqlConnection(connStr);
//创建一个cmd对象
SqlCommand cmd = new SqlCommand(sql, conn);
//打开数据库连接
conn.Open();
//使用SqlDataReader 对cmd 执行读取指令的数据 进行逐行读取
SqlDataReader sdr = cmd.ExecuteReader();
//如果读到数据了,说明 数据库中已存在 文本框中输入的用户名
if (sdr.Read())
{
//如果读到相同的用户名 则提示 用户名已存在
lblUidMsg.Text = "用户名已存在,请重新输入!";
return;
}
//如果用户名不存在 则判断下用户名密码是否为空
else if (txtUid.Text.Trim() == "")
{
//如果用户名 不为空, 将提示语句赋给label框 并在窗体上
lblUidMsg.Text = "用户名不能为空!";
}
//判断密码是否为空
else if (txtPwd.Text.Trim() == "")
{
//同理
lblPwdMsg.Text = "密码不能为空!";
//同时清除 用户名 提示框的内容
lblUidMsg.Text = "";
}
//判断再次输入密码是否为空
else if (txtPwdConfirm.Text.Trim() == "")
{
//同理
lblPwdConfirmMsg.Text = "验证密码不能为空!";
//同时清除 用户名 提示框 和 第一次密码输入提示框的内容
lblUidMsg.Text = "";
lblPwdMsg.Text = "";
}
//判断2次密码输入是否相同
else if (txtPwd.Text.Trim() != txtPwdConfirm.Text.Trim())
{
//同理
lblPwdMsg.Text = "2次密码必须一样!";
lblPwdConfirmMsg.Text = "请重新输入!";
return;
}
else
{
//清空上面所有label框的提示
lblUidMsg.Text = "";
lblPwdMsg.Text = "";
lblPwdConfirmMsg.Text = "";
//关闭数据库,节省资源
conn.Close();
//使用sql 数据插入语句
string sqlInsert = "insert into MovieAccount(MUserName,MUserPwd) values(@MUserName,@MUserPwd)";
SqlParameter[] param = {
new SqlParameter("@MUserName",txtUid.Text),
new SqlParameter("@MUserPwd",txtPwd.Text)
};
//使用 SQL数据库连接
SqlConnection connInsert = new SqlConnection(connStr);
//使用SQL command 指令来装载 SQL查询语句和SQL数据库连接
SqlCommand cmdInsert = new SqlCommand(sqlInsert, connInsert);
//再次打开数据连接 执行插入数据操作
connInsert.Open();
//使用cmd指令 添加所有参数
cmdInsert.Parameters.AddRange(param);
//定义一个整型变量 用于接受 cmd的 执行查询指令
int n = cmdInsert.ExecuteNonQuery();
//判断该值是否为空, 如果为空, 说明插入数据失败
if (n == 0)
{
MessageBox.Show("注册失败!,请重新输入");
return;
}
else
{
MessageBox.Show("注册成功!");
}
//关闭数据库连接
connInsert.Close();
}
}
private void btnBack_Click(object sender, EventArgs e)
{
//new一个main窗体
FrmMain main = new FrmMain();
//显示main窗体
main.Show();
//隐藏当前的窗体
this.Hide();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
namespace 电影记录管理系统
{
public partial class FrmRegister1 : Form
{
public FrmRegister1()
{
InitializeComponent();
}
//连接到配置文件App.config
static string connStr = ConfigurationManager.ConnectionStrings["str"].ConnectionString;
private void btnOK_Click(object sender, EventArgs e)
{
//否则判断 当前用户名在数据库中是否存在
//使用sql select语句 按 用户文本框中的文本内容 来选取数据库中的用户名
string sql = "select MUserName from MovieAccount where MUserName='" + txtUid.Text + "'";
//使用sql语句来连接数据库
SqlConnection conn = new SqlConnection(connStr);
//创建一个cmd对象
SqlCommand cmd = new SqlCommand(sql, conn);
//打开数据库连接
conn.Open();
//使用SqlDataReader 对cmd 执行读取指令的数据 进行逐行读取
SqlDataReader sdr = cmd.ExecuteReader();
//如果读到数据了,说明 数据库中已存在 文本框中输入的用户名
if (sdr.Read())
{
//如果读到相同的用户名 则提示 用户名已存在
lblUidMsg.Text = "用户名已存在,请重新输入!";
return;
}
//如果用户名不存在 则判断下用户名密码是否为空
else if (txtUid.Text.Trim() == "")
{
//如果用户名 不为空, 将提示语句赋给label框 并在窗体上
lblUidMsg.Text = "用户名不能为空!";
}
//判断密码是否为空
else if (txtPwd.Text.Trim() == "")
{
//同理
lblPwdMsg.Text = "密码不能为空!";
//同时清除 用户名 提示框的内容
lblUidMsg.Text = "";
}
//判断再次输入密码是否为空
else if (txtPwdConfirm.Text.Trim() == "")
{
//同理
lblPwdConfirmMsg.Text = "验证密码不能为空!";
//同时清除 用户名 提示框 和 第一次密码输入提示框的内容
lblUidMsg.Text = "";
lblPwdMsg.Text = "";
}
//判断2次密码输入是否相同
else if (txtPwd.Text.Trim() != txtPwdConfirm.Text.Trim())
{
//同理
lblPwdMsg.Text = "2次密码必须一样!";
lblPwdConfirmMsg.Text = "请重新输入!";
return;
}
else
{
//清空上面所有label框的提示
lblUidMsg.Text = "";
lblPwdMsg.Text = "";
lblPwdConfirmMsg.Text = "";
//关闭数据库,节省资源
conn.Close();
//使用sql 数据插入语句
string sqlInsert = "insert into MovieAccount(MUserName,MUserPwd) values(@MUserName,@MUserPwd)";
SqlParameter[] param = {
new SqlParameter("@MUserName",txtUid.Text),
new SqlParameter("@MUserPwd",txtPwd.Text)
};
//使用 SQL数据库连接
SqlConnection connInsert = new SqlConnection(connStr);
//使用SQL command 指令来装载 SQL查询语句和SQL数据库连接
SqlCommand cmdInsert = new SqlCommand(sqlInsert, connInsert);
//再次打开数据连接 执行插入数据操作
connInsert.Open();
//使用cmd指令 添加所有参数
cmdInsert.Parameters.AddRange(param);
//定义一个整型变量 用于接受 cmd的 执行查询指令
int n = cmdInsert.ExecuteNonQuery();
//判断该值是否为空, 如果为空, 说明插入数据失败
if (n == 0)
{
MessageBox.Show("注册失败!,请重新输入");
return;
}
else
{
MessageBox.Show("注册成功!");
}
//关闭数据库连接
connInsert.Close();
}
}
private void btnBack_Click(object sender, EventArgs e)
{
//new一个main窗体
FrmMain main = new FrmMain();
//显示main窗体
main.Show();
//隐藏当前的窗体
this.Hide();
}
}
}
相关文章推荐
- C#简易电影记录管理系统:开发七[用户分类]
- 银行管理系统 实现用户注册 登录 存、取款 交易记录查询和修改用户信息等功能
- 电影记录管理系统7[用户级别]
- 黑马程序员--用户注册登录管理系统…
- 会议记录管理系统(3) - 用户个人信息模块设计
- 黑马程序员--用户注册管理系统(Sp…
- 使用MVC实现用户登录注册系统—银行管理系统
- 【项目记录】山东大学场馆管理系统之——用户部分
- 我记录综合系统学习研究之用户管理四(用户空间)
- 黑马程序员--用户注册登录管理系统…
- 电影记录管理系统代码(笔记)
- 电影记录管理系统3[密码修改]
- 多用户管理系统--注册(1)
- 黑马程序员--用户注册登录管理系统…
- 电影记录管理系统九[数据恢复]
- 黑马程序员--用户注册登录管理系统…
- 电影记录管理系统十[权限设置]
- C#_会员管理系统:开发五(用户注册)
- 黑马程序员--用户注册登录管理系统…
- JSP+Servlet培训班作业管理系统[4]-记录登录用户信息