Exemplo n.º 1
0
        protected void ConfirmBtn_Click(object sender, EventArgs e)
        {
            if (this.Session["currentuser"] != null)
            {
                //code for adding cart data in db and show back result to user
                DataTable dtt = (DataTable)this.Session["currentuser"];
                string userid = dtt.Rows[0]["Uid"].ToString();

                bool isupdated = true;

                if (cb_profilechange.Checked)
                {
                    string newuname = txt_uname.Text.ToString();
                    string newphno = txt_phno.Text.ToString();
                    string newaddress = txt_address.Text.ToString();
                    try
                    {
                        IUser updateuser = new UserItems();
                        bool nameupdated = updateuser.UpdateProfile(userid, newuname, "name");
                        if (nameupdated)
                        {
                            bool phnoupdated = updateuser.UpdateProfile(userid, newphno, "phno");
                            if (phnoupdated)
                            {
                                bool addressupdated = updateuser.UpdateProfile(userid, newaddress, "address");
                                if (!addressupdated)
                                {
                                    isupdated = false;
                                }
                            }
                            else
                            {
                                isupdated = false;
                            }
                        }
                        else
                        {
                            isupdated = false;
                        }
                    }
                    catch
                    {
                        isupdated = false;
                    }
                }

                if (isupdated)
                {

                    //string emailid = txt_emailid.Text.ToString();
                    string shippingAdr = txt_uname.Text.ToString() + ";" + txt_phno.Text.ToString() + ";" + txt_address.Text.ToString() + ";";
                    string purchaseDate = System.DateTime.Now.ToString();

                    CartDetails = new List<CartItems>();

                    CartDetails = (List<CartItems>)Session["CartPicks"];

                    String cartItems = "";
                    string sizeString = "";
                    float Total = 0;
                    int count = 0;

                    if (CartDetails != null)
                    {
                        foreach (object cartObj in CartDetails)
                        {

                            CartItems item = cartObj as CartItems;
                            count += 1;
                            int cid = item.ItemId;
                            int qty = item.Qty;
                            float tot = item.TotalBill;
                            Total += tot;
                            cartItems += cid + "," + qty + ";";
                            sizeString += item.TypeCheck + ";";
                        }
                    }
                    else
                    {
                        Response.Redirect("../homepage.aspx");
                    }

                    float TotalBill = Total;
                    int ItemsCount = count;
                    OrderItems insertOrder = new OrderItems();
                    insertOrder.userid = int.Parse(userid);
                    insertOrder.purchaseDate = purchaseDate;
                    insertOrder.ShippingAdr = shippingAdr;
                    insertOrder.cartItems = cartItems;
                    insertOrder.totalBill = TotalBill;
                    insertOrder.totalItems = ItemsCount;
                    insertOrder.TypeItem = sizeString;
                    insertOrder.areaId = Int32.Parse(areaAc.AreaId);

                    UserItems ordr = new UserItems();
                    int purchaseId = ordr.insertOrders(insertOrder);
                    if (purchaseId != -1)
                    {
                        LoadItemsFinal();
                        //CartDiv.Visible = false;
                        //adressDiv.Visible = false;
                        //cartData.Visible = true;
                        //cartDataGV.Visible = true;
                        Session["CartPicks"] = null;
                        //lbl_status.Text = "Order placed successfully";

                        purchaseIdLbl.Text = purchaseId.ToString();
                        totalpLbl.Text = TotalBill.ToString();
                        itemspNoLbl.Text = ItemsCount.ToString();
                        purchaseDateLbl.Text = purchaseDate;
                        userpNameLbl.Text = txt_uname.Text.ToString();
                        phnpLbl.Text = txt_phno.Text.ToString();
                        addrpLbl.Text = txt_address.Text.ToString();

                        adrFlag = true;
                        ClientScript.RegisterHiddenField("isPostBack", "1");

                        int status = sendEmail();
                        ClientScriptManager cs = Page.ClientScript;
                        if (status == 1)
                        {
                            //emailsentlbl.Text = "Order information has been sent to your email";
                            //emailsentlbl.Visible = true;
                            //Response.Redirect("../USER/ProfilePage.aspx");
                            cs.RegisterStartupScript(typeof(Page), "PrintScript_" + UniqueID, "showOrderMailedDiv();", true);

                        }
                        else
                        {
                            cs.RegisterStartupScript(typeof(Page), "PrintScript_" + UniqueID, "showOrderMailedDivError();", true);
                        }
                    }
                    else
                    {
                        //show error
                        lbl_status.Text = HardCodedValues.BuddaResource.Error;
                    }
                }
                else
                {
                    lbl_status.Text = HardCodedValues.BuddaResource.Error;
                }
            }
            else
            {
                Response.Write(@"<script language='javascript'>alert('Your Session has Expired...');window.location.replace('../homepage.aspx');</script>");
            }
        }
Exemplo n.º 2
0
        protected void ConfirmBtn_Click(object sender, EventArgs e)
        {
            //code for adding cart data in db and show back result to user
            DataTable dtt = (DataTable)this.Session["currentuser"];
            string userid = dtt.Rows[0]["Uid"].ToString();

            bool isupdated=true;

            if (cb_profilechange.Checked)
            {
                string newuname = txt_uname.Text.ToString();
                string newphno = txt_phno.Text.ToString();
                string newaddress = txt_address.Text.ToString();
                try
                {
                    IUser updateuser = new UserItems();
                    bool nameupdated = updateuser.UpdateProfile(userid, newuname, "name");
                    if (nameupdated)
                    {
                        bool phnoupdated = updateuser.UpdateProfile(userid, newphno, "phno");
                        if (phnoupdated)
                        {
                            bool addressupdated = updateuser.UpdateProfile(userid, newaddress, "address");
                            if (!addressupdated)
                            {
                                isupdated = false;
                            }
                        }
                        else
                        {
                            isupdated = false;
                        }
                    }
                    else
                    {
                        isupdated = false;
                    }
                }
                catch
                {
                    isupdated = false;
                }
            }

            if (isupdated)
            {

                //string emailid = txt_emailid.Text.ToString();
                string shippingAdr = txt_uname.Text.ToString() + ";" + txt_phno.Text.ToString() + ";" + txt_address.Text.ToString() + ";";
                string purchaseDate = System.DateTime.Now.ToString();

                CartDetails = new List<CartItems>();

                CartDetails = (List<CartItems>)Session["CartPicks"];

                String cartItems = "";
                float Total = 0;
                int count = 0;

                foreach (object cartObj in CartDetails)
                {

                    CartItems item = cartObj as CartItems;
                    count += 1;
                    int cid = item.ItemId;
                    int qty = item.Qty;
                    float tot = item.TotalBill;
                    Total += tot;
                    cartItems += cid + "," + qty + ";";

                }

                float TotalBill = Total;
                int ItemsCount = count;
                OrderItems insertOrder = new OrderItems();
                insertOrder.userid = int.Parse(userid);
                insertOrder.purchaseDate = purchaseDate;
                insertOrder.ShippingAdr = shippingAdr;
                insertOrder.cartItems = cartItems;
                insertOrder.totalBill = TotalBill;
                insertOrder.totalItems = ItemsCount;

                UserItems ordr = new UserItems();
                int purchaseId = ordr.insertOrders(insertOrder);
                if (purchaseId != -1)
                {
                    adressDiv.Visible = false;
                    cartDataGV.Visible = true;
                    Session["CartPicks"] = null;
                }
                else
                {
                    //show error
                }
            }
            else
            {
                lbl_status.Text = "Error Occured, Try Again";
            }
        }