first, the specific code
Class Code
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Windows.Forms;namespaceszys{classClass2 { Public intSum; Public intAnswer {Get{returnSum;} } Public intMax (intN1,intN2,CharYunsuanfu) { if(Yunsuanfu = ='+') { returnSum = n1 +N2; } Else if(Yunsuanfu = ='-') { if(N1 >n2) { returnSum = N1-N2; } Else{MessageBox.Show ("The first number is greater than the second number! "); } } Else if(Yunsuanfu = ='/') { if(N2 = =0|| N2 <0) {MessageBox.Show ("the denominator cannot be 0 and greater than 0! "); } Else { returnSum = n1/N2; } } Else if(Yunsuanfu = ='*') { returnSum = N1 *N2; } returnSum; } } }
Form1 Code
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Data.SqlClient;namespaceszys{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Public Static intright =0; Public Static intCount =0; Private intT; Private voidButton5_click (Objectsender, EventArgs e) { stringStrcon =@"Data Source=.;i Nitial catalog=jisuanqi;integrated security=true"; SqlConnection Sqlcon=NewSqlConnection (Strcon); Try{Sqlcon. Open (); stringSLT =@"INSERT INTO Jisuan (number1,operator,number2)"+"values ('"+ TextBox1.Text +"', '"+ Textbox4.text +"', '"+ TextBox2.Text +"')"; SqlCommand cmd=NewSqlCommand (SLT, Sqlcon); Cmd. ExecuteNonQuery (); MessageBox.Show ("A successful quiz! "); } Catch(Exception ex) {MessageBox.Show ("failure of the quiz"+Ex. ToString ()); } sqlcon. Close (); Textbox1.clear (); Textbox4.clear (); Textbox2.clear (); } Private voidButton2_Click (Objectsender, EventArgs e) {textbox1.enabled=false; Textbox2.enabled=false; Textbox4.enabled=false; Textbox1.backcolor=Color.yellow; Textbox4.backcolor=Color.yellow; Textbox2.backcolor=Color.yellow; Textbox3.backcolor=Color.yellow; stringStrcon =@"Data Source=.;i Nitial catalog=jisuanqi;integrated security=true"; SqlConnection Sqlcon=NewSqlConnection (Strcon); inti =1; Sqlcon. Open (); stringSLT =@"SELECT * from Jisuan"; SqlCommand cmd=NewSqlCommand (SLT, Sqlcon); SqlDataAdapter da=NewSqlDataAdapter (CMD); DataSet DS=NewDataSet (); Da. Fill (DS); DataTable DT= ds. tables[0]; TextBox1.Text= dt. rows[i][0]. ToString (); Textbox4.text= dt. rows[i][1]. ToString (); TextBox2.Text= dt. rows[i][2]. ToString (); Sqlcon. Close (); } Private voidTextbox3_mouseclick (Objectsender, MouseEventArgs e)//timing;{label3. Text=t.tostring (); Timer1. Enabled=true; Timer1. Interval= +; Timer1. Start (); } Private voidTimer1_Tick (Objectsender, EventArgs e) {T= T +1; Label3. Text=t.tostring (); } Private voidButton3_Click (Objectsender, EventArgs e) {MessageBox.Show ("altogether"+ Label3. Text +"seconds"); Form2 Frm2=NewForm2 (); Frm2. ShowDialog (); } Private voidButton4_Click (Objectsender, EventArgs e) { intA =int. Parse (TextBox1.Text); intb =int. Parse (TextBox2.Text); Char C=Convert.tochar (TextBox4.Text.Trim ()); Class2 Con=NewClass2 (); Con. Max (A, B, c); if(Con. Answer = =int. Parse (TextBox3.Text)) {MessageBox.Show ("Congratulations, little one! Answer right! "); Right++; Count++; } Else{MessageBox.Show ("answer the wrong, continue to refuel! Kids"); Count++; } textbox1.clear (); Textbox2.clear (); Textbox3.clear (); Textbox4.clear (); } }}
Form2 Code
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceszys{ Public Partial classForm2:form { PublicForm2 () {InitializeComponent (); } Private voidForm2_load (Objectsender, EventArgs e) {TextBox1.Text=Form1.Count.ToString (); TextBox2.Text=Form1.right.ToString (); Textbox4.text= ((Form1.right/(Double) (Form1.count)) * -). ToString () +"%"; } } }
second, the test
Iii. Summary
using the database to save the problem is open is to increase the database query, first build a table, column name has the first number, the operator, the second number, and then write an additional query statement.
Calculator for the database