public MenuSelection(int idMenu)
        {
            InitializeComponent();
            this.Icon   = Properties.Resources.iconmain;
            this.idMenu = idMenu;
            this.tableLayoutPanel1.Dock = DockStyle.Fill;
            this.menu.TextAlign         = ContentAlignment.MiddleCenter;
            this.StartPosition          = FormStartPosition.CenterParent;
            Menù menu = (from m in RicettarioDB.getInstance().Menù
                         where m.idMenù == idMenu
                         select m).First();

            this.menu.Text         = menu.Nome;
            this.tipo.Text         = "Tipo :" + menu.Tipo;
            this.immageGestor.Dock = DockStyle.Top;
            ToolTip ricettaTip = TooltipFactory.createBasicTooltip("Ricette");

            menu.Assemblaggio.ToList().ForEach(x =>
            {
                PictureBox picture = new PictureBox();
                picture.Size       = new Size(100, 100);
                picture.Image      = new Bitmap(x.Ricetta.Immagine);
                picture.SizeMode   = PictureBoxSizeMode.StretchImage;
                this.immageGestor.Controls.Add(picture);
                ricettaTip.SetToolTip(picture, "Nome " + x.Ricetta.Nome +
                                      "\nPortata " + x.Ricetta.portata +
                                      "\nPersone = " + x.Ricetta.Persone);
                picture.Click += (obj, arg) => new RicettaVisualizzation(x.Ricetta.idRicetta).ShowDialog();
            });
        }
Beispiel #2
0
        public MenuInsert()
        {
            pane.AutoScroll = true;
            Size           basicSize   = new Size(400, 20);
            List <Ricetta> listRicette = (from c in db.Ricetta select c).ToList();
            //Label
            Label textNome = labelFactory.createAdvanceLabel("Scegli il nome del menu..", labelFactory.getGeneralFont(),
                                                             basicSize, Color.Black, ContentAlignment.TopLeft);

            Label textTipo = labelFactory.createAdvanceLabel("Scegli il tipo del menu..", labelFactory.getGeneralFont(),
                                                             basicSize, Color.Black, ContentAlignment.TopLeft);

            Label textRicette = labelFactory.createAdvanceLabel("Scegli ricette.", labelFactory.getGeneralFont(),
                                                                basicSize, Color.Black, ContentAlignment.TopLeft);

            //TextBox

            TextBox nomeText = new TextBox();

            nomeText.Size      = basicSize;
            nomeText.MaxLength = (int)textConst.NOME_MENU;

            TextBox tipoText = new TextBox();

            tipoText.Size      = basicSize;
            tipoText.MaxLength = (int)textConst.NOME_TIPO;

            //List view
            CheckedListBox ricette = new CheckedListBox();

            ricette.Size = new Size(400, 150);

            //Button
            Button aggiunge = new Button();

            aggiunge.Text = "Inserisci il menu";
            aggiunge.Size = basicSize;

            listRicette.ForEach(x => ricette.Items.Add(x.Nome));
            //nome
            this.pane.Controls.Add(textNome);
            this.pane.Controls.Add(nomeText);
            //tipo
            this.pane.Controls.Add(textTipo);
            this.pane.Controls.Add(tipoText);
            //ricette
            this.pane.Controls.Add(textRicette);
            this.pane.Controls.Add(ricette);
            //Inserimento
            this.pane.Controls.Add(aggiunge);

            //action
            aggiunge.Click += (obj, args) =>
            {
                if (nomeText.Text.Length == 0)
                {
                    AllertGestor.defaultError("Devi scegliere un nome");
                }
                else if (tipoText.Text.Length == 0)
                {
                    AllertGestor.defaultError("Devi scegliere un tipo");
                }
                else if (ricette.SelectedItems.Count == 0)
                {
                    AllertGestor.defaultError("Devi almeno una ricetta");
                }
                else
                {
                    Menù menu = new Menù();
                    menu.Nome = nomeText.Text;
                    menu.Tipo = tipoText.Text;
                    db.Menù.InsertOnSubmit(menu);
                    db.SubmitChanges();
                    foreach (int i in ricette.CheckedIndices)
                    {
                        Assemblaggio assemblaggio = new Assemblaggio();
                        assemblaggio.idMenù    = menu.idMenù;
                        assemblaggio.idRicetta = listRicette[i].idRicetta;
                        db.Assemblaggio.InsertOnSubmit(assemblaggio);
                    }
                    db.SubmitChanges();
                    AllertGestor.defaultShowOk("Menu inserito correttamente");
                    MainPaneGestor.getInstance().setPanel(PaneFactory.getMenuPane());
                    MainPaneGestor.getInstance().enableShowingSearch();
                    RicettarioDB.refresh();
                }
            };
        }