Example #1
0
        private void btnAddtoCart_Click(object sender, EventArgs e)
        {
            if (txtLaundryID.Text.Equals(""))
            {
                MessageBox.Show("Please Choose Laundry First");
            }
            else if (numericUpDown1.Value.Equals(0))
            {
                MessageBox.Show("Please Fill the Quantity More Than 0");
            }
            else
            {
                key = txtLaundryID.Text;

                var data = (from x in db.HeaderTransactions
                            join y in db.DetailTransactions on x.TransactionID equals y.TransactionID
                            join z in db.PriceLists on y.ProductID equals z.ProductID
                            where x.Status.Equals("Pending") && z.ProductID == key && x.UserID == user.UserID
                            select new { z.ProductID, z.ProductName, y.Quantity, TotalPrice = y.Quantity * z.ProductPrice });



                if (data.Count() == 0)
                {
                    DetailTransaction d = new DetailTransaction();

                    var cekHeaderExist = (from x in db.HeaderTransactions
                                          where x.Status.Equals("Pending") && x.UserID == user.UserID
                                          select x).ToList();

                    cekH = cekHeaderExist.Count();



                    if (cekHeaderExist.Count() == 0)
                    {
                        HeaderTransaction h = new HeaderTransaction();

                        h.TransactionID = txtTransactionID.Text;
                        h.UserID        = txtUserID.Text;
                        h.Status        = "Pending";

                        db.HeaderTransactions.AddObject(h);
                        db.SaveChanges();
                    }

                    d.TransactionID = txtTransactionID.Text;
                    d.ProductID     = txtLaundryID.Text;
                    d.Quantity      = Convert.ToInt32(Math.Round(numericUpDown1.Value, 0));
                    d.Price         = Int32.Parse(txtPrice.Text);



                    db.DetailTransactions.AddObject(d);
                    db.SaveChanges();

                    refreshTableDetail();
                }
                else
                {
                    DetailTransaction d = (from x in db.DetailTransactions join y in db.HeaderTransactions on x.TransactionID equals y.TransactionID
                                           where x.ProductID == key && y.Status == "Pending" && y.UserID == user.UserID
                                           select x).First();

                    int qtt = Convert.ToInt32(Math.Round(numericUpDown1.Value, 0));

                    d.Quantity = d.Quantity + qtt;

                    db.SaveChanges();
                    refreshTableDetail();
                }
            }

            grandTotalGenerator();
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the HeaderTransactions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToHeaderTransactions(HeaderTransaction headerTransaction)
 {
     base.AddObject("HeaderTransactions", headerTransaction);
 }