Пример #1
0
        public void SaveVeggiToFile(Veggi v)
        {
            StreamWriter writer = new StreamWriter(path, true);

            writer.WriteLine(v.ToString());
            writer.Close();
        }
Пример #2
0
 public void RemoveVeggi(Veggi v, double amount)
 {
     v.PutBack(amount);
     if (v.Amount <= 0)
     {
         basket.Remove(v);
     }
     file.UpdatedVeggies(basket);
 }
Пример #3
0
 public override bool Equals(object obj)
 {
     if (obj is Veggi)
     {
         Veggi otherVeggi = (Veggi)obj;
         if (otherVeggi.name == this.name && otherVeggi.category == this.category && otherVeggi.unitPrice == this.unitPrice)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #4
0
 //methods
 public void AddVeggiToBasket(Veggi v)
 {
     if (basket.Contains(v))
     {
         v.BuyMore(v.Amount);
     }
     else
     {
         basket.Add(v);
         file.SaveVeggiToFile(v);
     }
     file.UpdatedVeggies(basket);
 }
Пример #5
0
        private void listBoxVeggis_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Veggi veggi = (Veggi)listBoxVeggis.SelectedItem;

            if (veggi == null)
            {
                textBoxPrice.Text = "0";
            }
            else
            {
                double price = veggi.Amount * veggi.Price;
                textBoxPrice.Text = price.ToString();
            }
        }
Пример #6
0
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxVeggi.Text == "" || textBoxUnitPrice.Text == "" || textBoxAmount.Text == "")
            {
                MessageBox.Show("Input is empty!");
            }
            else
            {
                string name      = textBoxVeggi.Text;
                double unitPrice = double.Parse(textBoxUnitPrice.Text);
                double amount    = double.Parse(textBoxAmount.Text);
                string category  = textBoxCategory.Text;

                Veggi v = new Veggi(name, unitPrice, amount, category);
                basket.AddVeggiToBasket(v);
                RefreshGUI();
            }
        }
Пример #7
0
        private void buttonPutBack_Click(object sender, RoutedEventArgs e)
        {
            if (listBoxVeggis.SelectedItem == null)
            {
                MessageBox.Show("Select an Item!");
            }
            else if (textBoxAmount.Text == "")
            {
                MessageBox.Show("Amount is empty!");
            }
            else
            {
                double amount = double.Parse(textBoxAmount.Text);
                Veggi  veggi  = (Veggi)listBoxVeggis.SelectedItem;
                basket.RemoveVeggi(veggi, amount);

                RefreshGUI();
            }
        }
Пример #8
0
        //methods
        public List <Veggi> ReadFile()
        {
            List <Veggi> veggies = new List <Veggi>();
            StreamReader reader  = new StreamReader(path);
            string       line    = reader.ReadLine();

            while (line != null)
            {
                //read line and split it into parts
                string[] parts     = line.Split('\t');
                string   name      = parts[1];
                double   unitPrice = double.Parse(parts[3]);
                double   amount    = double.Parse(parts[5]);
                string   category  = parts[7];

                //creat object and add to collection
                Veggi v = new Veggi(name, unitPrice, amount, category);
                veggies.Add(v);
                line = reader.ReadLine();
            }
            reader.Close();
            return(veggies);
        }