コード例 #1
0
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            Form1 form1 = (Form1)ParentForm;
            try
            {
                SearchWindow searchForm = new SearchWindow();
                searchForm.ShowDialog();
                if (searchForm.Item != null)
                {
                    Item item = searchForm.Item;
                    bool onList = false;
                    foreach (ItemLine il in flowLayoutPanel1.Controls)
                    {
                        if (il.LblItem.Text == item.Name && il.TxtShop.Text == item.Location)
                        {
                            il.NudAmount.Value += 1;
                            lblSaved.Text = "";
                            onList = true;
                        }
                    }
                    if (item != null && onList == false)
                    {
                        ItemLine il = new ItemLine();
                        il.NotifyParentAmountEvent += new NotifyParentAmountDelegate(AmountChanged);
                        flowLayoutPanel1.Controls.Add(il);

                        PartList psl = service.CreatePartList(item, CurrentShoppingList.ShoppingListNumber, 1);
                        il.SetValues(item.Name, item.Price.ToString(), 1, false, item.Location, psl.Id);
                        bool found = false;
                        for (int i = 0; i <= form1.p.shoppingLists.Count() && !found; i++)
                        {
                            if (form1.p.shoppingLists[i].ShoppingListNumber == CurrentShoppingList.ShoppingListNumber)
                            {
                                List<PartList> partlists = form1.p.shoppingLists[i].PartLists.ToList();
                                partlists.Add(psl);
                                form1.p.shoppingLists[i].PartLists = partlists.ToArray();
                                CurrentShoppingList = form1.p.shoppingLists[i];
                                found = true;
                            }
                        }
                        CalculateSum();
                        lblSaved.Text = "Gemt";
                        lblSaved.ForeColor = Color.Green;
                        btnSaveList.Enabled = false;
                    }


                }
                
            }
            catch
                     (NullReferenceException)
            {
                MessageBox.Show("Noget gik galt. Listen du er på er muligvis blevet slettet et andet sted.");
                form1.p = service.FindPerson(form1.p.Username);
                form1.PopulateLists();
            }
    }
 public void PopulatePanel(List<ShoppingList> l )
 {
     flowLayoutPanel1.Controls.Clear();
     
     foreach (var o in l)
     {
     ItemLine il = new ItemLine();
     il.SetValues("gsfsf!", "200", 2, true);
     flowLayoutPanel1.Controls.Add(il);
     }
 }
コード例 #3
0
 public void PopulatePanel(List<PartList> l, ShoppingList sl)
 {
     lblTitle.Text = sl.Title;
     CurrentShoppingList = sl;
     flowLayoutPanel1.Controls.Clear();
     foreach (PartList psl in l)
     {
         ItemLine il = new ItemLine();
         il.NotifyParentAmountEvent += new NotifyParentAmountDelegate(AmountChanged);
         il.SetValues(psl.Item.Name, psl.Item.Price.ToString(), psl.Amount, psl.Bought, psl.Item.Location, psl.Id);
         flowLayoutPanel1.Controls.Add(il);
     }
     btnSaveList.Enabled = false;
     CalculateSum();
     lblSaved.Text = "";
 }