sloshymon 0 Newbie Poster

I have a what should be a simple form program that has a comboBox, textBox, two buttons, and a label. once the user picks an item it shows the cost for that item. they can then enter a number into the textBox, once order is clicked the total amount for the item*quantity is given. The problem I am having is, when I try to see if its adding to my List. So the printing of the list to a label. but all I really am trying to do is store the orders into a array, I think I am over complicating things.
Thanks in advance

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Market
{
    class Items
    {
        public string description { get; set; }//description of item
        public double cost { get; set; }// cost of item
        public int amount { get; set; } // amout of items



        public Items(double cost, int ammount, string description)
        {
            this.cost = cost;
            this.description = description;
            this.amount = ammount;
        }


        //ToString Formats output
        public override string ToString()
        {
            return string.Format("cost {0} ammount {1} Decription {2}", cost, amount, description);
        }

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Market
{
    class ItemList
    {
        private List<Items> aList;


        public ItemList()
        {
            this.aList = new List<Items>();
        }

        public void add(Items asg)
        {
            aList.Add(asg);
        }

        //not the right way but c
       // public void listOrder()
       // {
         //   for (int i = 0; i < aList.Count; i++) // Loop through List with for
           // {
             //   Console.WriteLine(aList[i]);
            //}
       // }

        public int Count { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Market
{
    public partial class Form1 : Form
    {
        private static ItemList asgList;
        private double cost;
        int amount = 0;

        public Form1()
        {
            InitializeComponent();
        }


        private void Order_Click(object sender, EventArgs e)
        {
            asgList = new ItemList();
            amount = int.Parse(textBox1.Text);
            cost *= amount;



            if (comboBox1.SelectedItem.ToString() == "Eggs")
            {
                label1.Text = "The cost for  " + amount + " dozen large, fresh eggs  is: " + (cost).ToString("C");
                string description = "The cost for  " + amount + " dozen large, fresh eggs  is: " + (cost).ToString("C");

                Items temp = new Items(cost, amount, description);

                asgList.add(temp);

            }
            else if (comboBox1.SelectedItem.ToString() == "Milk")
            {
                if (amount == 1)
                {
                    label1.Text = "The Cost for a fresh quart milk is: " + (cost).ToString("C");
                    string description = "The Cost for a fresh quart milk is: " + (cost).ToString("C");
                    Items temp = new Items(cost, amount, description);

                    asgList.add(temp);
                }
                else
                {
                    label1.Text = "The Cost for " + amount + "  quarts of fresh milk is: " + (cost).ToString("C");
                    string description = "The cost for  " + amount + " dozen large, fresh Milk  is: " + (cost).ToString("C");
                    Items temp = new Items(cost, amount, description);

                    asgList.add(temp);
                }
            }
            else
            {

                label1.Text = "The Cost for " + amount + " fresh loafs of bread is: " + (cost).ToString("C");
                string description = "The Cost for " + amount + " fresh loafs of bread is: " + (cost).ToString("C");
                Items temp = new Items(cost, amount, description);
                asgList.add(temp);
            }

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem.ToString() == "Eggs")
            {
                cost = 1.90;
                label1.Text = "The Cost is " + (cost).ToString("C") + " per dozen";
            }
            else if (comboBox1.SelectedItem.ToString() == "Milk")
            {

                cost = 1.47;
                label1.Text = "The Cost is " + (cost).ToString("C") + " per quart";
            }
            else
            {
                cost = 2.12;
                label1.Text = "The Cost is " + (cost).ToString("C") + " per loaf";
            }
        }

        private void total_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < asgList.Count; i++) // Loop through List with for
            {
                label1.Text = (asgList[i]);
            }




        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar)
                && !char.IsDigit(e.KeyChar)
                && e.KeyChar != '.')
            {
                e.Handled = true;
            }

            if (e.KeyChar == '.'
        && (sender as TextBox).Text.IndexOf('.') > -2)
            {
                e.Handled = true;
            }
            if (e.KeyChar == '-'
     && (sender as TextBox).Text.IndexOf('-') > -2)
            {
                e.Handled = true;
            }
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.