예제 #1
0
파일: Dodatok.cs 프로젝트: VJan-fin/FASAP
        public override MenuComponent GetReference(MenuComponent mc)
        {
            if (mc == null)
            {
                throw new NotImplementedException(String.Format("Не е можно да го нарачате само додатокот \"{0}\"", GetName()));
            }
            MenuComponent pom = this;

            while (pom.Parent != null)
            {
                if (pom.Parent.Equals(mc.Parent))
                {
                    break;
                }
                pom = pom.Parent;
            }
            if (pom.Parent == null)
            {
                throw new NotImplementedException(String.Format("Додатокот \"{0}\" не е соодветен на производот \"{1}\"", this.GetName(), mc.GetName()));
            }
            if (mc.Sodrzi(this))
            {
                throw new NotImplementedException(String.Format("Производот \"{0}\" веќе го содржи додатокот \"{1}\"", mc.GetName(), GetName()));
            }
            Dodatok dodatok = new Dodatok(ID, Ime, Cena, Opis);

            dodatok.Parent  = Parent;
            dodatok.Osnovna = mc;
            return(dodatok);
        }
예제 #2
0
파일: Dodatok.cs 프로젝트: VJan-fin/FASAP
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is Dodatok))
            {
                return(false);
            }
            Dodatok dodatok = obj as Dodatok;

            if (ID != dodatok.ID || !Parent.Equals(dodatok.Parent))
            {
                return(false);
            }
            if (Osnovna == null && dodatok.Osnovna == null)
            {
                return(true);
            }
            if (Osnovna == null)
            {
                return(false);
            }
            if (!Osnovna.Equals(dodatok.Osnovna))
            {
                return(false);
            }
            return(true);
        }
예제 #3
0
파일: Dodatok.cs 프로젝트: VJan-fin/FASAP
        public override bool Sodrzi(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is Dodatok))
            {
                return(false);
            }
            Dodatok dodatok = obj as Dodatok;

            if (ID != dodatok.ID || !Parent.Equals(dodatok.Parent))
            {
                if (Osnovna != null)
                {
                    return(Osnovna.Sodrzi(obj));
                }
            }
            return(true);
        }
예제 #4
0
        /// <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();
        }
예제 #5
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();
                    }
                }
            }
        }
예제 #6
0
        public override List <Narachki.Naracka> ListaNaracki(Oracle.DataAccess.Client.OracleConnection conn)
        {
            Dictionary <VklucuvaKey, Stavka> Stavki = new Dictionary <VklucuvaKey, Stavka>();
            string          sqlMeni = @"SELECT n.Narachka_ID, n.VKUPNA_CENA, n.VREME, site.BROJ_MASA,st.stavka_id, st.ime_stavka, st.opis_stavka, st.cena_stavka, st.dodatok_stavka, vk.kolichina_stavka, vk.vkluchuva_id, vk.dodatok_id
                                FROM Korisnik k, Vraboten v, Onsite_narachka site, Narachka n, Vkluchuva vk, Stavka st
                                WHERE k.Vraboten_ID = v.Vraboten_ID AND site.Vraboten_ID = v.Vraboten_ID
		                                AND n.Narachka_ID = site.Narachka_ID AND n.Restoran_ID = site.Restoran_ID
		                                AND n.Restoran_ID = k.Restoran_ID 
                                        AND vk.RESTORAN_ID = n.RESTORAN_ID
                                        AND vk.NARACHKA_ID = n.NARACHKA_ID
                                        AND vk.RESTORAN_ID = st.RESTORAN_ID
                                        AND vk.STAVKA_ID = st.STAVKA_ID
                                        AND vk.IME_MENI = st.IME_MENI
		                                AND k.Korisnichko_ime = :UserName AND k.lozinka = :Password
		                                AND n.Realizirana = 0
                                        ORDER BY n.NARACHKA_ID, vk.VKLUCHUVA_ID";
            OracleCommand   cmd     = new OracleCommand(sqlMeni, conn);
            OracleParameter prm     = new OracleParameter("UserName", OracleDbType.Varchar2);

            prm.Value = Username;
            cmd.Parameters.Add(prm);
            prm       = new OracleParameter("Password", OracleDbType.Varchar2);
            prm.Value = Password;
            cmd.Parameters.Add(prm);
            cmd.CommandType = CommandType.Text;
            OracleDataReader          dr      = cmd.ExecuteReader();
            List <Naracka>            lista   = new List <Naracka>();
            Dictionary <int, Naracka> Naracki = new Dictionary <int, Naracka>();

            while (dr.Read())
            {
                int narid = dr.GetInt32(0);
                if (!Naracki.ContainsKey(narid))
                {
                    Naracka nar = new Onsite(narid, dr.GetInt32(1), dr.GetDateTime(2), dr.GetInt32(3));
                    Naracki.Add(narid, nar);
                    lista.Add(nar);
                }
                int    vklucuvaid = dr.GetInt32(10);
                int?   dodatokid;
                object obj1 = dr.GetValue(11);
                if (obj1 == null)
                {
                    dodatokid = null;
                }
                else
                {
                    dodatokid = obj1 as int?;
                }
                Object obj = dr.GetValue(6);
                String pomosen;
                if (obj == null)
                {
                    pomosen = null;
                }
                else
                {
                    pomosen = obj as String;
                }
                String IsDecorator = (string)dr.GetValue(8);
                if (IsDecorator == "1")
                {
                    Dodatok dodatok = new Dodatok(dr.GetInt16(4), dr.GetString(5), (decimal)dr.GetValue(7), pomosen);
                    dodatok.DodatokKey  = new VklucuvaKey(narid, dodatokid);
                    dodatok.VklucuvaKey = new VklucuvaKey(narid, vklucuvaid);
                    dodatok.Kolicina    = dr.GetInt32(9);
                    Stavki.Add(new VklucuvaKey(narid, vklucuvaid), dodatok);
                }
                else
                {
                    Stavka stavka = new Stavka(dr.GetInt16(4), dr.GetString(5), (decimal)dr.GetValue(7), pomosen);
                    stavka.DodatokKey  = new VklucuvaKey(narid, dodatokid);
                    stavka.VklucuvaKey = new VklucuvaKey(narid, vklucuvaid);
                    stavka.Kolicina    = dr.GetInt32(9);
                    Stavki.Add(new VklucuvaKey(narid, vklucuvaid), stavka);
                }
            }

            Dictionary <VklucuvaKey, Stavka> StavkiKoiSeRef = new Dictionary <VklucuvaKey, Stavka>();

            foreach (var obj in Stavki)
            {
                Stavka st;
                if (Stavki.TryGetValue(obj.Value.getDodatokKey(), out st))
                {
                    (obj.Value as Dodatok).Osnovna = st;
                    StavkiKoiSeRef.Add(obj.Value.getDodatokKey(), st);
                }
            }

            foreach (var obj in Stavki)
            {
                if (!StavkiKoiSeRef.ContainsKey(obj.Value.getVklucuvaKey()))
                {
                    Naracka nar;
                    if (Naracki.TryGetValue(obj.Value.VklucuvaKey.NarackaID, out nar))
                    {
                        nar.AddA(new OrderComponent(obj.Value, obj.Value.Kolicina));
                    }
                }
            }

            return(lista);
        }