Exemplo n.º 1
0
        protected void btnXacNhan_Click(object sender, EventArgs e)
        {
            //try
            //{
            string receivername    = txtReceiverName.Text;
            string receiverphone   = txtReceiverPhone.Text;
            string receiveraddress = txtReceiverAddress.Text;
            string receiveremail   = txtReceiverEmail.Text;
            string orderdate       = lbBookDate.Text;
            string totalmoney      = lbTotalMoney.Text;
            int    paymentid       = int.Parse(drdPayment.SelectedValue);

            if (receivername == "" || receiverphone == "" || receiveraddress == "" || drdPayment.SelectedValue == "")
            {
                Response.Write("<script>alert('Chưa nhập đủ thông tin, nhập lại!')</script>");
            }
            else
            {
                DataTable dt = new DataTable();
                dt = bus.GetUserID();
                int userid = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    userid = int.Parse(dr["UserID"].ToString());
                }


                bus.InsertOrder(userid, orderdate, receivername, receiverphone, receiveraddress, receiveremail, paymentid, totalmoney);

                DataTable dtOrder = new DataTable();
                dtOrder = bus.GetOrder();
                int orderid = 0;
                foreach (DataRow dr in dtOrder.Rows)
                {
                    orderid = int.Parse(dr["OrderID"].ToString().Trim());
                }
                DataTable cart = new DataTable();
                cart = Session["cart"] as DataTable;
                foreach (DataRow dr in cart.Rows)
                {
                    int     productid       = int.Parse(dr["ID"].ToString());
                    decimal productcost     = Convert.ToDecimal(dr["Cost"].ToString());
                    int     productquantity = int.Parse(dr["Quantity"].ToString());
                    bus.InsertOrderDetail(orderid, productid, productcost, productquantity);
                }

                Session["cart"] = null;
                string alert = "Mua hàng thành công";
                Response.Redirect("~/Page/Home.aspx?alert=" + alert);
                //Response.Write("<script>alert('Mua hàng thành công')</script>");
            }
            //}
            //catch (Exception)
            //{

            //    Response.Write("<script>alert('Có lỗi rồi!')</script>");
            //}
        }