The most important is to connect to the database, the connection database is all encapsulated in the SqlHelper class, the following code is to create a table
public form1 () { initializecomponent (); string connectionString = "data source=localhost;initial catalog=sanhui; persist security info=true; user id=sa; Password=sa "; //connection Database is sanhui SqlHelper.connectionString = connectionString; string CommandText = "if objectproperty ( object_ ID (' table1 '), ' istable ') = 1 print ' table1 already exists ' else create table table1 ([Id] char] not null primary key, [intime] char (255) NOT NULL , [outtime] char (255) not null, [name] char (255) Not null, [idcard] char ( not null, [allcost] char) (255) NOT Null, [discount] char (255) not null, [cost] char (255) NOT NULL) "; //Verify that the table table1 exists and does not exist create sqlhelper.executenonquery ( System.data.commandtype.text, commandtext, null); }
The above is four tabs, currently only "Passenger information register" and "View History" did the preliminary function. The code for these two interfaces is described in detail below
1. The first is to insert the DateTimePicker space, you can choose the passenger check-in time, * * * * Month * * Day, sometimes need to be accurate to a few points, so next to add ComboBox drop-down list, you can choose a few. Check-in time is displayed in a TextBox space, in order to avoid errors, you must select the input and not enter the date manually, so change the property readonly to True. To enable the TextBox to display * * * * * * * points, add the following code to the Form.cs:
private void Datetimepicker1_valuechanged (object sender, EventArgs e)
{
Intime.text = dateTimePicker1.Value.Date.ToString ("yyyy/mm/dd") + "" "+ comboBox1.SelectedItem.ToString () +" point ";
}
The function of departure time is the same as the function design of check-in time.
The properties on the right are displayed in a TextBox. The ID card must be guaranteed to 18 digits. Set in the database.
String commandtext = "IF objectproperty (object_id (' table1 '), ' istable ') = 1 print ' table1 already exists ' else CREATE TABLE table1 ([I D] Char (+) NOT null PRIMARY KEY, [Intime] char (255) is not NULL, [Outtime] char (255) is not NULL, [Name] char (255) Not null, [idcard] Char (+) not NULL, [allcost] char (255) is not NULL, [Discount] char (255) is not NULL, [cost] char (255) is not NULL) ";
Since all information is required, click "Add Information" and have the following code:
Private void button1_click_1 (object sender, eventargs e) { try { if (Intime.Text.Trim () != "" & & outtime.text.trim () != " && username.text.trim () != " " && idcard.text.trim () != " && allcost.text.trim () ! = "" && discount.text.trim () != "" && Cost.Text.Trim () != "" &amP;& idcard.text.trim (). LENGTH==18) { string id = datetime.now.tostring ("Yyyy-mm-dd hh:mm:ss.fff"); string commandtext = "Insert into table1 values" (' + id + ') , ' + Intime.Text + ', ' + Outtime.Text + ' ', ' ' + username.text + "', '" + Idcard.Text + "', '" + allcost.text + "', '" + Discount.Text + "', '" + Cost.Text + "')"; //insert this information in table 1 &nBsp; sqlhelper.executenonquery (system.data.commandtype.text, commandtext, NULL); messagebox.show ("added successfully! "); double a = convert.todouble (Cost.Text.Trim ()); messagebox.show (A. ToString ()); } else messagebox.show ("Incomplete information");             } catch (EXCEPTION E1) { messagebox.show ("Add failed! "+e1. ToString ()); //Displays the error message } }
It's easier to empty.
private void Button2_Click (object sender, EventArgs e) {intime.text = ""; Outtime.text = ""; Username.text = ""; Idcard.text = ""; Allcost.text = ""; Discount.text = ""; Cost.text = ""; }
due to real receipts = Receivable amount-discount. This automatically calculates the paid amount
private void allcost_textchanged (Object sender, eventargs e) //of the amount receivable { if (Discount.Text.Trim () == " ") discount.text = "0"; //Default to 0 if (Allcost.Text.Trim () == "") Allcost.Text = "0"; Cost.Text = (Convert.todouble (Allcost.Text.Trim ()) &Nbsp; - convert.todouble (Discount.Text.Trim ())). ToString (); } Private void discount_textchanged (object sender, eventargs e) { if ( Discount.Text.Trim () == "") Discount.Text = "0"; if (Allcost.Text.Trim () == "") Allcost.Text = "0"; Cost.Text = (Convert.todouble (Allcost.Text.Trim ()) &nbSp; -convert.todouble ( discount.text.trim ())). ToString (); }
2. The function of viewing the page is described below
This function has not been successful, not for the time being, write again later
A list of hotel stays registered in C #