The à la carte module is an important part of the restaurant management system, which has two functions: one is to save the dishes ordered by the guests, and the other is to remove the order.
I. A-la-carte design
First of all, the restaurant has all the dishes stored in the database, in order to invoke the table in the Database menu information table, a la carte interface to have the attributes should be consistent with the menu information table, menu number, cuisine, list price, number of servings, discounts are one by one corresponding, and then the main points of the selected dishes, add to the order form. A la carte from the new founding that place, the à la carte interface as shown in:
After selecting the desired dish, click on the Confirmation button to display the selected dish below and save it to the database, storing the code as follows:
stringOrdnum =Txb_ordernum. Text; stringOrderxi =Strcaixi; stringOrdername =Txb_ordername. Text; floatOrderperprice =float. Parse (Txb_perprice. Text); floatOrderDiscount =float. Parse (Txb_discount. Text); intOrdertotalnum =Convert.ToInt32 (txb_totalnum. Text); //save specific information about the selected dishes in the specific order Information table stringstrconn =@"Data Source=.;i Nitial catalog=restaurant;integrated Security=sspi; "; SqlConnection Conn=NewSqlConnection (strconn); Conn. Open (); stringsqlcom =string. Format (@"insert into specific à la carte information (menu number, cuisine, dish name, number of copies, unit price, discount, table position, status) values (' {0} ', ' {1 } ', ' {2} ', ' {3} ', ' {4} ', ' {5} ', ' {6} ', ' No Checkout ')", Ordnum, Orderxi, Ordername, Ordertotalnum, Orderperprice, orderdiscount,desknum); SqlCommand cmd=NewSqlCommand (sqlcom, conn); Cmd. ExecuteNonQuery (); Conn. Close ();
The code for displaying information in the ListView control is as follows:
// Displays the information of the selected dish in the ListView control New ListViewItem (); = Ordnum; It. SubItems.Add (ORDERXI); It. SubItems.Add (ordername); It. SubItems.Add (Txb_perprice. Text); It. SubItems.Add (Txb_discount. Text); It. SubItems.Add (Txb_totalnum. Text); LISTVIEW1.ITEMS.ADD (it);
In the course of choosing a dish, if the guest has chosen the wrong or do not want the dish, it must be deleted from the database, and in the following table does not show, its specific code:
if(ListView1.SelectedItems.Count >0) { stringOrdernum = listview1.selecteditems[0]. subitems[0]. Text; stringOrdername = listview1.selecteditems[0]. subitems[2]. Text; stringstrconn =@"Data Source=.;i Nitial catalog=restaurant;integrated Security=sspi; "; SqlConnection Conn=NewSqlConnection (strconn); Conn. Open (); stringSqlcommond =string. Format (@"Delete from specific ordering information where (menu number = '"+ Ordernum +"') and (dish name = '"+ Ordername +"')"); //establishes the SqlCommand object, is responsible for the SQL statement execution and the stored procedure call;SqlCommand cmd =NewSqlCommand (Sqlcommond, conn); //operations on results returned after SQL or stored procedure executionSqlDataAdapter da =NewSqlDataAdapter (); Da. SelectCommand=cmd; Cmd. ExecuteReader (); MessageBox.Show ("successfully removed from the database"); Conn. Close (); //Delete Selection intLisnum =listView1.Items.IndexOf (Listview1.focuseditem); ListView1.Items.Remove (Listview1.items[lisnum]); } Else{MessageBox.Show ("Please select the dish you want to delete! "); }
Finally, save all the selected dishes in the following code:
stringstrconn =@"Data Source=.;i Nitial catalog=restaurant;integrated Security=sspi; "; SqlConnection Conn=NewSqlConnection (strconn); Conn. Open (); stringsqlcom =string. Format (@"INSERT INTO order information (menu number, table location, number of diners, service staff) values (' {0} ', ' {1} ', ' {2} ', ' {3} ')", Txb_ordernum. Text, Desknum,peocount, servername); SqlCommand cmd=NewSqlCommand (sqlcom, conn); Cmd. ExecuteNonQuery (); MessageBox.Show ("Save order information successfully!! "); Conn. Close (); This. Close (); Opform. Close ();
Restaurant management of a la carte