עגלת קניות

clip_image002

 

namespace CoffeShop

{

    public partial class cartWin : Form

    {

        dbEntities db = new dbEntities();

        orderView currOrder;

        public cartWin()

        {

            InitializeComponent();

        }

        public cartWin(orderView currOrder)

        {

            InitializeComponent();

            this.currOrder = currOrder;

        }

        private void cartWin_Load(object sender, EventArgs e)

        {

            label2.Text = currOrder.orderID.ToString();

            textBox1.Text = currOrder.custFirstName + " " + currOrder.custLastName;

            textBox2.Text = currOrder.orderDate.ToString("dd/MM/yyyy");

            List<productTBL> profList = (from s in db.productTBL orderby s.name select s).ToList();

            dataGridView1.DataSource = profList;

            comboBox1.DataSource = profList;

 

            var cartList = (from s in db.salesTBL

                                       where s.orderID == currOrder.orderID

                                       join r in db.productTBL on s.productID equals r.Id

                                       select new

                                       {

                                           s.Id,

                                           r.name,

                                           r.price,

                                           s.amount,

                                           total = s.amount * r.price

                                       }).ToList();

            dataGridView2.DataSource = cartList;

            comboBox2.DataSource = cartList;

          

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            productTBL p1 = (productTBL)comboBox1.SelectedItem;

            salesTBL s1 = new salesTBL();

            s1.productID = p1.Id;

            s1.orderID = currOrder.orderID;

            s1.amount = (int)numericUpDown1.Value;

            db.salesTBL.Add(s1);

            db.SaveChanges();

            cartWin_Load(null, null);

 

        }

    }

}