C # simple movie record management system: developer 5 [User Registration]

Source: Internet
Author: User

Overview

To facilitate system login, we manually added the user name and password to the database, and did not implement user registration in the system. in this phase, we will work together to implement the user registration function.

 

Principle

The principle is very simple. First, determine whether the user name already exists in the Database. Execute the SQL select statement to obtain the user name in the text box, then, use SqlDataReader to read the data in the database row by row and determine whether the same user name already exists in the database. if the password already exists, registration is prohibited. If the password does not exist, the user's password and Password confirmation are judged separately. If both meet the conditions (two identical passwords are entered ), execute the SQL insert statement to insert the registered user name and password to the database.

 

First, we need to add a button to jump to the user registration form on the system main interface.

User Registration name: tsbRegistration

 

Add the following code under the click event of this button (used for form jump ).

Private void tsbRegistration_Click (object sender, EventArgs e) {// a new user registration form object FrmRegistration registration = new FrmRegistration (); // displays the user registration form registration. show (); // hide the current form (Main Interface) this. hide ();}

Then, we design the user registration form.

Create a new user registration form FrmRegistration. cs interface design is as follows

Text Box Username: txtUid password name: txtPwd Password Confirmation name: txtPwdConfirm

Enter the user password on the right of the text box. The user name prompt is "name: lblUidMsg". The password prompt is "name: lblPwdMsg". The Password Confirmation is "name: lblPwdConfirmMsg ".

Button Registration name: btnOK return name: btnBack

User Registration Form code

Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; using System. configuration; using System. data. sqlClient; /*************************************** ******************* Author: soFlash-blog Park http://www.cnblogs.com/longwu ** Description: FrmRegistration. cs User Registration Form ***************************** * ***********************/Namespace movie record management system {public partial class FrmRegistration: form {public FrmRegistration () {InitializeComponent () ;}// connection string to obtain the configuration file App. the string "str" static string connStr = ConfigurationManager in config. connectionStrings ["str"]. connectionString; private void btnOK_Click (object sender, EventArgs e) {// otherwise, determine whether the current user name exists in the Database // use the SQL select statement to select the user name string SQL = in the database based on the text content in the user text box "Select MUserName from MovieAccount where MUserName = '" + txtUid. text + "'"; // create an SQL database connection SqlConnection conn = new SqlConnection (connStr ); // use the SQL cmd command to load the SQL query statement and connect to the database SqlCommand cmd = new SqlCommand (SQL, conn); // open the database connection conn before executing the operation. open (); // use SqlDataReader to read SqlDataReader row-by-row SqlDataReader sdr = cmd from the data that executes the command in cmd. executeReader (); // if data is read, the user name if (sdr) entered in the text box already exists in the database. read () {// if you Read the same user name, the system prompts that the user name already exists. LblUidMsg. Text = "the user name already exists. Please enter it again! "; Return;} // if the user name does not exist, determine whether the user name and password are empty else if (txtUid. text. trim () = "") {// if the user name is not empty, assign the prompt statement to the label box and lblUidMsg on the form. text = "user name cannot be blank! ";}// Determine whether the password is empty else if (txtPwd. Text. Trim () =" ") {// Similarly, lblPwdMsg. Text =" the password cannot be blank! "; // Clear the content of lblUidMsg in the user name prompt box at the same time. text = "";} // determines whether the new password is null. else if (txtPwdConfirm. text. trim () = "") {// Similarly, lblPwdConfirmMsg. text = "the verification password cannot be blank! "; // Clear both the user name prompt box and the content of the first Password Input prompt box lblUidMsg. text = ""; lblPwdMsg. text = "";} // determines whether two passwords are entered in the same else if (txtPwd. text. trim ()! = TxtPwdConfirm. Text. Trim () {// Similarly, lblPwdMsg. Text = "the two passwords must be the same! "; LblPwdConfirmMsg. Text =" Please try again! "; Return;} else // if the above test is performed, insert the account password to the database. {// clear all the above label boxes and the lblUidMsg prompt is displayed. text = ""; lblPwdMsg. text = ""; lblPwdConfirmMsg. text = ""; // if the user name exists in the Database, close the database connection (Resource Saving) conn. close (); // use the SQL data insert statement string sqlInsert = "insert into MovieAccount (MUserName, MUserPwd) values (@ MUserName, @ MUserPwd )"; // use an SQL parameter array to load the data SqlParameter [] param = {new SqlParameter ("@ MUserName", txtUid. text), new SqlPa Rameter ("@ MUserPwd", txtPwd. text)}; // use sqldatabase to connect to SqlConnection connInsert = new SqlConnection (connStr); // use the SQL command to load the SQL query statement and sqldatabase connection SqlCommand cmdInsert = new SqlCommand (sqlInsert, connInsert); // re-open the data connection and execute the insert data operation connInsert. open (); // use the cmd command to add all the parameters cmdInsert. parameters. addRange (param); // defines an integer variable used to receive the Command run by cmd (the return value of the ExcuteNonQuery () method of cmd is an integer) int n = cmdInsert. executeNonQuery (); // judge Whether the value is null. if it is null, data insertion fails. if (n = 0) {MessageBox. Show ("registration failed !, Re-enter "); // If the insertion fails, the operation will not continue. return;} else {// otherwise, the data is inserted successfully. MessageBox. Show (" registration successful! ");} // Close the database connection connInsert. close () ;}// return the main form private void btnBack_Click (object sender, EventArgs e) {// a new main form object FrmMain main = new FrmMain (); // jump to the main form main. show (); // hide the current form this. hide ();}}}

The Code has been written. Let's test the user registration function.

 

 

 

 

 

 

 

In this way, our user registration function is complete. In the next phase, we will learn the most common feature in the information management system-data search.

 

Add source code

MovieRecordManagementSystem05.zip

Related Recommendations [click here to view the Directory]
  • C # simple movie record management system: developer 1 [user logon]
  • C # simple movie record management system: Development 2 [add, delete, modify, and query]
  • C # simple movie record management system: Development 3 [Password modification]
  • C # simple movie record management system: Development 4 [log view]
  • C # simple movie record management system: Development 6 [data search]
  • C # simple movie record management system: Development 7 [User Classification]
  • C # simple movie record management system: Development 8 [data backup]
  • C # simple movie record management system: Development 9 [data recovery]
  • C # simple movie record management system: Conclusion [permission Assignment]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.