コード例 #1
0
        /// <summary>
        /// Metod för att fylla alla labels i denna form med information från receptet man trycker på i listbox. Kalla metoden GetRecipe ifrån receptmanager. In parameter
        /// kommer ifrån selected index.
        /// </summary>
        public void UpdateReceipeinfo()
        {
            List <Ingrediens> lst    = new List <Ingrediens>();
            Recept            recipe = receptManager.GetRecipe(lstRecepter.SelectedIndex);

            lblname.Text         = recipe.Receptnamn;
            lblInstuktioner.Text = recipe.Beskrivning;
            foreach (Ingrediens i in recipe.Ingrediens)
            {
                lst.Add(i);
            }
            lstIng.DataSource = lst;
            ingridients       = lst;
            pbImage.Image     = recipe.Picture;
            if (recipe is Kött)
            {
                Kött temp = recipe as Kött;
                lblType.Text = temp.Typeofmeat;
            }
            else if (recipe is Fisk)
            {
                Fisk temp = recipe as Fisk;
                lblType.Text = temp.Typeoffish;
            }
            else
            {
                return;
            }
        }
コード例 #2
0
        /// <summary>
        /// När användaren trycker add knappen så först kontralleras inputenen. Sen om kött radioknappen är
        /// itrycket så skapas  ett ny kött. Sen om den andra radio knapp är i tryckt så skapas en fisk
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Recept r = null;

            if (ReadInput())
            {
                if (rdbMeat.Checked)
                {
                    r = new Kött(txtType.Text, txtname.Text, txtbeskrivning.Text, ingridients, pbImage.Image);
                }
                else if (rdbFish.Checked)
                {
                    r = new Fisk(txtType.Text, txtname.Text, txtbeskrivning.Text, ingridients, pbImage.Image);
                }
                else
                {
                    return;
                }
                recepie = r;
                ClearData();
                UpdateGui();
            }
            else
            {
                return;
            }

            this.DialogResult = DialogResult.OK;
        }
コード例 #3
0
        /// <summary>
        /// Metod för att ändra en recept. Den går in i recept listan med index för hitta specifik palts, sen
        /// lägga till  ny recept för värje variabel. Dynamisc bindning som säger om receptlist[index] platsen är lika med ett kött objekt då är typeof meat lika med new_recipe
        /// typ of meat. Sen samma om index platsen är av typ fisk.
        /// </summary>
        /// <param name="new_recipe"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public bool ChangeRecept(Recept new_recipe, int index)
        {
            Receptlist[index].Receptnamn  = new_recipe.Receptnamn;
            Receptlist[index].Beskrivning = new_recipe.Beskrivning;
            Receptlist[index].Picture     = new_recipe.Picture;
            Receptlist[index].Ingrediens  = new_recipe.Ingrediens;
            if (Receptlist[index] is Kött && new_recipe is Kött)
            {
                Kött temp  = Receptlist[index] as Kött;
                Kött temp2 = new_recipe as Kött;
                temp.Typeofmeat = temp2.Typeofmeat;
            }
            else if (Receptlist[index] is Kött && new_recipe is Fisk)
            {
                Fisk temp  = Receptlist[index] as Fisk;
                Fisk temp2 = new_recipe as Fisk;
                temp.Typeoffish = temp2.Typeoffish;
            }

            return(true);
        }