コード例 #1
0
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Changing the tab (table) essentially assigns the selectedTable variable

            // trap door the event if we are midway through an order or if the table
            // has already ordered

            if (newOrder != null)
                return;

            selectedSeat = null;

            TabControl selectedTab = (TabControl)sender;

            selectedTable = tables[selectedTab.SelectedIndex];

            // trapdoor the event if the table has already ordered
            // this has to be done after the selectedTable var is
            // updated or a subtle bug is introduced

            if (selectedTable.OrderPlaced == true)
                return;

            // The selected table has its seats added to the 'seated' arraylist
            // for the table object. The seats are disabled in preparation
            // for when the start new order button is hit

            foreach (Control ctrl in tabControl1.SelectedTab.Controls)
            {
                if (ctrl is Seat)
                {
                    if (selectedTable.seated.Count < 4)
                    {
                        selectedTable.seated.Add((Seat)ctrl);
                        ctrl.Enabled = false;
                    }
                }
            }
            selectedTable.Waiter = labelWaiter.Text;

            // a new order may now be raised

            buttonStartOrder.Enabled = true;
        }
コード例 #2
0
        private void initObjects()
        {
            // We create an object to manage all the local database interactions

            ldp = new LocalDataProcessor();
            wsp = new WebServiceProcessor();

            // Create 10 tables

            for (int i = 0; i < 10; i++)
            {
                tables[i] = new Table(i);
            }

            selectedTable = tables[0];

            // to handle seat color changes the table class has a
            // an arraylist called 'seated' full of seat objects
            // they are added here

            foreach (Control ctrl in tabControl1.TabPages[0].Controls)
            {
                if (ctrl is Seat)
                {
                    if (selectedTable.seated.Count <= 4)
                        selectedTable.seated.Add((Seat)ctrl);
                }
            }

            // What meal is unavailable today? We read in the first
            // entry from a flat 'UnavailableMeals.txt' file here

            string getLocation = Directory.GetCurrentDirectory();

            FileStream fs =
                new FileStream(getLocation + "\\UnavailableMeals.txt", FileMode.OpenOrCreate, FileAccess.Read);
            StreamReader sr = new StreamReader(fs);

            string offMeals = sr.ReadLine();
            int offMealNo = int.Parse(offMeals.Substring(0,1));

            sr.Close();

            // write out the stream without the off meal

            fs = new FileStream(getLocation + "\\UnavailableMeals.txt", FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);

            sw.Write(offMeals.Substring(1));
            sw.Close();
            fs.Close();

            // and notify the user

            listBoxSummary.Items.Add(listBoxMeals.Items[offMealNo] + " is unavailable");

            // The meal must now be taken off the menu

            listBoxMeals.Items.RemoveAt(offMealNo);
        }