protected void Button6_Click(object sender, EventArgs e)
        {
            int            rate;
            var            db            = new QCDBMLDataContext();
            int            pending_order = db.order_headers.Count(order_header => order_header.canteen_id == (int)Session["can_id"] && order_header.status == "placed");
            canteen_master canteen       = db.canteen_masters.Single(canteen_master => canteen_master.canteen_id == (int)Session["can_id"]);

            if (canteen.order_limit <= pending_order)
            {
                Label4.Text = "Canteen is overcrowded. Please order after a few minutes";
            }
            else
            {
                student_master student    = db.student_masters.Single(student_master => student_master.id == (int)Session["id"]);
                long           stu_wallet = (long)student.wallet;
                if (((int)Session["tot_amt"]) > stu_wallet)
                {
                    Label4.Text = "You dont have enough money in your wallet";
                }
                else
                {
                    student.wallet -= (int)Session["tot_amt"];
                    db.SubmitChanges();
                    canteen_master sel_canteen = db.canteen_masters.Single(canteen_master => canteen_master.canteen_id == (int)Session["can_id"]);
                    sel_canteen.wallet += (int)Session["tot_amt"];
                    db.SubmitChanges();
                    order_header neworder = new order_header();
                    neworder.stu_id     = (int)Session["id"];
                    neworder.canteen_id = (int)Session["can_id"];
                    neworder.order_date = DateTime.Now;
                    DateTime temp_date = (DateTime)neworder.order_date;
                    neworder.amount = (int)Session["tot_amt"];
                    neworder.status = "placed";
                    db.order_headers.InsertOnSubmit(neworder);
                    db.SubmitChanges();
                    order_header oh  = db.order_headers.Single(order_header => order_header.order_date.Equals(temp_date));
                    int          oid = oh.order_id;
                    foreach (GridViewRow gv2row in GridView2.Rows)
                    {
                        order_detail neworderdet = new order_detail();
                        neworderdet.order_id = oid;
                        food_master sel_food    = db.food_masters.Single(food_master => food_master.name.Equals(gv2row.Cells[1].Text));
                        int         sel_food_id = sel_food.food_item_id;
                        neworderdet.food_item_id = sel_food_id;
                        foreach (GridViewRow gvrow in GridView1.Rows)
                        {
                            if (gvrow.Cells[1].Text.Equals(gv2row.Cells[1].Text))
                            {
                                rate             = Int32.Parse(gvrow.Cells[3].Text);
                                neworderdet.rate = rate;
                                neworderdet.qty  = Int32.Parse(gv2row.Cells[2].Text);
                                break;
                            }
                        }
                        db.order_details.InsertOnSubmit(neworderdet);
                        menu_master menu = db.menu_masters.Single(menu_master => menu_master.canteen_id == neworder.canteen_id && menu_master.food_item_id == neworderdet.food_item_id);
                        menu.qty -= neworderdet.qty;
                        db.SubmitChanges();
                    }
                }
            }
            DropDownList1_SelectedIndexChanged(sender, e);
        }
Example #2
0
 partial void Updateorder_header(order_header instance);
Example #3
0
 partial void Deleteorder_header(order_header instance);
Example #4
0
 partial void Insertorder_header(order_header instance);