예제 #1
0
    private ShopCarData GetShopCarData(string iPID, ShopCarData[] iData)
    {
        ShopCarData TempData = new ShopCarData();

        for (int i = 0; i < iData.Length; i++)
        {
            if (iPID == iData[i].ID)
            {
                TempData = iData[i];
                return(TempData);
            }
        }

        return(TempData);
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string      aJsonDataStr = Request["JsonData"].ToString();
            ShopCarData aShopCarData = JsonConvert.DeserializeObject <ShopCarData>(aJsonDataStr);

            HttpCookie aAccountCookie = Request.Cookies["Account"];
            string     aAccount       = aAccountCookie.Value;

            HttpCookie aCookie = Request.Cookies[aAccount];
            //取得cookie字串
            string aCookieData = aCookie.Value;
            //把資料分隔開來
            string[] aNewContent = aCookieData.Split(Convert.ToChar(','));
            //重新給陣列大小
            Array.Resize(ref mProductID, aNewContent.Length);
            Array.Resize(ref mProductCount, aNewContent.Length);

            for (int i = 0; i < aNewContent.Length; i++)
            {
                string[] aTemp = aNewContent[i].Split(Convert.ToChar('|'));
                mProductID[i]    = aTemp[0];
                mProductCount[i] = aTemp[1];
            }
            //開始寫入SQL
            try
            {
                string aStr = "INSERT INTO BuyData(ProductID,ProductCount,CardNumber,Password,BuyAddress,BuyName,BuyPhone,GetName,GetPhone,GetAddress,UserAccount,SingleNumber,RecTime) VALUES('{0}','{1}','{2}','{3}',N'{4}',N'{5}','{6}',N'{7}','{8}',N'{9}','{10}','{11}','{12}')";

                using (SqlConnection vCon = new SqlConnection("Data Source=184.168.47.10;Integrated Security=False;User ID=MobileDaddy;PASSWORD=Aa54380438!;Connect Timeout=15;Encrypt=False;Packet Size=4096"))
                {
                    vCon.Open();

                    string aSingleNumber = GetSingleNumber();
                    string aRecTime      = DateTime.Now.ToString("yyyy-MM-dd HH:mm");

                    for (int i = 0; i < mProductID.Length; i++)
                    {
                        string aBuyAddress = GetAddress(aShopCarData.BuyAddressCity, aShopCarData.BuyAddressArea, aShopCarData.BuyAddress);
                        string aGetAddress = GetAddress(aShopCarData.GetAddressCity, aShopCarData.GetAddressArea, aShopCarData.GetAddress);

                        string aSQLStr = string.Format(aStr, mProductID[i], mProductCount[i], aShopCarData.CardNumber, aShopCarData.Password, aBuyAddress, aShopCarData.BuyName, aShopCarData.BuyPhone, aShopCarData.GetName, aShopCarData.GetPhone, aGetAddress, aAccount, aSingleNumber, aRecTime);

                        using (SqlCommand vCmd = new SqlCommand(aSQLStr, vCon))
                        {
                            vCmd.ExecuteNonQuery();
                        }
                    }
                }

                Response.Write("1");
            }
            catch
            {
            }
        }
        catch
        {
            Response.Write("2");
        }
    }