• 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>

  • 相关阅读:
    git 忽略文件夹权限
    文字特效-shine.js-阴影随动
    微信小程序scroll-view中的坑(因为动态设置高度导致无法下拉)
    gitlab 403 forbidden 报错解决
    Vue子组件调用父组件的方法
    github的小笔记
    windows win10 重装系统 提示不是gpt分区不能安装
    使用html5播放m3u8直播源
    youtube-dl 使用简介
    ABAP RSA 加密
  • 原文地址:https://www.cnblogs.com/missheyo/p/10240132.html
Copyright © 2020-2023  润新知