先判断你要注册的用户是不是存在,如果存在就不能注册,如果不存在则进行写入动作。
下面是我写的,你可以进行参考。
protected void Button1_Click(object sender, EventArgs e)
{
using (TransactionScope ts = new TransactionScope()) //如果发生错误则数据库回滚
{
try
{
if (txtuser.Text == "" || txtname.Text == "")
{
握逗团 PublicFun.PublicFunction.showMsg(this, "请输入工号,或姓名");
return;
}
if (txtpass.Text == "" || txtpass2.Text == "")
{
PublicFun.PublicFunction.showMsg(this, "密码不能为空");
return;
}
if (txtemail.Text == "")
{
PublicFun.PublicFunction.showMsg(this, "邮件不能为空");
return;
}
if (txtpass.Text != txtpass2.Text)
{
PublicFun.PublicFunction.showMsg(this, "两次输入的密码补符,请检查");
return;
}
string ceconstr = PublicFun.PublicFunction.GetDBconstr("ce_manage_db");
string sql = "select * from account_user_t where userid='" + txtuser.Text.Trim() + "' ";
指腊 ds = MySqlHelper.ExecuteDataset(ceconstr, sql);
if (ds.Tables[0].Rows.Count == 0)
{
sql = "insert into account_user_t_new(Userid,Password,Username,DeptName,UserDuty,Email,Tel,Ext,createdate,flag) " +
" values('" + txtuser.Text.Trim() + "','" + txtpass.Text.Trim() + "','" + txtname.Text.Trim() + "','" + dpDept.SelectedItem.ToString() + "','" + dpJob.SelectedItem.ToString() + "', " +
" '" + txtemail.Text.Trim() + "','" + txttel.Text.Trim() + "','" + txtext.Text.Trim() + "',now(),'Y') ";
段橘 MySqlHelper.ExecuteNonQuery(PublicFun.PublicFunction.GetDBconstr("ce_manage_db"), sql);
PublicFun.PublicFunction.showMsg(this, "注册成功,等待主管审核");
}
else
{
PublicFun.PublicFunction.showMsg(this, "此工号:" + txtuser.Text.Trim() + " 已经存在 ");
return;
}
}
catch (Exception ex)
{
PublicFun.PublicFunction.showMsg(this, ex.Message);
}
ts.Complete(); //如果发生错误则数据库回滚
}
txtuser.Text = "";
txtname.Text = "";
}
无非就是对数据库的增删查操作,数据库查询语句要会,ADO.NET中的几个重要对象以及方法要知道。登录就是通过输入的用户名和密码到数据库查一下,如果记录为0,就提示输入有误,否则就让这个用户登录,发布信息就是把输瞎喊迹入的信息插渗弯入数据表中磨并。