winform注册功能
注册按钮事件:
private void btnregister_click(object sender, eventargs e)
{
string username = txtusername.text;
string userpwd = txtuserpwd.text;
string tel = txttel.text;
string email = txtemail.text;
string name = txtname.text;
int dept = convert.toint32(txtdept.text);
if (string.isnullorempty(username) && string.isnullorempty(userpwd))
{
messagebox.show("用户名和密码不能为空!","提示",messageboxbuttons.ok,messageboxicon.information);
return;
}
string sql = "insert into [userinfo]([username],[userpwd],[name],[deptid],[tel],[email],[state],[registertime],[lastlogintime],[remark])" +
"values(@username,@userpwd,@name,@deptid,@tel,@email,@state,getdate(),getdate(),'null')";
sqlparameter[] param =
{
new sqlparameter("@username",sqldbtype.varchar),
new sqlparameter("@userpwd",sqldbtype.varchar),
new sqlparameter("@name",sqldbtype.varchar),
new sqlparameter("@deptid",sqldbtype.int),
new sqlparameter("@tel",sqldbtype.varchar),
new sqlparameter("@email",sqldbtype.varchar),
new sqlparameter("@state",sqldbtype.varchar)
};
param[0].value = username;
param[1].value = userpwd;
param[2].value = name;
param[3].value = dept;
param[4].value = tel;
param[5].value = email;
param[6].value = "";
int count = datamanager.set(sql, param);
if (count > 0)
{
dialogresult dr = messagebox.show("注册成功,是否登录?", "提示", messageboxbuttons.okcancel, messageboxicon.question);
if (dr == dialogresult.ok)
{
frmlogin login = new frmlogin();
login.show();
this.hide();
}
else
{
this.show();
}
}
else
{
messagebox.show("注册失败!","提示",messageboxbuttons.abortretryignore,messageboxicon.hand);
}
}
调用底层的方法:
datamanager类:
public static int set(string sql, sqlparameter[] pars)
{
return new dataservice().set(sql, pars);
}
dataservice类:
public int set(string sql, sqlparameter[] pars)
{
init(sql, pars, syscontrol.connectionstring);
return set();
}
private int set()
{
con.open();
int i = cmd.executenonquery();
con.close();
return i;
}
syscontrol类:
/// <summary>
/// 数据库连接字符串
/// </summary>
public static string connectionstring = configurationmanager.appsettings["connectionstring"];
在app配置文件里面添加链接:
<appsettings>
<add key ="connectionstring" value="server=.;user id=sa; password=123456; database=db;"/>
</appsettings>
上一篇: 百度:已将人工智能用于外卖
下一篇: AI从人机大战后开始走入我们的生活?