Esempio n. 1
0
        public void SomarItensComandaUmItem()
        {
            Item item = new Item()
            {
                Descricao = "Cerveja", Preco = 10
            };

            Comanda comanda = new Comanda()
            {
                Status = StatusComanda.Aberta, Numero = "BZE1000"
            };

            var ItemComanda = new ItemComanda()
            {
                Comanda = comanda, ComandaId = comanda.Id, Item = item, ItemId = item.Id, Quantidade = 5
            };

            Comanda comandaItem = new Comanda();

            comandaItem = comanda;

            comandaItem.Itens.Add(ItemComanda);

            var soma = comandaItem.Itens.Sum(x => x.Quantidade * x.Item.Preco);

            Assert.AreEqual(50, soma);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.Write("Quantos itens foram consumidos? ");
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                Console.Write("Código do produto: ");
                int codigo = int.Parse(Console.ReadLine());
                Console.Write("Descrição do produto: ");
                string descricao = Console.ReadLine();
                Console.Write("Preço: ");
                double preco = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

                Produto produto = new Produto(codigo, descricao, preco);

                ItemComanda item = new ItemComanda(produto, n);

                Comanda c = new Comanda();

                c.addlista(item);

                Console.WriteLine(c);
            }
        }
Esempio n. 3
0
    protected void buttonComandaClick(object sender, EventArgs e)
    {
        Comanda comanda = Session["comanda"] as Comanda;

        if (comanda == null)
        {
            User user = Session["user"] as User;
            comanda = new Comanda();
            if (user == null)
            {
                comanda.IdUser = 0;
            }
            else
            {
                comanda.IdUser = user.Id;
            }
            comanda.Data = DateTime.Now;
        }
        Button      order_button = sender as Button;
        int         index_meniu  = Convert.ToInt32(order_button.CommandArgument);
        ItemComanda item         = new ItemComanda(recomandari_[index_meniu], 1);

        comanda.addItemComanda(item);
        Session["comanda"] = comanda;
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal('hide')", true);
        Label       badge        = Master.FindControl("Badge") as Label;
        UpdatePanel update_badge = Master.FindControl("BadgeUpdatePanel") as UpdatePanel;

        badge.Text = comanda.NumarPreparate + "";
        update_badge.Update();
    }
Esempio n. 4
0
        // Recomandari calculate prin Content Based Filtering.
        private static List<Preparat> Gaseste_recomandari_ContentBased(int id_user, int k, List<Comanda> istoric_comenzi)
        {
            Dictionary<String, int> dictionar_tipuri = new Dictionary<String,int>();
            Dictionary<String, int> dictionar_specificuri = new Dictionary<String,int>();

            // Calculam pretul mediu al unei comenzi, tipul si specificul preferate.
            double pret_mediu = 0;
            int nr_preparate = 0;
            String specific = "", tip = "";
            Hashtable lista_item_comanda;
            Preparat preparat;

            foreach(Comanda comanda in istoric_comenzi)
            {
                pret_mediu += comanda.Pret;
                nr_preparate += comanda.NumarPreparate;

                lista_item_comanda = comanda.ListaItem;
                foreach(DictionaryEntry item in lista_item_comanda)
                {
                    ItemComanda item_comanda = item.Value as ItemComanda;
                    preparat = item_comanda.Preparat;
                    specific = preparat.Specific;
                    if(dictionar_specificuri.ContainsKey(specific))
                    {
                        dictionar_specificuri[specific]++;
                        //.TryGetValue(specific, out value);
                        //dictionar_specificuri.Add(specific, value+1);
                    }
                    else
                    {
                        dictionar_specificuri.Add(specific, 1);
                    }

                    tip = preparat.Tip;
                    if (dictionar_tipuri.ContainsKey(tip))
                    {
                        dictionar_tipuri[tip]++;
                        //    .TryGetValue(tip, out value);
                        //dictionar_tipuri.Add(tip, value + 1);
                    }
                    else
                    {
                        dictionar_tipuri.Add(tip, 1);
                    }
                }
                
            }

            specific = dictionar_specificuri.MaxBy(x => x.Value).Key;
            tip = dictionar_tipuri.MaxBy(x => x.Value).Key;
            List<Preparat> recomandari = new List<Preparat>();
            if (nr_preparate > 0)
            {
                pret_mediu = pret_mediu / nr_preparate;
            }

            recomandari = preparateDupaParametri(id_user,specific,tip, pret_mediu, k);
            return recomandari;
        }
Esempio n. 5
0
        private void BtnIncluir_Click(object sender, EventArgs e)
        {
            // obtém o objeto comanda selecionado
            Comanda c = cbComandas.SelectedValue as Comanda;
            // busca o objeto produto a partir do produto selecionado
            Produto p = ObterProduto(Convert.ToInt32(cbProdutos.SelectedValue));

            if (p != null)
            {
                // TODO: validar campo
                double quantidade = Convert.ToDouble(txtQuantidade.Text);
                // cria um novo item e adiciona na comanda
                ItemComanda item = new ItemComanda(p, quantidade);
                c.AdicionarItem(item);
            }
            // verifica se deseja adicionar um novo item, senão fecha a tela
            DialogResult resultado = MessageBox.Show("Item incluido com sucesso\r\nDeseja incluir outro item?",
                                                     "Confirmação", MessageBoxButtons.YesNoCancel);

            if (resultado == DialogResult.No)
            {
                Close();
            }
            else
            {
                Limpar();
            }
        }
Esempio n. 6
0
    protected void deletePreparat(object sender, EventArgs e)
    {
        Comanda     comanda = Session["comanda"] as Comanda;
        LinkButton  adauga  = sender as LinkButton;
        int         id      = Convert.ToInt32(adauga.CommandArgument);
        ItemComanda item    = comanda.ListaItem[id] as ItemComanda;

        comanda.removeItemComanda(item);
        item.scadeCantitate();
        comanda.addItemComanda(item);
        Session["comanda"] = comanda;
        updateBadge();
        ComandaListView.DataBind();
        showTotal();
    }
Esempio n. 7
0
 private static List<Preparat> eliminaComandate(List<IstoricComenzi> istorice, IstoricComenzi istoric_user, Comanda comanda)
 {
     HashSet<Preparat> preparate = new HashSet<Preparat>();
     int avg = DatabaseFunctions.numarMediuComandariPreparat(istoric_user.IdUser);
     foreach (var istoric in istorice)
     {
         foreach (var com in istoric.ListaComenzi)
         {
             foreach (DictionaryEntry item in com.ListaItem)
             {
                 ItemComanda item_comanda = item.Value as ItemComanda;
                 int nr = DatabaseFunctions.numarComandariPreparat(istoric_user.IdUser, item_comanda.Preparat.Id);
                 if (!comanda.ListaItem.ContainsKey(item_comanda.Preparat.Id) && avg >= nr)
                 {
                     preparate.Add(item_comanda.Preparat);
                 }
             }
         }
     }
     return preparate.ToList();
 }
Esempio n. 8
0
 protected void buttonComandaClick(object sender, EventArgs e)
 {
     if (Session["user"] == null)
     {
         Session["error"] = "Trebuie sa fi autentificat pentru a putea comanda";
         Response.Redirect("../../Web_Forms/User_actions/Login.aspx");
     }
     else
     {
         Comanda comanda = Session["comanda"] as Comanda;
         if (comanda == null)
         {
             User user = Session["user"] as User;
             comanda = new Comanda();
             if (user == null)
             {
                 comanda.IdUser = 0;
             }
             else
             {
                 comanda.IdUser = user.Id;
             }
             comanda.Data = DateTime.Now;
         }
         Button      order_button = sender as Button;
         int         index_meniu  = Convert.ToInt32(order_button.CommandArgument);
         ItemComanda item         = new ItemComanda(meniu_[index_meniu], 1);
         comanda.addItemComanda(item);
         Session["comanda"] = comanda;
         ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal('hide')", true);
         Label       badge        = Master.FindControl("Badge") as Label;
         UpdatePanel update_badge = Master.FindControl("BadgeUpdatePanel") as UpdatePanel;
         badge.Text = comanda.NumarPreparate + "";
         update_badge.Update();
     }
 }
Esempio n. 9
0
    protected void buttonComandaClick(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["error"] = "Trebuie sa fi autentificat pentru a putea comanda";
            Response.Redirect("../../Web_Forms/User_actions/Login.aspx");
        }
        else
        {
            Comanda comanda = Session["comanda"] as Comanda;
            if (comanda == null)
            {
                User user = Session["user"] as User;
                comanda = new Comanda();
                if (user == null)
                {
                    comanda.IdUser = 0;
                }
                else
                {
                    comanda.IdUser = user.Id;
                }
                comanda.Data = DateTime.Now;
            }
            Button      order_button = sender as Button;
            int         id_preparat  = Convert.ToInt32(order_button.CommandArgument);
            ItemComanda item         = new ItemComanda(potriviri_[id_preparat] as Preparat, 1);
            comanda.addItemComanda(item);
            Session["comanda"] = comanda;

            //// Potriviri additions
            potriviri_.Clear();
            potriviriKeyedByPreparate_.Clear();

            List <Preparat> preparate = comanda.ListaItem.Values.Cast <ItemComanda>().Select(itemComanda => itemComanda.Preparat).ToList();

            IEnumerator <Preparat> preparate_enumerator = preparate.GetEnumerator();

            foreach (Preparat preparat in preparate)
            {
                List <Preparat> potriviri = null;
                if (potriviriPreparateCache_.ContainsKey(preparat.Id))
                {
                    potriviri = potriviriPreparateCache_[preparat.Id] as List <Preparat>;
                }
                else
                {
                    potriviri = DatabaseFunctions.getPotriviriPreparat(preparat);
                    potriviriPreparateCache_.Add(preparat.Id, potriviri);
                }

                foreach (Preparat potrivire in potriviri)
                {
                    bool potrivire_valida = true;

                    preparate_enumerator.Reset();
                    while (preparate_enumerator.MoveNext())
                    {
                        if (preparate_enumerator.Current.Id == potrivire.Id)
                        {
                            potrivire_valida = false;
                            break;
                        }

                        if (preparate_enumerator.Current.Tip.Equals(potrivire.Tip))
                        {
                            potrivire_valida = false;
                            break;
                        }
                    }

                    if (potrivire_valida)
                    {
                        if (!potriviri_.ContainsKey(potrivire.Id))
                        {
                            potriviri_.Add(potrivire.Id, potrivire);
                        }

                        List <int> id_potriviri = null;
                        if (potriviriKeyedByPreparate_.ContainsKey(preparat.Id))
                        {
                            id_potriviri = potriviriKeyedByPreparate_[preparat.Id] as List <int>;
                            id_potriviri.Add(potrivire.Id);
                        }
                        else
                        {
                            id_potriviri = new List <int>();
                            id_potriviri.Add(potrivire.Id);
                            potriviriKeyedByPreparate_[preparat.Id] = id_potriviri;
                        }
                    }
                }
            }

            carouselRepeater.DataSource = potriviri_.Values;
            carouselRepeater.DataBind();
            if (carouselRepeater.Items.Count == 0)
            {
                potriviriDiv.Visible = false;
            }
            ////

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$('#myModal').modal('hide')", true);
            Label       badge        = Master.FindControl("Badge") as Label;
            UpdatePanel update_badge = Master.FindControl("BadgeUpdatePanel") as UpdatePanel;
            badge.Text = comanda.NumarPreparate + "";
            update_badge.Update();

            bindComandaListView();
        }
    }