Create a new user registration form (VIPRegistration.cs):
The user registration Form (VIPRegistration.cs) detailed code is as follows:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten usingSystem.Data.SqlClient; One usingSystem.Configuration; A - namespacemember Management System - { the Public Partial classVipregistration:form - { - Publicvipregistration () - { + InitializeComponent (); - } + A at //Submit Button - Private voidBtnok_click (Objectsender, EventArgs e) - { - - stringConnStr = configurationmanager.connectionstrings["Str"]. ConnectionString; -SqlConnection conn =NewSqlConnection (CONNSTR); in stringsql =string. Format ("Select vUserName from Vipaccount where Vusername= ' {0} '", txtName.Text); -SqlCommand cmd =NewSqlCommand (SQL, conn); to Conn. Open (); +SqlDataReader sda=cmd. ExecuteReader (); - the if(TxtName.Text.Trim () = ="") * { $lblname.text="user name cannot be empty";Panax Notoginseng return; - } the Else if(TxtPwd.Text.Trim () = =""|| TxtPwdConfirm.Text.Trim () = ="") + { ALblpwd.text ="The password cannot be empty"; the return; + } - Else if(TxtPwdConfirm.Text.Trim ()! =TxtPwd.Text.Trim ()) $ { $Lblpwdconfirm.text ="two times the password input is different, please confirm and then lose"; - return; - } the Else if(SDA. Read ()) - {WuyiLblname.text ="user name already exists, please re-enter"; the return; - } Wu Else - { About Conn. Close (); $SqlConnection Conninsert =NewSqlConnection (CONNSTR); - stringInsertsql =string. Format ("INSERT INTO Vipaccount (VUSERNAME,VUSERPWD) VALUES (' {0} ', ' {1} ')", txtname.text,txtpwd.text); -SqlCommand Cmdinsert =NewSqlCommand (Insertsql, conninsert); - Conninsert. Open (); A intn =Cmdinsert. ExecuteNonQuery (); + if(n = =0) the { -MessageBox.Show ("registration failed, please re-enter"); $ } the Else the { theMessageBox.Show ("Registration Successful"); the } - Conninsert. Close (); in the } the //Conn. Close (); About } the the //back to main menu the Private voidBtnback_click (Objectsender, EventArgs e) + { -Vipmain VM =NewVipmain (); the VMs. Show ();Bayi This. Hide (); the } the - Private voidVipregistration_load (Objectsender, EventArgs e) - { theLblname.text =""; theLblpwd.text =""; theLblpwdconfirm.text =""; the } - the } the}
The main interface form (VIPMain.cs) adds a new button:
User Registration Button Code:
1 Private void Btnregistration_click (object sender, EventArgs e)2 {3 New vipregistration (); 4 Vrn. Show (); 5 This . Hide (); 6 }
C#_ member Management System: Development Five (user registration)