3 Replies - 420 Views - Last Post: 13 June 2013 - 11:17 AM Rate Topic: -----

#1 CansuD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-June 13

Problem is the Table Reservation does not work on RestaurantInfoSystem

Posted 12 June 2013 - 01:17 AM

This is the Restaurant Information system and includes the table reservation.I attached the form image.When i click the button and then reserve there is no action . When i cliclk the show Reservation every time the Free table is 20 and others 0.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RestInfoSys
{
    public partial class Masalar : Form
    {
        public Masalar()
        {
            InitializeComponent();
        }
        int gosterilecekTable = 0;

        private void tsMasaOlustur_Click(object sender, EventArgs e)
        {
            if (flowLayoutPanel2.Controls.Count == 20)
            {
                MessageBox.Show("The Tables are already created...");
                    return;
            }
            for (int i = 0; i < 20; i++)
            {
                Button btn = new Button();
                btn.Name = "btn_" + i;
                btn.Text = "Table " + i;
                btn.Width = 113;
                btn.Height = 71;
                btn.BackColor = Color.LightBlue;
                flowLayoutPanel2.Controls.Add(btn);
                MasaDurum durum = new MasaDurum();
                durum.DoluMu = false;
                durum.AlinanYemekler = "";
                durum.MasaNo = i;
                btn.Tag = durum;
                btn.Click += new EventHandler(btn_Click);
             }
            masaSayisiGuncelle();
        }
        void btn_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            masaOperation op = new masaOperation();
            op.ShowDialog();
            if (op.Tag == "1")
            {
                if (btn.BackColor == Color.Red)
                {
                    MessageBox.Show("The table has already been filled!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                btn.BackColor = Color.Red;
            }
            if (op.Tag == "2")
            {
                if (btn.BackColor == Color.LightBlue)
                {
                    MessageBox.Show("The table has already been Empty!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                btn.BackColor = Color.LightBlue;
            }
            if (op.Tag == "3")
            {
                if (btn.BackColor == Color.Purple)
                {
                    MessageBox.Show("The table has already been Reserved!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                btn.BackColor = Color.Purple;
            }
            masaSayisiGuncelle();
        }
        public void masaSayisiGuncelle()
        {
            int bosMasaSayisi = 0;
            int reservedMasaSayisi = 0;
            int doluMasaSayisi = 0;
            foreach (Control c in flowLayoutPanel2.Controls)
            {
                Button btn = (Button)c;
                if (btn.BackColor == Color.Purple)
                {
                    reservedMasaSayisi++;
                }
                if (btn.BackColor == Color.Red)
                {
                    doluMasaSayisi++;
                }
                if (btn.BackColor == Color.LightBlue)
                {
                    bosMasaSayisi++;
                }

            }
            lblBosMasaSayisi.Text = bosMasaSayisi.ToString();
            lblDoluMasaSayisi.Text = doluMasaSayisi.ToString();
            lblReservedMasaSayisi.Text = reservedMasaSayisi.ToString();
        }
        private void Masalar_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult dr = MessageBox.Show(" Are you sure to close the tables", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.No)
            {
                e.Cancel = true;
            }
        }

        private void linkLabel1Forward_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
        {
            foreach (Control c in flowLayoutPanel2.Controls)
            {
                Button btn = (Button)c;
                btn.Visible = false;
            }
            int masaSayisi = flowLayoutPanel2.Controls.Count;
            for (int i = masaSayisi; i < masaSayisi+20; i++)
            {
                Button btn = new Button();
                btn.Name = "btn_" + i;
                btn.Text = "Table " + i;
                btn.Width = 113;
                btn.Height = 71;
                btn.BackColor = Color.LightBlue;
                flowLayoutPanel2.Controls.Add(btn);
                MasaDurum durum = new MasaDurum();
                durum.DoluMu = false;
                durum.AlinanYemekler = "";
                durum.MasaNo = i;
                btn.Tag = durum;
                btn.Click += new EventHandler(btn_Click);
            }
            masaSayisiGuncelle();
        }
        private void linkLabel2Reverse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (kontrol())
            {
                MessageBox.Show("You are in the zero page!!!!");
                return;
            }
            string TipTableName;
            foreach (Control c in flowLayoutPanel2.Controls)
            {
                Button btn = (Button)c;
                if (btn.Visible == true)
                {
                    TipTableName = btn.Name;
                    gosterilecekTable = Convert.ToInt32(TipTableName.Substring(4));
                    MessageBox.Show(gosterilecekTable.ToString());
                    Sakla();
                    break;
                }
            }
            gosterilecekTable -= 20;
            int counter = 1;
            foreach (Control c in flowLayoutPanel2.Controls)
            {
                Button btn = (Button)c;
                if (btn.Name == "btn_" + gosterilecekTable.ToString())
                {
                    btn.Visible = true;
                    gosterilecekTable++;
                    counter++;
                    if (counter > 20)
                    {
                        break;
                    }
                }
            }
         }
        private Boolean kontrol()
        {
            foreach (Control c in flowLayoutPanel2.Controls)
            {
                Button btn = (Button)c;
                if (btn.Name == "btn_" && btn.Visible == true)
                {
                    return true;
                }
            }
            return false;
        }
        private void Sakla()
        {
            foreach (Control c in flowLayoutPanel2.Controls)
            {
                Button btn = (Button)c;
                btn.Visible = false;
            }
        }

        private void Masalar_Load(object sender, EventArgs e)
        {

        }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RestInfoSys
{
    class masaOperation
    {
        string tag;
        public string Tag
           {
               get { return tag; }
               set { tag = value; }
        }
        [b]public masaOperation()
        {
          
        }[/b]
        public void ShowDialog()
        {
        }
    }
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RestInfoSys
{
    class MasaDurum
    {
        public MasaDurum()
        {

        }
        bool doluMu;
        public bool DoluMu
        {
            get { return doluMu; }
            set { doluMu = value; }
        }
        string alinanYemekler;
        public string AlinanYemekler
        {
            get { return alinanYemekler; }
            set { alinanYemekler = value; }
        }
        int masaNo;
        public int MasaNo
        {
            get { return masaNo; }
            set { masaNo = value; }
        }
    }
}



Posted Image

This post has been edited by Curtis Rutland: 12 June 2013 - 07:34 AM
Reason for edit:: fixing code and img


Is This A Good Question/Topic? 0
  • +

Replies To: Problem is the Table Reservation does not work on RestaurantInfoSystem

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Problem is the Table Reservation does not work on RestaurantInfoSystem

Posted 12 June 2013 - 07:27 AM

I started reading through your code.
I want desperately to just say "stop and redesign this". Worry about the GUI last and the data first.

You have designed everything around the buttons as the holders of information. This is horrible. The GUI is supposed to be nothing more than a way to interact with information, like which tables are reserved. The GUI is not supposed to be the repository of the information. The button itself should not be telling you if it is reserved. You also need to start using enums instead of hardcoding codes like this: if (op.Tag == "2")

I want you to also consider this: What if the user is color-blind? Your color-coded display for table status is meaningless. Adding an icon to the button as well as tooltips stating the status would be helpful.

All of your functions require you loop through all the controls on the form. Just very bad. You should have a collection that holds the reservation list. Make a Reservation class that holds:
  • Table number
  • DateTime of the reservation
  • The guest name
  • Duration of the reservation
  • Status (filled, reserved, empty)


Then have your GUI represent that data. That way you can save the data to a database or serialize it to XML. You can then also display the data 100 different ways such as a grid, on a report page, or as the buttons you have... whatever.
Was This Post Helpful? 0
  • +
  • -

#3 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4496
  • View blog
  • Posts: 7,845
  • Joined: 08-June 10

Re: Problem is the Table Reservation does not work on RestaurantInfoSystem

Posted 12 June 2013 - 07:36 AM

To piggy-back on tlhIn`toq's post, that's why WPF is such a great tool, because you can follow an MVVM pattern. Your UI is nothing but bound views, and you write model classes that model your real-world logic, and add viewmodels that help map your business logic into your display logic. You keep everything separate, and your code could be refactored to use a completely different frontend with very little disruption to the backend code.
Was This Post Helpful? 1
  • +
  • -

#4 CansuD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-June 13

Re: Problem is the Table Reservation does not work on RestaurantInfoSystem

Posted 13 June 2013 - 11:17 AM

Thanks your support, good explanation.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1