コード例 #1
0
ファイル: Meni.cs プロジェクト: VJan-fin/FASAP
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is Meni))
            {
                return(false);
            }
            Meni meni = obj as Meni;

            if (Ime != meni.Ime)
            {
                return(false);
            }
            //foreach (var obt in Content)
            //    foreach (var oob in meni.Content)
            //        if (!obt.Equals(oob))
            //            return false;
            return(true);
        }
コード例 #2
0
ファイル: IzvrsuvanjeNaracka.cs プロジェクト: VJan-fin/FASAP
        /// <summary>
        /// Креирање на мени со помош на хеш мапи.
        /// Идеја: Да се овозможи еднократно читање од база и потоа линеарно креирање на дрвото на менија.
        ///
        /// Ги поставува: Restoran.GlavnoMeni и CurrMenu (иста истанца)
        /// </summary>
        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 AND VALIDNOST_MENI = 1";
            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);
            CurrMenu = Restoran.GlavnoMeni;
            PopolniListaMenija();
        }
コード例 #3
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();
                    }
                }
            }
        }
コード例 #4
0
        private void PopolniListaMenija()
        {
            if (CurrMenu == null)
            {
                return;
            }
            int ind = this.indMeni;

            for (int i = 0; i < this.ListaStavki.Count; i++)
            {
                if (ind < CurrMenu.GetContent().Count)
                {
                    if (CurrMenu.GetContent()[ind] is Meni)
                    {
                        Meni mn = CurrMenu.GetContent()[ind] as Meni;
                        if (!ShowInactive && !mn.ValidnostMeni)
                        {
                            i--;
                            ind++;
                            continue;
                        }
                        SetObject(ListaStavki[i], CurrMenu.GetContent()[ind]);
                        SetFontLabel(ListaStavki[i], new Font("Trebuchet MS", 16, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | FontStyle.Underline))), System.Drawing.GraphicsUnit.Point, ((byte)(204))));
                        ListaStavki[i].ForeColor = Color.Gold;
                        if (!mn.ValidnostMeni)
                        {
                            if (mn.Equals(SelectedComponent))
                            {
                                ListaStavki[i].ForeColor = Color.Firebrick;
                            }
                            else
                            {
                                ListaStavki[i].ForeColor = Color.FromArgb(250, 20, 20);
                            }
                        }
                        else
                        {
                            if (mn.Equals(SelectedComponent))
                            {
                                ListaStavki[i].ForeColor = Color.SaddleBrown;
                            }
                            else
                            {
                                ListaStavki[i].ForeColor = Color.Gold;
                            }
                        }
                    }
                    else
                    {
                        SetFontLabel(ListaStavki[i], new Font("Trebuchet MS", 16, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(204))));
                        SetObject(ListaStavki[i], CurrMenu.GetContent()[ind]);
                        if (CurrMenu.GetContent()[ind].Equals(SelectedComponent))
                        {
                            ListaStavki[i].ForeColor = Color.SaddleBrown;
                        }
                        else
                        {
                            ListaStavki[i].ForeColor = Color.White;
                        }
                        ListaStavki[i].Image = Resources.LabelBackground2;
                    }

                    if (CurrMenu.GetContent()[ind].Equals(SelectedComponent))
                    {
                        ListaStavki[i].Image = Resources.LabelBackgroundSelected;
                    }
                    else
                    {
                        ListaStavki[i].Image = Resources.LabelBackground2;
                    }
                    ind++;
                }
                else
                {
                    ListaStavki[i].Image = Resources.LabelBackground2;
                    SetObject(ListaStavki[i], null);
                    SetFontLabel(ListaStavki[i], new Font("Trebuchet MS", 16, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(204))));
                    ListaStavki[i].ForeColor = Color.Khaki;
                }
            }
        }