예제 #1
0
 private void BTAddToList_Click(object sender, EventArgs e)
 {
     //check empty fields
     if (CBBoodschap.SelectedIndex >= 0 && string.IsNullOrWhiteSpace(TBAmount.Text) == false)
     {
         bool alreadyExists = true;
         //check if already added
         for (int i = 0; i < boodschappenLijst.Count(); i++)
         {
             if (CBBoodschap.SelectedItem.ToString() == Convert.ToString(boodschappenLijst[i].Item))
             {
                 alreadyExists = false;
                 MessageBox.Show("Boodschap staat al in de lijst op regel: " + (i + 1));
             }
         }
         if (alreadyExists)
         {
             //add item to list
             Boodschap bs = new Boodschap(CBBoodschap.SelectedItem.ToString(), Convert.ToInt32(TBAmount.Text));
             boodschappenLijst.Add(bs);
             displayBoodschappenLijst();
             CBBoodschap.SelectedIndex = -1;
             TBAmount.Text             = "";
         }
     }
     else
     {
         MessageBox.Show("Niet alle velden zijn ingevuld.");
     }
 }
예제 #2
0
        void LoadCurrentBoodschappenLijst()
        {
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load("LastGroceryList.xml");
            }
            catch
            {
                XmlWriter writer = XmlWriter.Create("LastGroceryList.xml");
                writer.WriteStartElement("Grocerys");
                writer.WriteEndElement();
                writer.Flush();
            }
            try
            {
                foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
                {
                    string    item   = node.SelectSingleNode("Item").InnerText;
                    string    amount = node.SelectSingleNode("Amount").InnerText;
                    Boodschap bs     = new Boodschap(item, Convert.ToInt32(amount));
                    boodschappenLijst.Add(bs);
                }
                displayBoodschappenLijst();
            }
            catch
            {
            }
        }