Beispiel #1
0
    protected void ibtnBuyNow_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["name"] != null)
        {
            string phoneid = Request.QueryString["PhoneId"].ToString();
            BuyerDSTableAdapters.aspnet_UsersTableAdapter userDA = new BuyerDSTableAdapters.aspnet_UsersTableAdapter();
            DataTable            userdDT    = userDA.GetDataByUName(Session["name"].ToString());
            string               buyer      = "";
            ShopCartTableAdapter shopcartDA = new ShopCartTableAdapter();
            if (userdDT.Rows.Count > 0)
            {
                buyer = userdDT.Rows[0][1].ToString();
                DataTable shopcartDT = shopcartDA.GetDataBySCidPid(System.Guid.Parse(buyer), long.Parse(phoneid));
                if (shopcartDT.Rows.Count > 0)
                {
                    int Dt = shopcartDA.UpdateCartQuantity(int.Parse(txtNum.Text), int.Parse(lblAllPrice.Text), DateTime.Now, "是", long.Parse(shopcartDT.Rows[0][0].ToString()));
                    if (Dt == 1)
                    {
                        Response.Redirect("~/Buyer/SubmitOrder.aspx");
                    }
                    else
                    {
                        Response.Write("<Script>alert('未能成功结算!')</Script>");
                    }
                }
                else
                {
                    string        ConnSql = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
                    SqlConnection Conn    = new SqlConnection(ConnSql);
                    Conn.Open();

                    string         SelectSql = "SELECT * FROM V_PhoneDetailInfo WHERE phone_id =" + long.Parse(phoneid) + "";
                    SqlDataAdapter da        = new SqlDataAdapter();
                    da.SelectCommand = new SqlCommand(SelectSql, Conn);
                    DataSet ds = new DataSet();
                    da.Fill(ds);

                    string seller = "";

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        seller = ds.Tables[0].Rows[0]["sellerId"].ToString().Trim();
                        int DT = shopcartDA.AddShoppingCart(System.Guid.Parse(buyer), System.Guid.Parse(seller), long.Parse(phoneid), int.Parse(txtNum.Text.Trim()), int.Parse(lblAllPrice.Text.Trim()), DateTime.Now, "是");
                        if (DT > 0)
                        {
                            Response.Redirect("~/Buyer/SubmitOrder.aspx");
                        }
                        else
                        {
                            Response.Write("<Script>alert('未能成功结算!')</Script>");
                        }
                    }
                }
            }
            else
            {
                Response.Write("<Script>alert('未能成功结算!')</Script>");
            }
        }
        else
        {
            Session["lasturl"] = Server.UrlDecode(Request.Url.AbsoluteUri.ToString());
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>openDiv('newDiv');</script>");
            //Response.Write("<Script>alert('登录后才能购买!')</Script>");
        }
    }
Beispiel #2
0
    protected void ibtnBuyNow_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["name"] != null)
        {
          string phoneid = Request.QueryString["PhoneId"].ToString();
            BuyerDSTableAdapters.aspnet_UsersTableAdapter userDA = new BuyerDSTableAdapters.aspnet_UsersTableAdapter();
            DataTable userdDT = userDA.GetDataByUName(Session["name"].ToString());
            string buyer = "";
            ShopCartTableAdapter shopcartDA = new ShopCartTableAdapter();
            if (userdDT.Rows.Count > 0)
            {
                buyer = userdDT.Rows[0][1].ToString();
                DataTable shopcartDT = shopcartDA.GetDataBySCidPid(System.Guid.Parse(buyer), long.Parse(phoneid));
                if (shopcartDT.Rows.Count > 0)
                {
                    int Dt = shopcartDA.UpdateCartQuantity(int.Parse(txtNum.Text), int.Parse(lblAllPrice.Text), DateTime.Now, "是", long.Parse(shopcartDT.Rows[0][0].ToString()));
                    if (Dt == 1)
                    {
                        Response.Redirect("~/Buyer/SubmitOrder.aspx");
                    }
                    else
                    {
                        Response.Write("<Script>alert('未能成功结算!')</Script>");
                    }
                }
                else
                {
                    string ConnSql = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
                    SqlConnection Conn = new SqlConnection(ConnSql);
                    Conn.Open();

                    string SelectSql = "SELECT * FROM V_PhoneDetailInfo WHERE phone_id =" + long.Parse(phoneid) + "";
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = new SqlCommand(SelectSql, Conn);
                    DataSet ds = new DataSet();
                    da.Fill(ds);

                    string seller = "";

                    if (ds.Tables[0].Rows.Count > 0)
                    {

                        seller = ds.Tables[0].Rows[0]["sellerId"].ToString().Trim();
                        int DT = shopcartDA.AddShoppingCart(System.Guid.Parse(buyer), System.Guid.Parse(seller), long.Parse(phoneid), int.Parse(txtNum.Text.Trim()), int.Parse(lblAllPrice.Text.Trim()), DateTime.Now, "是");
                        if (DT > 0)
                        {
                            Response.Redirect("~/Buyer/SubmitOrder.aspx");
                        }
                        else
                        {
                            Response.Write("<Script>alert('未能成功结算!')</Script>");
                        }
                    }

                }

            }
            else
            {
                Response.Write("<Script>alert('未能成功结算!')</Script>");
            }

        }
        else
        {
            Session["lasturl"] = Server.UrlDecode(Request.Url.AbsoluteUri.ToString());
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>openDiv('newDiv');</script>");
            //Response.Write("<Script>alert('登录后才能购买!')</Script>");
        }
    }