'Sending order to database- Till/Kitchen View Restaurant Ordering System

I'm creating a restaurant ordering system and cant figure out how to send the completed order back into the access database and across to the kitchen view form. It creates buttons for the user to choose which items they want from the database. I need it to get the highest orderID from the listview where the order is and loop through each item getting the MenuID, time and tableno from the till view. Can answer any questions as may not have explained it clearly. Here is some of the code for the till view form. Any help would be appreciated.

    public TillView()
        {
            InitializeComponent();
        }

        
        private void Form1_Load(object sender, EventArgs e)
        {
            
            int i = 0;
            clsDBConnector dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string sqlStr;
            dbConnector.Connect();
            sqlStr = "SELECT description, CatID FROM tblCategory";
            dr = dbConnector.DoSQL(sqlStr);
            


            while (dr.Read())
            {
                Button btn = new Button();
                btn.BackColor = Color.Lime;
                btn.ForeColor = Color.Black;
                btn.Font = new Font(btn.Font.Name, 12, FontStyle.Bold);
                btn.Size = new Size(110, 100);
                btn.Visible = true;
                btn.Tag = dr[1].ToString();
                btn.Text = dr[0].ToString();
                btn.Name = "btn_ " + i;
                i++;
                btn.Click += Btn_Click;
                flpCategory.Controls.Add(btn);
            }
            dbConnector.Close();

            string time = DateTime.Now.ToString("t");
            lblTime.Text = ($"{""}" + time);
            lblDate.Text = (DateTime.Now.ToString("dd/MM/yyyy"));
            lblServer.Text = Login.server;
            
            

        }

        private void Btn_Click(object sender, EventArgs e)
        {
            flpItem.Controls.Clear();
            int i = 0;
            int catID = Convert.ToInt32((sender as Button).Tag.ToString());
            clsDBConnector dbConnector = new clsDBConnector();
            OleDbDataReader dr;
            string sqlStr;
            dbConnector.Connect();
            sqlStr = "SELECT description, CatID, menuID, cost FROM tblMenu where catid = " + catID;
            dr = dbConnector.DoSQL(sqlStr);

            while (dr.Read())
            {
                string Description = Convert.ToString((sender as Button).Tag);
                int MenuID = Convert.ToInt32((sender as Button).Tag.ToString());
                int Cost = Convert.ToInt32((sender as Button).Tag.ToString());
                Button bttn = new Button();
                bttn.BackColor = Color.LightSkyBlue;
                bttn.ForeColor = Color.Black;
                bttn.Size = new Size(105, 95);
                bttn.Visible = true;
                bttn.Tag = dr[2].ToString() + "-" + dr[3].ToString() ;

                bttn.Text = dr[0].ToString();
                bttn.Name = "bttn_ " + i;
                i++;
                bttn.Click += bttn_Click;
                flpItem.Controls.Add(bttn);

            }
            dbConnector.Close();
        }
private void bttn_Click(object sender, EventArgs e)
        {
            string theTag = (sender as Button).Tag.ToString() ;
            string[] theTagArray = theTag.Split('-');
            int MenuID = Convert.ToInt32(theTagArray[0]);
            double cost = Convert.ToDouble(theTagArray[1]);
            //lstVOrder.Items.Add(MenuID.ToString());
            string Description = Convert.ToString(((sender as Button).Text));
            lstVOrder.Font = new Font(Font.Name, 12);
            lstVOrder.Items.Add(Description.ToString());
            lstVOrder.Items[lstVOrder.Items.Count - 1].SubItems.Add(cost.ToString("N2"));
            lstVOrder.Items[lstVOrder.Items.Count - 1].SubItems.Add("");
            lstVOrder.Items[lstVOrder.Items.Count - 1].SubItems.Add(MenuID.ToString());
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source