protected void btn_login_Click(object sender, EventArgs e)
        {
            string luname = txt_lusername.Text;
            string lpassword = CLASS.PasswordEncryption.EncryptIt(txt_lpassword.Text);
            try
            {
                IUser checkuser = new UserItems();

                //returns datatable if username and password are matched
                dt = checkuser.checklogin(luname, lpassword);
                if (dt != null)
                {
                    this.Session["currentuser"] = dt;
                    //lbl_login.Text = "Log In Successfull";
                    Response.Redirect("~/homepage.aspx");
                    //txt_lusername.Enabled = txt_lpassword.Enabled = false;
                }
                else
                {
                    lbl_login.Text = HardCodedValues.BuddaResource.LoginFail;
                }
            }
            catch (Exception ex)
            {
                lbl_login.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
            }
        }
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            string uname = txt_emailid.Text;
            string oldpassword = CLASS.PasswordEncryption.EncryptIt(txt_oldpwd.Text);
            string newpassword = CLASS.PasswordEncryption.EncryptIt(txt_newpwd.Text);
            try
            {
                IUser checkuser = new UserItems();

                //returns a table if given email id and password are matched
                dt = checkuser.checklogin(uname, oldpassword);
                if (dt != null)
                {
                    string userid = dt.Rows[0]["Uid"].ToString();
                    bool ispwdupdated = checkuser.UpdatePassword(userid, newpassword);
                    if (ispwdupdated)
                    {
                        lbl_submit.Text = HardCodedValues.BuddaResource.PwdChangeSuccess;
                    }
                    else
                    {
                        lbl_submit.Text = HardCodedValues.BuddaResource.Error;
                    }
                }
                else
                {
                    lbl_submit.Text = HardCodedValues.BuddaResource.LoginFail;
                }
            }
            catch (Exception ex)
            {
                lbl_submit.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
            }
        }
        public string LoginUser(string emailid, string password)
        {
            //string flag = string.Empty;
            string encryptedpwd = CLASS.PasswordEncryption.EncryptIt(password);
            try
            {

                IUser checkuser = new UserItems();

                //returns datatable if username and password are matched
                dt = checkuser.checklogin(emailid, encryptedpwd);
                if (dt != null)
                {
                    //flag = "Existing User";
                    this.Session["currentuser"] = dt;
                    return emailid;
                }
                else
                {
                    //flag = "Invalid User";
                    return "nouser";

                }
            }
            catch (Exception ex)
            {
                //flag = "Error: " + ex;
                return "nouser";
            }

            //return flag;
        }
Beispiel #4
0
        private void getOrders()
        {
            DataTable dt     = (DataTable)this.Session["currentuser"];
            string    userid = dt.Rows[0]["Uid"].ToString();

            try
            {
                BusinessLogicBS.UserClasses.UserItems getOrders = new BusinessLogicBS.UserClasses.UserItems();
                DataTable orderDT = getOrders.getUserOrders(userid);

                if (orderDT != null)
                {
                    orderGrid.DataSource = orderDT;
                    orderGrid.DataBind();
                }
                else
                {
                    //grpMsgLbl.Text = "No Data for items! change the catagory";
                    orderGrid.DataSource = null;
                    orderGrid.DataBind();
                }
            }
            catch (Exception iExp)
            {
                throw iExp;
            }
        }
        protected void btn_fsubmit_Click(object sender, EventArgs e)
        {
            //check whether the entered captcha text is matched or not
            if (this.txt_captcha.Text == this.Session["CaptchaImageText"].ToString())
            {
                string emailid = txt_femailid.Text;
                try
                {
                    IUser checkuser = new UserItems();

                    //returns table if given email id exists
                    dt = checkuser.checkavailability(emailid);
                    if (dt == null)
                    {
                        lbl_femailid.Text = HardCodedValues.BuddaResource.EmailIdNull;
                        // Create a random Captcha and store it in the Session object.
                        this.Session["CaptchaImageText"] = Captcha.CaptchaImage.GenerateRandomCode(HardCodedValues.BudhaConstants.RandomPasswordLength);
                        lbl_captcha.Text = string.Empty;
                    }
                    else
                    {
                        //if email id exists, then generate a new random password
                        string newpwd = GenerateRandomPassword(HardCodedValues.BudhaConstants.RandomPasswordLength);

                        //encrypt the given password to store in database
                        string encryptedpwd = CLASS.PasswordEncryption.EncryptIt(newpwd);

                        //update the new password in database
                        bool ispwdupdated = checkuser.UpdatePassword(emailid, encryptedpwd);
                        if (ispwdupdated)
                        {
                            //send the new password to the user email id
                            sendEmail(emailid, newpwd);

                            lbl_fsubmit.Text = HardCodedValues.BuddaResource.PwdForgotSuccess;
                            lbl_fsubmit.Font.Bold = true;
                        }
                        else
                        {
                            lbl_fsubmit.Text = HardCodedValues.BuddaResource.Error;
                        }
                    }
                }
                catch (Exception ex)
                {
                    lbl_fsubmit.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
                }
            }
            else
            {
                txt_captcha.Text = "";
                lbl_captcha.Text = HardCodedValues.BuddaResource.CaptchaError;
                // Create a random Captcha and store it in the Session object.
                this.Session["CaptchaImageText"] = Captcha.CaptchaImage.GenerateRandomCode(7);
                txt_captcha.Focus();
            }
        }
        public static AddressDetails[] showAdress()
        {
            List<AddressDetails> adrdetails = new List<AddressDetails>();
            //budhashop.USER.OrderPage pge = new budhashop.USER.OrderPage();
            if (HttpContext.Current.Session["currentuser"] != null)
            {
                DataTable dtt = (DataTable)HttpContext.Current.Session["currentuser"];
                string emailid = dtt.Rows[0]["Email"].ToString();

                try
                {

                    IUser retrieveuser = new UserItems();

                    //returns the table if given emailid exists
                    DataTable dt2 = retrieveuser.checkavailability(emailid);
                    if (dt2 != null)
                    {
                        AddressDetails adr = new AddressDetails();
                        //pge.txt_emailid.Text
                        adr.EmailId = dt2.Rows[0]["Email"].ToString();

                        //txt_uname.Text
                        adr.UserName = dt2.Rows[0]["UserName"].ToString();
                        //pge.txt_phno.Text
                        adr.Phone = dt2.Rows[0]["Phone"].ToString();
                        //pge.txt_address.Text
                        adr.Address = dt2.Rows[0]["Address"].ToString();

                        adrdetails.Add(adr);
                    }

                }
                catch (Exception ex)
                {
                    //pge.lbl_status.Text = "Error Occured : " + ex.Message;
                    throw ex;
                }
            }

            //ClientScript.RegisterHiddenField("isPostBack", "1");
            return adrdetails.ToArray();

            //pge.CartDiv.Visible = false;
            //pge.adressDiv.Visible = true;
            //return true;
        }
 public bool insertFeedback(string emailid, string msg)
 {
     try
     {
         IUser feedbackInsert = new UserItems();
         //insert feedback details in database with given values
         int count = feedbackInsert.insertFeedback(emailid, msg);
         if (count > 0)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch
     {
         return false;
     }
 }
        protected void retrieveUser(string emailid)
        {
            try
            {
                IUser retrieveuser = new UserItems();

                //returns the table if given emailid exists
                dt = retrieveuser.checkavailability(emailid);
                if (dt != null)
                {
                    txt_emailid.Text = dt.Rows[0]["Email"].ToString();
                    txt_uname.Text = dt.Rows[0]["UserName"].ToString();
                    txt_phno.Text = dt.Rows[0]["Phone"].ToString();
                    txt_address.Text = dt.Rows[0]["Address"].ToString();
                }
            }
            catch (Exception ex)
            {
                lbl_status.Text = "Error Occured : " + ex.Message;
            }
        }
 public bool UpdateProfile(string newvalue, string fieldname)
 {
     dt = (DataTable)this.Session["currentuser"];
     string userid = dt.Rows[0]["Uid"].ToString();
     try
     {
         IUser updateprofile = new UserItems();
         bool isupdated = updateprofile.UpdateProfile(userid, newvalue, fieldname);
         return isupdated;
     }
     catch
     {
         return false;
     }
 }
 public bool UpdatePassword(string oldpwd, string newpwd)
 {
     dt = (DataTable)this.Session["currentuser"];
     string emailid = dt.Rows[0]["Email"].ToString();
     string userid = dt.Rows[0]["Uid"].ToString();
     string validuser = LoginUser(emailid, oldpwd);
     if (validuser != "nouser")
     {
         string newpassword = CLASS.PasswordEncryption.EncryptIt(newpwd);
         try
         {
             IUser updatepassword = new UserItems();
             bool ispwdupdated = updatepassword.UpdatePassword(userid, newpassword);
             return ispwdupdated;
         }
         catch
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
        public bool RegisterUser(string emailid, string password)
        {
            try
            {
                IUser checkuser = new UserItems();

                //returns the table if given emailid exists
                dt = checkuser.checkavailability(emailid);
                if (dt == null)
                {
                    string encryptedpwd = CLASS.PasswordEncryption.EncryptIt(password);
                    BusinessEntitiesBS.UserEntities.userobj userObj = new BusinessEntitiesBS.UserEntities.userobj();

                    userObj.uname = "";
                    userObj.emailid = emailid;
                    userObj.pwd = encryptedpwd;
                    try
                    {
                        IUser userInsert = new UserItems();

                        //insert new user details in database with given values
                        userInsert.insertUser(userObj);

                        DataTable dt2 = userInsert.checklogin(emailid, encryptedpwd);

                        this.Session["currentuser"] = dt2;

                        return true;
                    }
                    catch (Exception exp)
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        protected void btn_reg_Click(object sender, EventArgs e)
        {
            if (lbl_checkemail.Text == HardCodedValues.BuddaResource.EmailIdAvailable)
            {
                //Check whether the Captcha text is correct or not
                if (this.txt_captcha.Text == this.Session["CaptchaImageText"].ToString())
                {
                    string uname = txt_username.Text;
                    string emailid = txt_emailid.Text;
                    string encryptedpwd = CLASS.PasswordEncryption.EncryptIt(txt_password.Text);

                    bool verfyDomain = verifyDomain(emailid);
                    bool chkEmail = sendEmail(emailid);

                    if (verfyDomain && chkEmail)
                    {
                        BusinessEntitiesBS.UserEntities.userobj userObj = new BusinessEntitiesBS.UserEntities.userobj();

                        userObj.uname = uname;
                        userObj.emailid = emailid;
                        userObj.pwd = encryptedpwd;
                        try
                        {
                            IUser userInsert = new UserItems();

                            //insert new user details in database with given values
                            userInsert.insertUser(userObj);

                            dt = userInsert.checklogin(emailid, encryptedpwd);
                            this.Session["currentuser"] = dt;

                            //lbl_register.Text = "Registration Successfull";
                            Response.Redirect("~/USER/ProfilePage.aspx");
                        }
                        catch (Exception exp)
                        {
                            lbl_register.Text = HardCodedValues.BuddaResource.CatchBlockError + exp.Message;
                        }
                    }
                    else
                    {
                        lbl_register.Text = "Registration Incomplete! Invalid email id or domain. Please provide valid email for regitration.";

                    }
                }
                else
                {
                    txt_captcha.Text = "";
                    lbl_captcha.Text = HardCodedValues.BuddaResource.CaptchaError;
                    // Create a random Captcha and store it in the Session object.
                    this.Session["CaptchaImageText"] = Captcha.CaptchaImage.GenerateRandomCode(7);
                    txt_captcha.Focus();
                }
            }
            else
            {
                txt_emailid.Focus();
            }
        }
        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";
            }
        }
        protected void txt_emailid_TextChanged(object sender, EventArgs e)
        {
            string emailid = txt_emailid.Text;
            bool ismatched = System.Text.RegularExpressions.Regex.IsMatch(emailid, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
            if (ismatched)
            {
                try
                {
                    IUser checkuser = new UserItems();

                    //returns the table if given emailid exists
                    dt = checkuser.checkavailability(emailid);
                    if (dt != null)
                    {
                        imgEmail.ImageUrl = "~/images/unavailable.png";
                        imgEmail.Visible = true;
                        lbl_checkemail.Text = HardCodedValues.BuddaResource.EmailIdExist;
                        lbl_checkemail.ForeColor = System.Drawing.Color.Red;
                        txt_emailid.Focus();
                    }
                    else
                    {
                        imgEmail.ImageUrl = "~/images/tick.png";
                        imgEmail.Visible = true;
                        lbl_checkemail.Text = HardCodedValues.BuddaResource.EmailIdAvailable;
                        lbl_checkemail.ForeColor = System.Drawing.Color.Green;
                    }
                }
                catch (Exception ex)
                {
                    lbl_checkemail.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
                }
            }
            else
            {
                imgEmail.ImageUrl = "~/images/unavailable.png";
                imgEmail.Visible = true;
                lbl_checkemail.Text = HardCodedValues.BuddaResource.EmailFormatError;
                lbl_checkemail.ForeColor = System.Drawing.Color.Red;
                txt_emailid.Focus();
            }
        }
        private void retrieveUser(string emailid)
        {
            try
            {
                IUser retrieveuser = new UserItems();

                //returns the table if given emailid exists
                DataTable dt = retrieveuser.checkavailability(emailid);
                if (dt != null)
                {
                    txt_emailid.Text = dt.Rows[0]["Email"].ToString();
                    txt_uname.Text = dt.Rows[0]["UserName"].ToString();
                    txt_phno.Text = dt.Rows[0]["Phone"].ToString();
                    txt_address.Text = dt.Rows[0]["Address"].ToString();
                }
            }
            catch (Exception ex)
            {
                lbl_status.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
            }
        }
        private void getOrders()
        {
            DataTable dt = (DataTable)this.Session["currentuser"];
            string userid = dt.Rows[0]["Uid"].ToString();
            try
            {
                BusinessLogicBS.UserClasses.UserItems getOrders = new BusinessLogicBS.UserClasses.UserItems();
                DataTable orderDT = getOrders.getUserOrders(userid);

                if (orderDT != null)
                {
                    orderGrid.DataSource = orderDT;
                    orderGrid.DataBind();
                }
                else
                {
                    //grpMsgLbl.Text = "No Data for items! change the catagory";
                    orderGrid.DataSource = null;
                    orderGrid.DataBind();
                }
            }
            catch (Exception iExp)
            {
                throw iExp;
            }
        }
        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>");
            }
        }
 public static int checkPid(int Pid)
 {
     IUser checkPid = new UserItems();
     int count = checkPid.checkPurchaseId(Pid);
     return count;
 }