Exemplo n.º 1
0
        private void KreirajMeni()
        {
            Dictionary <string, Meni>      Menus = new Dictionary <string, Meni>();
            Dictionary <StavkaKey, Stavka> Items = new Dictionary <StavkaKey, Stavka>();

            string        sql = @"SELECT * FROM MENI WHERE RESTORAN_ID = :RES_ID";
            OracleCommand cmd = new OracleCommand(sql, Conn);

            OracleParameter prm = new OracleParameter("RES_ID", OracleDbType.Int64);

            prm.Value = Restoran.RestoranID;
            cmd.Parameters.Add(prm);

            cmd.CommandType = CommandType.Text;
            OracleDataReader dr = cmd.ExecuteReader();
            Meni             meni;

            while (dr.Read())
            {
                meni = new Meni(dr.GetString(1));
                Object obj = dr.GetValue(3);
                if (obj == null)
                {
                    meni.ImeGlavno = null;
                }
                else
                {
                    meni.ImeGlavno = obj as String;
                }
                String IsValid = (string)dr.GetValue(2);
                if (IsValid == "1")
                {
                    meni.ValidnostMeni = true;
                }
                else
                {
                    meni.ValidnostMeni = false;
                }
                Menus.Add(meni.Ime, meni);
            }
            sql = @"SELECT * FROM STAVKA WHERE VALIDNOST_STAVKA LIKE '1' AND RESTORAN_ID = :RES_ID";
            cmd = new OracleCommand(sql, Conn);

            prm       = new OracleParameter("RES_ID", OracleDbType.Int64);
            prm.Value = Restoran.RestoranID;
            cmd.Parameters.Add(prm);

            cmd.CommandType = CommandType.Text;
            dr = cmd.ExecuteReader();

            Dodatok dodatok;
            Stavka  stavka;

            while (dr.Read())
            {
                String IsDecorator = (string)dr.GetValue(5);
                Object ImeGlavno   = dr.GetValue(1);
                Object OpisStavka  = dr.GetValue(3);
                if (IsDecorator == "1")
                {
                    dodatok = new Dodatok((int)dr.GetValue(2), dr.GetString(7), (decimal)dr.GetValue(4));
                    if (ImeGlavno == null)
                    {
                        dodatok.ImeGlavno = null;
                    }
                    else
                    {
                        dodatok.ImeGlavno = ImeGlavno as String;
                    }
                    if (OpisStavka == null)
                    {
                        dodatok.Opis = null;
                    }
                    else
                    {
                        dodatok.Opis = OpisStavka as String;
                    }
                    Items.Add(dodatok.GetStavkaKey(), dodatok);
                }
                else
                {
                    stavka = new Stavka((int)dr.GetValue(2), dr.GetString(7), (decimal)dr.GetValue(4));
                    if (ImeGlavno == null)
                    {
                        stavka.ImeGlavno = null;
                    }
                    else
                    {
                        stavka.ImeGlavno = ImeGlavno as String;
                    }
                    if (OpisStavka == null)
                    {
                        stavka.Opis = null;
                    }
                    else
                    {
                        stavka.Opis = OpisStavka as String;
                    }
                    Items.Add(stavka.GetStavkaKey(), stavka);
                }
            }

            foreach (var obj in Menus)
            {
                Meni menu;
                if (obj.Value.ImeGlavno != null && Menus.TryGetValue(obj.Value.ImeGlavno, out menu))
                {
                    menu.AddComp(obj.Value);
                    obj.Value.Parent = menu;
                }
                else
                {
                    Restoran.GlavnoMeni = obj.Value;
                }
            }

            foreach (var obj in Items)
            {
                Meni menu;
                if (Menus.TryGetValue(obj.Value.ImeGlavno, out menu))
                {
                    menu.AddComp(obj.Value);
                    obj.Value.Parent = menu;
                }
            }
            //lblOsnovnoMeni.UpdateObject(Restoran.GlavnoMeni);
            LoadingSemaphore.WaitOne();
            SetObject(lblOsnovnoMeni, Restoran.GlavnoMeni);
            MenuComponent mm = Restoran.GetSameComponent(CurrMenu);

            if (mm == null)
            {
                CurrMenu          = Restoran.GlavnoMeni;
                SelectedComponent = null;
            }
            else
            {
                CurrMenu = mm;
            }
            SelectedComponent = Restoran.GetSameComponent(SelectedComponent);

            PostaviPateka();
            PopolniListaMenija();
        }
Exemplo n.º 2
0
        private void SocuvajPromeni()
        {
            if (!ValidateChildren())
            {
                timer1.Stop();
                ButtonFasapSetText(lblErrorMessage, "Лошо внесени податоци, промените се одбиени");
                ButtonFasapSetVisible(lblErrorMessage, true);
                timer1.Start();
                IsChanged = false;
                return;
            }
            if (SelectedComponent != null)
            {
                try
                {
                    SelectedComponent.SqlDelete(Conn, Restoran.RestoranID);
                }
                catch (Exception ex)
                {
                    timer1.Stop();
                    ButtonFasapSetText(lblErrorMessage, ex.Message);
                    ButtonFasapSetVisible(lblErrorMessage, true);
                    timer1.Start();
                    return;
                }
                if (IsDecorator)
                {
                    Dodatok dodatok = new Dodatok((SelectedComponent as Stavka).ID, tbIme.Text, int.Parse(tbCena.Text), tbOpis.Text);
                    dodatok.Parent    = SelectedComponent.Parent;
                    SelectedComponent = dodatok;
                }
                else
                {
                    Stavka dodatok = new Stavka((SelectedComponent as Stavka).ID, tbIme.Text, int.Parse(tbCena.Text), tbOpis.Text);
                    dodatok.Parent    = SelectedComponent.Parent;
                    SelectedComponent = dodatok;
                }

                try
                {
                    SelectedComponent.SqlInsert(Conn, Restoran.RestoranID);
                    IsChanged = false;
                    Thread oThread = new Thread(new ThreadStart(KreirajMeni));
                    oThread.Start();
                    LoadingSemaphore.Release();
                }
                catch (Exception ex)
                {
                    timer1.Stop();
                    ButtonFasapSetText(lblErrorMessage, ex.Message);
                    ButtonFasapSetVisible(lblErrorMessage, true);
                    timer1.Start();
                }
            }
            else
            {
                if (DodadiStavka)
                {
                    MenuComponent mc;
                    if (IsDecorator)
                    {
                        mc = new Dodatok(-1, tbIme.Text, int.Parse(tbCena.Text), tbOpis.Text);
                    }
                    else
                    {
                        mc = new Stavka(-1, tbIme.Text, int.Parse(tbCena.Text), tbOpis.Text);
                    }
                    mc.Parent = CurrMenu;
                    try
                    {
                        mc.SqlInsert(Conn, Restoran.RestoranID);
                        IsChanged = false;
                        Thread oThread = new Thread(new ThreadStart(KreirajMeni));
                        oThread.Start();
                        LoadingSemaphore.Release();
                        tbIme.Visible      = false;
                        lblIme.Visible     = false;
                        lblOpis.Visible    = false;
                        tbOpis.Visible     = false;
                        lblDodatok.Visible = false;
                        btnDodatok.Visible = false;
                        lblCena.Visible    = false;
                        tbCena.Visible     = false;
                    }
                    catch (DuplicatePrimaryKeyException ex)
                    {
                        MessageBoxForm mf = new MessageBoxForm(ex.Message, false);
                        if (mf.ShowDialog() == DialogResult.Yes)
                        {
                            tbIme.Text = "";
                        }
                        else
                        {
                            tbIme.Visible      = false;
                            lblIme.Visible     = false;
                            lblOpis.Visible    = false;
                            tbOpis.Visible     = false;
                            lblDodatok.Visible = false;
                            btnDodatok.Visible = false;
                            lblCena.Visible    = false;
                            tbCena.Visible     = false;
                            IsChanged          = false;
                            SelectedComponent  = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        timer1.Stop();
                        ButtonFasapSetText(lblErrorMessage, ex.Message);
                        ButtonFasapSetVisible(lblErrorMessage, true);
                        timer1.Start();
                    }
                }
                else
                {
                    MenuComponent mc = new Meni(tbIme.Text);
                    mc.Parent = CurrMenu;
                    try
                    {
                        mc.SqlInsert(Conn, Restoran.RestoranID);
                        IsChanged = false;
                        Thread oThread = new Thread(new ThreadStart(KreirajMeni));
                        oThread.Start();
                        LoadingSemaphore.Release();
                        tbIme.Visible  = false;
                        lblIme.Visible = false;
                    }
                    catch (DuplicatePrimaryKeyException ex)
                    {
                        MessageBoxForm mf = new MessageBoxForm(ex.Message, false);
                        if (mf.ShowDialog() == DialogResult.Yes)
                        {
                            tbIme.Text = "";
                        }
                        else
                        {
                            tbIme.Visible     = false;
                            lblIme.Visible    = false;
                            IsChanged         = false;
                            SelectedComponent = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        timer1.Stop();
                        ButtonFasapSetText(lblErrorMessage, ex.Message);
                        ButtonFasapSetVisible(lblErrorMessage, true);
                        timer1.Start();
                    }
                }
            }
        }
Exemplo n.º 3
0
 public override void RemoveComp(MenuComponent mc)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 4
0
 public override MenuComponent GetReference(MenuComponent mc)
 {
     return(this);
 }
Exemplo n.º 5
0
 public override void RemoveComp(MenuComponent mc)
 {
     Content.Remove(mc);
 }
Exemplo n.º 6
0
 public override MenuComponent GetReference(MenuComponent mc)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public Dodatok(int id, string ime, decimal cena, string opis = "")
     : base(id, ime, cena, opis)
 {
     Osnovna = null;
 }
Exemplo n.º 8
0
 public override void AddComp(MenuComponent mc)
 {
     Content.Add(mc);
 }
Exemplo n.º 9
0
 public OrderComponent(MenuComponent i, int q = 1)
 {
     Item          = i;
     this.Quantity = q;
 }
Exemplo n.º 10
0
 public abstract MenuComponent GetSameComponent(MenuComponent mc);
Exemplo n.º 11
0
 /// <summary>
 /// Важен метод за да се креира нов објект идентичен на постоечкиот кој ќе уечествува во нарачката.
 /// За разлика од него конкретниот од кој се зема референцата постои во менито.
 /// </summary>
 /// <param name="mc"></param>
 /// <returns></returns>
 public abstract MenuComponent GetReference(MenuComponent mc);
Exemplo n.º 12
0
 public abstract void RemoveComp(MenuComponent mc);
Exemplo n.º 13
0
 public abstract void AddComp(MenuComponent mc);