• C#_会员管理系统:开发五(用户注册)


    创建一个新的用户注册窗体(VIPRegistration.cs):

    用户注册窗体(VIPRegistration.cs)详细代码如下:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 using System.Data.SqlClient;
    11 using System.Configuration;
    12 
    13 namespace 会员管理系统
    14 {
    15     public partial class VIPRegistration : Form
    16     {
    17         public VIPRegistration()
    18         {
    19             InitializeComponent();
    20         }
    21 
    22 
    23         //提交按钮
    24         private void btnOK_Click(object sender, EventArgs e)
    25         {
    26             
    27             string connstr = ConfigurationManager.ConnectionStrings["str"].ConnectionString;
    28             SqlConnection conn = new SqlConnection(connstr);
    29             string sql = string.Format("select vusername from VipAccount where vUserName='{0}' ",txtName.Text);
    30             SqlCommand cmd = new SqlCommand(sql, conn);
    31             conn.Open();
    32             SqlDataReader sda=cmd.ExecuteReader();
    33 
    34             if (txtName.Text.Trim() == "")
    35             {
    36                 lblName.Text="用户名不能为空";
    37                 return;
    38             }
    39             else if (txtPwd.Text.Trim() == ""|| txtPwdConfirm.Text.Trim()=="")
    40             {
    41                 lblPwd.Text = "密码不能为空";
    42                 return;
    43             }
    44             else if (txtPwdConfirm.Text.Trim()!= txtPwd.Text.Trim())
    45             {
    46                 lblPwdConfirm.Text = "两次密码输入不同,请确认后再输";
    47                 return;
    48             }
    49             else if (sda.Read())
    50             {
    51                 lblName.Text = "用户名已存在,请重新输入";
    52                 return;
    53             }
    54             else
    55             {
    56                 conn.Close();
    57                 SqlConnection conninsert = new SqlConnection(connstr);
    58                 string insertsql = string.Format("insert into VipAccount(vUserName,vUserPwd) values('{0}','{1}')",txtName.Text,txtPwd.Text);
    59                 SqlCommand cmdinsert = new SqlCommand(insertsql, conninsert);
    60                 conninsert.Open();
    61                 int n = cmdinsert.ExecuteNonQuery();
    62                 if (n == 0)
    63                 {
    64                     MessageBox.Show("注册失败,请重新输入");
    65                 }
    66                 else
    67                 {
    68                     MessageBox.Show("注册成功");
    69                 }
    70                 conninsert.Close();
    71 
    72             }
    73             //conn.Close();
    74         }
    75 
    76         //返回主菜单
    77         private void btnBack_Click(object sender, EventArgs e)
    78         {
    79             VIPMain vm = new VIPMain();
    80             vm.Show();
    81             this.Hide();
    82         }
    83 
    84         private void VIPRegistration_Load(object sender, EventArgs e)
    85         {
    86             lblName.Text = "";
    87             lblPwd.Text = "";
    88             lblPwdConfirm.Text = "";
    89         }
    90         
    91     }
    92 }

    主界面窗体(VIPMain.cs)添加一个新的按钮:

    用户注册按钮代码:

    1         private void btnRegistration_Click(object sender, EventArgs e)
    2         {
    3             VIPRegistration vrn = new VIPRegistration();
    4             vrn.Show();
    5             this.Hide();
    6         }
  • 相关阅读:
    吴太银:华为消费者云服务Cassandra使用场景与最佳实践
    使用FileZilla连接Linux
    debug 与 release
    删除cocos2dx项目模版
    [转]C/C++控制台输出时设置字体及背景颜色
    iphone调试的一些问题
    [转]Refactoring Game Entities with Components
    使用QT + cocos2dx制作工具
    [转]printf输出字体颜色
    Error: No module named books
  • 原文地址:https://www.cnblogs.com/start-from-scratch/p/5426357.html
Copyright © 2020-2023  润新知