示例#1
0
 public Main()
 {
     InitializeComponent();
     gestor = MainPaneGestor.getInstance();
     gestor.setMainPane(rightPane);
     gestor.setPanel(PaneFactory.getMainPane());
     gestor.disableShowingSearch();
 }
示例#2
0
 private void button1_Click(object sender, EventArgs e)
 {
     gestor.enableShowingSearch();
     gestor.clearPane();
     gestor.setPanel(PaneFactory.getMenuPane());
 }
示例#3
0
 //Ingredienti
 private void button2_Click(object sender, EventArgs e)
 {
     gestor.disableShowingSearch();
     gestor.clearPane();
     gestor.setPanel(PaneFactory.getIngredientPane());
 }
示例#4
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();
                }
            };
        }
        private void queryInsert(object sender, EventArgs e)
        {
            if (this.box.Text.Length == 0)
            {
                AllertGestor.defaultError("Devi scegliere un nome");
            }
            else if (this.categorie.SelectedItem == null)
            {
                AllertGestor.defaultError("Devi scegliere una categoria");
            }
            else if (this.unitàDiMisura.SelectedItems.Count == 0)
            {
                AllertGestor.defaultError("Devi almeno una unità di misura");
            }
            else
            {
                Ingrediente ing = new Ingrediente();
                ing.Nome    = box.Text;
                ing.NomeCat = categorie.SelectedItem.ToString();
                db.Ingrediente.InsertOnSubmit(ing);
                try
                {
                    db.SubmitChanges();
                } catch (Exception exc)
                {
                    AllertGestor.defaultError("Ingrediente già presente!");
                    return;
                }
                int max = ing.idIngrediente;
                foreach (int i in this.checkCaratteristiche.CheckedIndices)
                {
                    Tuple <int, String> value = this.caratteristiche[i];
                    Caratterizzante     cat   = new Caratterizzante();
                    cat.idCaratteristica = value.Item1;
                    cat.idIngrediente    = max;
                    db.Caratterizzante.InsertOnSubmit(cat);
                }

                this.ingrUdm.ToList().ForEach(x =>
                {
                    IngrUDM ingUdm       = new IngrUDM();
                    ingUdm.kcalPerUnità  = (float)x.Value;
                    ingUdm.NomeUDM       = x.Key;
                    ingUdm.idIngrediente = max;
                    db.IngrUDM.InsertOnSubmit(ingUdm);
                });
                foreach (int i in this.alternativeBox.CheckedIndices)
                {
                    Alternativo alt = new Alternativo();
                    alt.idIngrediente    = max;
                    alt.AltIdIngrediente = this.ingredienti[i].idIngrediente;
                    Alternativo alt2 = new Alternativo();
                    alt2.AltIdIngrediente = max;
                    alt2.idIngrediente    = this.ingredienti[i].idIngrediente;
                    db.Alternativo.InsertOnSubmit(alt);
                    db.Alternativo.InsertOnSubmit(alt2);
                }
                //se qualcosa è andato storto elimino l'ingrediente
                if (this.checkOk() == false)
                {
                    db.Ingrediente.DeleteOnSubmit(ing);
                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception exc)
                    {
                        RicettarioDB.refresh();
                        this.db = RicettarioDB.getInstance();
                        AllertGestor.defaultError("Qualcosa non va");
                        MainPaneGestor.getInstance().setPanel(PaneFactory.getIngredientPane());
                    }
                }
                else
                {
                    RicettarioDB.refresh();
                    AllertGestor.defaultShowOk("Ingrediente inserito!");
                    MainPaneGestor.getInstance().setPanel(PaneFactory.getIngredientPane());
                }
            }
        }
示例#6
0
        public RicettaInsert()
        {
            HashSet <RicettaStrumento> rsToInsert   = new HashSet <RicettaStrumento>();
            HashSet <Step>             stepToInsert = new HashSet <Step>();

            mainPanel = new TableLayoutPanel();
            this.mainPanel.AutoScroll = true;
            Size size = new Size(300, 20);
            //Label
            Label textRicetta = labelFactory.createAdvanceLabel("Inserisci il nome della ricetta", labelFactory.getGeneralFont(),
                                                                size, Color.Black, ContentAlignment.TopLeft);
            Label textTCottura = labelFactory.createAdvanceLabel("Inserisci il tempo di cottura in minuti", labelFactory.getGeneralFont(),
                                                                 size, Color.Black, ContentAlignment.TopLeft);
            Label textTPreparazione = labelFactory.createAdvanceLabel("Inserisci il tempo di preparazione in minuti", labelFactory.getGeneralFont(),
                                                                      size, Color.Black, ContentAlignment.TopLeft);
            Label textDifficolta = labelFactory.createAdvanceLabel("Inserisci la difficoltà", labelFactory.getGeneralFont(),
                                                                   size, Color.Black, ContentAlignment.TopLeft);

            Label textPersone = labelFactory.createAdvanceLabel("Inserisci il numero di persone", labelFactory.getGeneralFont(),
                                                                size, Color.Black, ContentAlignment.TopLeft);

            Label textPortata = labelFactory.createAdvanceLabel("Seleziona la portata desiderata", labelFactory.getGeneralFont(),
                                                                size, Color.Black, ContentAlignment.TopLeft);

            Label textImage = labelFactory.createAdvanceLabel("", labelFactory.getGeneralFont(),
                                                              new Size(400, 20), Color.Black, ContentAlignment.TopLeft);

            Label textDescrizione = labelFactory.createAdvanceLabel("Inserisci la descrizione", labelFactory.getGeneralFont(),
                                                                    size, Color.Black, ContentAlignment.TopLeft);

            //TextBox
            TextBox ricettaText = new TextBox();

            ricettaText.Size      = size;
            ricettaText.MaxLength = (int)textConst.NOME_RICETTA;

            TextBox cotturaText = new TextBox();

            cotturaText.Size      = size;
            cotturaText.MaxLength = 3;

            TextBox preparazioneText = new TextBox();

            preparazioneText.Size      = size;
            preparazioneText.MaxLength = 3;

            TextBox personeText = new TextBox();

            personeText.Size      = new Size(20, 20);
            personeText.MaxLength = 2;

            //RichTextBox

            RichTextBox descrizione = new RichTextBox();

            descrizione.Size = new Size(400, 100);

            //ComboBox
            ComboBox difficoltàBox = new ComboBox();

            DifficoltàUtilities.getDifficulties().ForEach(x => difficoltàBox.Items.Add(DifficoltàUtilities.getDifficulty(x)));

            ComboBox portataBox = new ComboBox();

            portataBox.Items.AddRange((from c in db.Portata
                                       select c.Nome).ToArray());

            //ListView
            ListView listRs = new ListView();

            listRs.View = View.List;
            //Button
            Button insertImage = new Button();

            insertImage.Text   = "Scegli un'immagine per la tua ricetta..";
            insertImage.Size   = size;
            insertImage.Click += (obj, arg) =>
            {
                try
                {
                    textImage.Text = UtilityImage.findFileCheckImage();
                }
                catch (ArgumentException exc)
                {
                    textImage.Text = "";
                    AllertGestor.defaultError("Devi selezionare un'immagine valida");
                }
            };

            Button addRicetta = new Button();

            addRicetta.Text    = "Aggiungi la ricetta..";
            addRicetta.Size    = new Size(200, 25);
            addRicetta.Enabled = false;
            //Cosa fare quando la ricetta deve essere inserita
            addRicetta.Click += (obj, args) =>
            {
                int tcottura, tpreparazione, persone;
                if (ricettaText.TextLength == 0)
                {
                    AllertGestor.defaultError("Devi inserire un nome!");
                }
                else if (cotturaText.TextLength == 0)
                {
                    AllertGestor.defaultError("Devi inserire il tempo di cottura");
                }
                else if (!Int32.TryParse(cotturaText.Text, out tcottura))
                {
                    AllertGestor.defaultError("il tempo di cottura deve essere numerico");
                }
                else if (preparazioneText.TextLength == 0)
                {
                    AllertGestor.defaultError("Devi inserire il tempo di preparazione");
                }
                else if (!Int32.TryParse(preparazioneText.Text, out tpreparazione))
                {
                    AllertGestor.defaultError("il tempo di preparazione deve essere numerico");
                }
                else if (textImage.Text.Equals(""))
                {
                    AllertGestor.defaultError("Devi inserire un'immagine");
                }
                else if (descrizione.TextLength == 0)
                {
                    AllertGestor.defaultError("Devi inserire una descrizione!");
                }
                else if (difficoltàBox.SelectedItem == null)
                {
                    AllertGestor.defaultError("Devi inserire una difficoltà!");
                }
                else if (portataBox.SelectedItem == null)
                {
                    AllertGestor.defaultError("Devi inserire una portata!");
                }
                else if (personeText.TextLength == 0)
                {
                    AllertGestor.defaultError("Devi inserire il numero di persone corretto!");
                }
                else if (!Int32.TryParse(personeText.Text, out persone))
                {
                    AllertGestor.defaultError("le persone devono avere un'indice numerico!");
                }
                else
                {
                    Ricetta ricetta = new Ricetta();
                    ricetta.Nome          = ricettaText.Text;
                    ricetta.TCottura      = tcottura;
                    ricetta.Persone       = persone;
                    ricetta.TPreparazione = tpreparazione;
                    ricetta.Difficoltà    = difficoltàBox.SelectedIndex;
                    ricetta.portata       = portataBox.SelectedItem.ToString();

                    string localFile = FileGestor.copyFileToLocalFolder(textImage.Text, ricetta.Nome);
                    ricetta.Immagine    = localFile;
                    ricetta.Descrizione = descrizione.Text;
                    db.Ricetta.InsertOnSubmit(ricetta);
                    bool insert = true;
                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception exc)
                    {
                        insert = false;
                        RicettarioDB.refresh();
                        this.db = RicettarioDB.getInstance();
                        AllertGestor.defaultError("Il nome della ricetta è già stato inserito! controlla nel menù principale\n" + exc);
                    }
                    if (insert)
                    {
                        //Aggiustamento dei vari valori trovati
                        stepToInsert.ToList().ForEach(x => {
                            x.Immagine = FileGestor.copyFileToLocalFolder(x.Immagine, "" + ricetta.idRicetta + "" + x.idRicettaStrum + "" + x.Nome);
                        });
                        rsToInsert.ToList().ForEach(x =>
                        {
                            x.idRicetta = ricetta.idRicetta;
                            x.Presenta.ToList().ForEach(z =>
                            {
                                Presenta p       = new Presenta();
                                p.idRicetta      = ricetta.idRicetta;
                                p.idRicettaStrum = z.idRicettaStrum;
                                p.idIngrediente  = z.idIngrediente;
                                p.Quantità       = z.Quantità;
                                p.NomeUDM        = z.NomeUDM;
                                x.Presenta.Remove(z);
                                x.Presenta.Add(p);
                            });
                            x.Definito.ToList().ForEach(z => {
                                Definito d         = new Definito();
                                d.idRicetta        = ricetta.idRicetta;
                                d.idRicettaStrum   = z.idRicettaStrum;
                                d.idCaratteristica = z.idCaratteristica;
                                x.Definito.Remove(z);
                                x.Definito.Add(d);
                            });
                            x.Utilizzo.ToList().ForEach(z => {
                                Utilizzo u       = new Utilizzo();
                                u.idRicetta      = ricetta.idRicetta;
                                u.idRicettaStrum = z.idRicettaStrum;
                                u.idStrumento    = z.idStrumento;
                                x.Utilizzo.Remove(z);
                                x.Utilizzo.Add(u);
                            });
                        });
                        stepToInsert.ToList().ForEach(x =>
                        {
                            x.idRicetta = ricetta.idRicetta;
                            x.Uso.ToList().ForEach(z =>
                            {
                                Uso u            = new Uso();
                                u.idRicetta      = ricetta.idRicetta;
                                u.idRicettaStrum = z.idRicettaStrum;
                                u.idStrumento    = z.idStrumento;
                                u.NomeStep       = z.NomeStep;
                                x.Uso.Remove(z);
                                x.Uso.Add(u);
                            });
                            x.Consumo.ToList().ForEach(z =>
                            {
                                Consumo p        = new Consumo();
                                p.idRicetta      = ricetta.idRicetta;
                                p.idRicettaStrum = z.idRicettaStrum;
                                p.idIngrediente  = z.idIngrediente;
                                p.Quantità       = z.Quantità;
                                p.NomeUDM        = z.NomeUDM;
                                p.NomeStep       = z.NomeStep;
                                x.Consumo.Remove(z);
                                x.Consumo.Add(p);
                            });
                        });
                        db.RicettaStrumento.InsertAllOnSubmit(rsToInsert.AsEnumerable());
                        db.Step.InsertAllOnSubmit(stepToInsert.AsEnumerable());
                        try
                        {
                            db.SubmitChanges();
                            AllertGestor.defaultShowOk("Ricetta Inserita!");
                        }
                        catch (Exception exc)
                        {
                            AllertGestor.defaultError("errore grave consultare il tecnico: \n traccia : " + exc.ToString());
                        }
                    }
                    RicettarioDB.refresh();
                    MainPaneGestor.getInstance().enableShowingSearch();
                    MainPaneGestor.getInstance().setPanel(PaneFactory.getRicettaPane());
                }
            };
            Button addSteps = new Button();

            addSteps.Text = "Inserisci gli step...";
            addSteps.Size = new Size(200, 25);
            //Cosa fare quando gli step devono essere inseriti
            addSteps.Click += (obj, args) =>
            {
                ricettaStrumentoInsert popup = new ricettaStrumentoInsert(ricettaStrumentoIndex);
                popup.StartPosition = FormStartPosition.CenterParent;
                popup.setRicettaStrumento(rsToInsert);
                popup.setSteps(stepToInsert);
                popup.ShowDialog();
                if (rsToInsert.Count != 0)
                {
                    addRicetta.Enabled = true;
                }
                listRs.Items.Clear();
                ricettaStrumentoIndex++;
                rsToInsert.ToList().ForEach(x => listRs.Items.Add("Famiglia Step id :" + x.idRicettaStrum));
            };
            //Name Ricetta
            mainPanel.Controls.Add(textRicetta);
            mainPanel.Controls.Add(ricettaText);
            //Tempo Cottura
            mainPanel.Controls.Add(textTCottura);
            mainPanel.Controls.Add(cotturaText);
            //Tempo Preparazione
            mainPanel.Controls.Add(textTPreparazione);
            mainPanel.Controls.Add(preparazioneText);
            //Difficoltà
            mainPanel.Controls.Add(textDifficolta);
            mainPanel.Controls.Add(difficoltàBox);
            //Persone
            mainPanel.Controls.Add(textPersone);
            mainPanel.Controls.Add(personeText);
            //portata
            mainPanel.Controls.Add(textPortata);
            mainPanel.Controls.Add(portataBox);
            //Immagine
            mainPanel.Controls.Add(insertImage);
            mainPanel.Controls.Add(textImage);
            //Descrizione
            mainPanel.Controls.Add(textDescrizione);
            mainPanel.Controls.Add(descrizione);

            //Inserimento
            mainPanel.Controls.Add(addSteps);

            //ListView
            mainPanel.Controls.Add(listRs);
            //Inserimento Ricetta
            mainPanel.Controls.Add(addRicetta);
        }