And say this is still a registered login winform window procedure, "bring up the user as a class" "object-oriented"
What is the meaning of this sentence? The following is my first design code
The namespace APP
{
Public partial class Form1: Form//Form1 is inherited Form a class
{
Public _click ()//constructor can't private
{
InitializeComponent ();//initialize the form
}
Private void Form1_Load (object sender, EventArgs e)
{
}
Private void button1_Click (object sender, EventArgs e)//trigger event for the button1_Click
{
If (string. IsNullOrEmpty (textBox1. Text + textBox2. Text))//determine whether null value
MessageBox. Show (" enter the user name and password ", "warning");
The else
{
SqlConnection conn=new SqlConnection (" Data source=(local); Initial Catalog=log; Integrated Security=True ");//instantiate the conn variable, specifies the database connection parameters, do not need the user name and password, namely the Windows authentication mode
Conn. The Open ();//open the conn connection database
SqlCommand CMD=new SqlCommand (" select * from the log where user name='" + textBox1. Text. The Trim () + "' and password='" + textBox2. Text. The Trim () + "' ", conn);//the sqlcommand object allows you to specify on the database to add and delete, database connection object, the execution of database statements
SqlDataReader SDR=CMD. ExecuteReader ();//ExecuteReader method is used to create SqlDataReader object type
The SDR. The Read (); Read data from the database//
If (SDR) HasRows)//use HasRows attribute judgment whether there is data in the results
MessageBox. Show (" landing successful ", "prompt");
The else
MessageBox. Show (" the user name or password is wrong ", "warning");
Conn. Close ();
}
}
Private void textBox1_TextChanged (object sender, EventArgs e)
{
}
Private void label1_Click (object sender, EventArgs e)
{
}
Private void checkBox1_CheckedChanged (object sender, EventArgs e)
{
If (checkBox1. Checked)//default to true
{
TextBox2. PasswordChar='\ 0';
}
The else
{
TextBox2. PasswordChar='*';
}
}
Private void textBox2_TextChanged (object sender, EventArgs e)
{
}
Private void button2_Click (object sender, EventArgs e)
{
Strings str1=textBox1. Text;//read the user name and password
String str2=textBox2. Text;
Int a=0;//check the user name, password complexity
int b=0;
Int c=0;
Int x=0;
Int y=0;
Int z=0;
Int I=textBox1. Text. Length;
Int j=textBox2 Text. Length;
For (int m=0; M & lt; Str1. Length; M++)
{
Char cha1=str1 [m].
If (char. IsLetter (cha1))//whether for letter
{
a++;
}
The else
{
If (char. IsDigit (cha1))//whether to digital
{
B++;
}
The else
If (char. IsPunctuation (cha1))//for punctuation
{
c++;
}
}
}
For (int n=0; N & lt; Str2. Length; N++)
{
Char cha2=str2 [n].
If (char. IsLetter (cha2))
{
x++;
}
The else
If (char. IsDigit (cha2))
{
Y++;
}
The else
If (char. IsPunctuation (cha2))
{
Z++;
}
}
If (a==0 | |==0 b | | c==0 | |==0 x | | y==0 | | z==0 | | I & lt; 6 | | I & gt; 15 | | j & lt; 10 | | j & gt; 15 | | Regex. IsMatch (str1 + str2, "[^ a zA - Z0-9 _]"))//regular expression used to check whether the string and the specified expression match
{
MessageBox. Show (" user name length in 6-15, password length in 10-15, \ n only Numbers, letters, underline, \ n the user name and password must contain Numbers, letters, underline, ", "warning");
}
The else
{
SqlConnection conn=new SqlConnection (" Data Source=(local); Initial Catalog=log; Integrated Security=True ");
Conn. The Open ();
SqlCommand CMD=new SqlCommand (" select * from the log where user name='" + textBox1. Text. The Trim () + "' ", conn);
SqlDataReader SDR=CMD. ExecuteReader ();
The SDR. The Read ();
If (SDR) HasRows)
{
MessageBox. Show (" the user name already exists ", "warning");
}
The else
{
The SDR. The Close ();
String myInsert="insert into the log (username, password) values ('" + textBox1. Text + "', '" + textBox2. Text +") ";
SqlCommand myCom=new SqlCommand (myInsert, conn);//create a SqlCommand object type
MyCom. ExecuteNonQuery ();
Conn. Close ();
Conn. The Dispose ();//shut down and release the object, the next call to recreate the conn
MessageBox. Show (" registration ");
}
}
}
Private void button3_Click (object sender, EventArgs e)//close program
{
Close ();
}
}
}
Also please bosses detailed answer, I am not really familiar with c #, best code instructions, thank you
CodePudding user response:
Have you made object is calledCodePudding user response: