protected void Page_Load(object sender, EventArgs e) { int id = -1; if (Request.QueryString["id"] == null || !int.TryParse(Request.QueryString["id"], out id)) { Response.Redirect("AddProgram.aspx"); } try { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "delete from LH_Programs where id = @id"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@id", id); SqlDataReader dr = cmd.ExecuteReader(); Response.Redirect("AddProgram.aspx"); } catch (Exception) { Response.Redirect("AddProgram.aspx"); throw; } }
protected void search_button_click(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(Login.GetConnectionString()); //string strsql = "select * from LH_product join LH_product_image on LH_product_image.ID =" + // "(select top 1 LH_product_image.ID from LH_product_image where LH_product_image.product_id = LH_product.ID) where LH_product.title like @searchTxt or LH_product.description like @searchTxt"; string strsql = "SELECT LP.ID,LP.title,LP.description,LP.earnedLP,LP.price,LP.category,LPI.ID,LPI.product_id,LPI.image,LHW.ID,CASE WHEN LHW.ID IS NULL THEN '0' ELSE '1' END AS IsSelected FROM LH_PRODUCT LP JOIN LH_PRODUCT_IMAGE LPI ON LPI.ID =" + "(SELECT TOP 1 LPII.ID FROM LH_PRODUCT_IMAGE LPII WHERE LPII.PRODUCT_ID=LP.ID) LEFT join LH_WISHLIST LHW ON LHW.ID =" + "(SELECT ID FROM LH_WISHLIST LHWW WHERE LHWW.PRODUCTID = LP.ID AND USERID = @userID) where LP.title like @searchTxt or LP.description like @searchTxt "; con.Open(); SqlCommand cmd = new SqlCommand(strsql, con); cmd.Parameters.AddWithValue("searchTxt", "%" + search_txt.Value + "%"); cmd.Parameters.AddWithValue("@userID", userID); SqlDataReader dr = cmd.ExecuteReader(); productList.InnerHtml = ""; int i = 0; while (dr.Read()) { createProduct(int.Parse(dr[0].ToString()), dr["image"].ToString(), dr["title"].ToString(), dr["description"].ToString(), float.Parse(dr["price"].ToString()), dr["IsSelected"].ToString(), i, int.Parse(dr["earnedLP"].ToString())); i++; } con.Close(); } catch (Exception) { throw; } }
public int GetCountofCart(int userid) { int ncount = -1; //string wishList = Request.Form["WISHLIST"]; // int count=-1; // Session["Count"] = 0; SqlConnection con = new SqlConnection(Login.GetConnectionString()); string strsql = "select Count(*) from LH_cart where user_ID=@userid"; try { con.Open(); SqlCommand cmd = new SqlCommand(strsql, con); cmd.Parameters.AddWithValue("@userid", userid); ncount = (int)cmd.ExecuteScalar(); CartIconList_ex.InnerText = Convert.ToString(ncount); return(ncount); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } finally { con.Close(); } }
protected int GetCartCount(int uid) { int Cartcount; // int count=-1; SqlConnection con = new SqlConnection(Login.GetConnectionString()); string strsql = "select Count(*) from LH_cart where user_ID=@uid"; try { con.Open(); SqlCommand cmd = new SqlCommand(strsql, con); cmd.Parameters.AddWithValue("@uid", uid); Cartcount = (int)cmd.ExecuteScalar(); Session["CartCount"] = Cartcount; return(Cartcount); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } finally { con.Close(); } }
public static bool checkUser(string userName) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); try { string query = "select count(*) from LH_Programs where Username = @username"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@username", userName); SqlDataReader dr = cmd.ExecuteReader(); int result = -1; dr.Read(); int.TryParse(dr[0].ToString(), out result); if (result == 0) { return(true); } else { return(false); } } catch (Exception e) { return(false); throw; } }
public static int AddWishlist(int userid, int productid) { // int userid = int.Parse(Request.Form["userID"]); int productid = int.Parse(Request.Form["productID"]); // Response.Write("AAA----UserID:"+userid.ToString()+"----productID:"+productid.ToString()); int cnt = 0; try { if (userid != null && productid != null) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string Sql = "insert into LH_WishList(UserId,ProductID)values(@val1,@val2)"; con.Open(); SqlCommand cmd = new SqlCommand(Sql, con); cmd.Parameters.AddWithValue("@val1", userid); cmd.Parameters.AddWithValue("@val2", productid); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); con.Close(); // GetCount(userid); // Product p = new Product(); //p.GetCount(userid); // cnt = p.GetCount(userid); } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } return(cnt); }
public static int Deletecartitem(int userid, int productID) { int cnt = 0; try { { SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); string Sql1 = "delete from LH_cart where user_ID=@userid and product_ID=@product_ID"; con1.Open(); SqlCommand cmd1 = new SqlCommand(Sql1, con1); cmd1.Parameters.AddWithValue("@UserId", userid); cmd1.Parameters.AddWithValue("@product_ID", productID); cmd1.CommandType = CommandType.Text; cmd1.ExecuteNonQuery(); con1.Close(); // GetCount(userid); //Product p = new Product(); //p.GetCount(userid); cnt = GetCount(userid); } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } return(cnt); }
protected void Page_Load(object sender, EventArgs e) { if (Session["login"] != null) { string username = null; if (Session["id"] != null) { int.TryParse(clsRidjindalEncryption.Decrypt(Session["id"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256), out userID); } if (Session["userName"] != null) { username = clsRidjindalEncryption.Decrypt(Session["userName"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string email = null; if (Session["email"] != null) { email = clsRidjindalEncryption.Decrypt(Session["email"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string pwd = null; if (Session["pwd"] != null) { pwd = clsRidjindalEncryption.Decrypt(Session["pwd"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } bool isSession = (Session["login"] != null) ? clsRidjindalEncryption.Decrypt(Session["login"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256) == "1" : false; if (Login.checkLogin(username, email, pwd, isSession) != null) { sign.Visible = false; usernameDiv.Visible = true; usernametxt.InnerText = username; } else { sign.Visible = true; usernameDiv.Visible = false; } SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "SELECT LP.ID,LP.title,LPI.image,LP.description,LP.price,LP.category,LP.featured,LPI.ID,LPI.product_id,LPI.image,LHW.ID,CASE WHEN LHW.ID IS NULL THEN '0' ELSE '1' END AS IsSelected FROM LH_PRODUCT LP JOIN LH_PRODUCT_IMAGE LPI ON LPI.ID =(SELECT TOP 1 LPII.ID FROM LH_PRODUCT_IMAGE LPII WHERE LPII.PRODUCT_ID = LP.ID) LEFT join LH_WISHLIST LHW ON LHW.ID = (SELECT top 1 ID FROM LH_WISHLIST LHWW WHERE LHWW.PRODUCTID = LP.ID ) where LP.featured = 1"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { createProduct(int.Parse(dr[0].ToString()), dr[9].ToString(), dr["title"].ToString(), dr["description"].ToString(), float.Parse(dr["price"].ToString()), dr["IsSelected"].ToString()); } con.Close(); } else { Response.Redirect("logout.aspx"); } }
public static int Add2Cart(int userid, int productid) { int cnt = 0; bool BRecExist = false; try { SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); SqlCommand cmd1 = new SqlCommand("select product_ID from LH_cart where user_ID = " + userid + " and product_ID=" + productid + " ", con1); con1.Open(); SqlDataReader reader = cmd1.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); con1.Close(); int numRows = dt.Rows.Count; if (numRows > 0) { BRecExist = true; return(0); } else { BRecExist = false; } if (userid != null && productid != null) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string Sql = "insert into LH_cart(user_ID,product_ID,quantity)values(@val1,@val2,1)"; con.Open(); SqlCommand cmd = new SqlCommand(Sql, con); cmd.Parameters.AddWithValue("@val1", userid); cmd.Parameters.AddWithValue("@val2", productid); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); con.Close(); // GetCount(userid); cnt = GetCartCount(userid); } } catch (Exception ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } if (BRecExist == false) { return(cnt); } else { return(0); } }
private void InsertInfo() { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string MiddleName = "ddd"; string Country = "ksa"; string City = "Riyadh"; string state = "Riyadh"; string Sql = "insert into LH_User(FirstName,LastName,Password,Email,Mobile,Create_Date,Update_Date,UserName,MiddleName,Country,City,State,activationCode) values(@val1,@val2,@val3,@val4,@val5,@val6,@val7,@val8,'ddd','ksa','Riyadh','Riyadh',@activation)"; try { string activationCode = Guid.NewGuid().ToString(); if (txtUname.Text == "" || txtEmail.Value == "" || txtFname.Value == "" || txtLname.Value == "" || txtMobile.Text == "" || txtPswd.Text == "" || txtremail.Value == "" || txtrePswd.Text == "") { Response.Redirect("SignUp.aspx"); } // string brecordexist = "Username already exist"; else { con.Open(); } SqlCommand cmd = new SqlCommand(Sql, con); cmd.Parameters.AddWithValue("@val1", txtFname.Value); cmd.Parameters.AddWithValue("@val2", txtLname.Value); cmd.Parameters.AddWithValue("@val3", txtPswd.Text); cmd.Parameters.AddWithValue("@val4", txtEmail.Value); cmd.Parameters.AddWithValue("@val5", txtMobile.Text); cmd.Parameters.AddWithValue("@val6", DateTime.Now); cmd.Parameters.AddWithValue("@val7", DateTime.Now); cmd.Parameters.AddWithValue("@val8", txtUname.Text); cmd.Parameters.AddWithValue("@activation", activationCode); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/"; Login.sendEmail(txtEmail.Value, baseUrl + "activation.aspx?c=" + activationCode); } catch (Exception ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } finally { con.Close(); Session["UserName"] = txtUname.Text; } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["c"] != null) { int id = -1; string email = null; string code = Request.QueryString["c"]; SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "select id,Email from LH_User where activationCode = @code"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@code", code); SqlDataReader dr = cmd.ExecuteReader(); if (!dr.HasRows) { Response.Write("Activation Failed."); } else { while (dr.Read()) { id = int.Parse(dr["id"].ToString()); email = dr["email"].ToString(); con.Close(); con.Open(); query = "update LH_user set active = 1 where id = @id"; cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@id", id); cmd.ExecuteReader(); con.Close(); break; } Login.sendEmail(email, "Account Activated."); activationtxt.Visible = true; error.Visible = false; } } else { activationtxt.Visible = false; error.Visible = true; } }
protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "select * from LH_user where Email = @email or mobile = @mobile"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@email", txtEmail.Value); cmd.Parameters.AddWithValue("@mobile", txtMobile.Text); SqlDataReader dr = cmd.ExecuteReader(); if (!dr.HasRows) { con.Close(); int id = -1; if (Session["id"] != null) { int.TryParse(clsRidjindalEncryption.Decrypt(Session["id"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256), out id); } query = "update LH_User set FirstName ='" + txtFname.Value + "',LastName ='" + txtLname.Value + "',Mobile ='" + txtMobile.Text + "',Email ='" + txtEmail.Value + "' where Id='" + id + "'"; con.Open(); cmd = new SqlCommand(query, con); try { cmd.ExecuteNonQuery(); messageTxt.InnerText = "data updated successfully"; } catch (Exception) { messageTxt.InnerText = "data not updated"; } finally { con.Close(); //Response.Redirect("AddProgram.aspx"); } } else { messageTxt.InnerText = "Email or mobile is already inserted before."; } }
public static string[] checkLogin(string username, string email, string password, bool isSession) { try { string[] result = new string[6]; SqlConnection con = new SqlConnection(Login.GetConnectionString()); string strsql = "select Id, UserName,Email,role,Mobile,isLoggedIn,retailerID from dbo.LH_User where (username=@UserName or email=@UserName) and password=@Password "; con.Open(); SqlCommand cmd = new SqlCommand(strsql, con); cmd.Parameters.AddWithValue("@UserName", username); cmd.Parameters.AddWithValue("@Password", password); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { //bool islogged = bool.Parse(dr["isLoggedIn"].ToString()); //if (islogged && !isSession) //{ // return null; //} result[0] = dr["Id"].ToString(); result[1] = dr["UserName"].ToString(); result[2] = dr["email"].ToString(); result[3] = dr["role"].ToString(); result[4] = dr["mobile"].ToString(); result[5] = dr["retailerID"].ToString(); break; } return(result); } else { return(null); } } catch (Exception ex) { return(null); throw; } }
public static float getProgramsCount(int userID) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "select * from LH_programs join LH_programs_list on LH_Programs.program = LH_programs_list.ID "; con.Open(); SqlCommand cmd = new SqlCommand(query, con); SqlDataReader dr = cmd.ExecuteReader(); float count = -1; while (dr.Read()) { count += float.Parse(dr["rate"].ToString()) * float.Parse(dr["Points"].ToString()); } return(count); }
// [System.Web.Services.WebMethod] public static int GetCount(int userid) { int ncount = -1; //string wishList = Request.Form["WISHLIST"]; // int count=-1; // Session["Count"] = 0; SqlConnection con = new SqlConnection(Login.GetConnectionString()); string strsql = "select Count(*) from LH_WishList where UserId=@userid"; try { con.Open(); SqlCommand cmd = new SqlCommand(strsql, con); cmd.Parameters.AddWithValue("@userid", userid); ncount = (int)cmd.ExecuteScalar(); // HttpContext.Current.Session["Count"] = ncount; //for (int Count = 0; Count <= ncount; ncount++) //{ //Session["CountWishIcon"] = ncount; //Label wishList = (Label)this.form1.FindControl("wishList"); //wishIconList_ex.InnerText = ncount.ToString(); //} // wishList.InnerText =Convert.ToString(ncount); // wishList.InnerText= HttpContext.Current.Session["Count"].ToString(); //Label wishList = (Label)page.FindControl("wishList"); // ncount = ncount - 1; return(ncount); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } finally { con.Close(); } }
public static int removeWishList(int userid, int productid) { try { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "delete from LH_WishList where productID = @productID and UserId = @userID"; SqlCommand cmd = new SqlCommand(query, con); con.Open(); cmd.Parameters.AddWithValue("@productID", productid); cmd.Parameters.AddWithValue("@userid", userid); SqlDataReader dr = cmd.ExecuteReader(); return(GetCount(userid)); } catch (Exception ex) { return(0); } }
public static string doResetPassword(string password, int id, string email, string code) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); try { SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); string query1 = "select id,Email from LH_User where resetCode = @code"; con.Open(); SqlCommand cmd1 = new SqlCommand(query1, con1); cmd1.Parameters.AddWithValue("@code", code); SqlDataReader dr1 = cmd1.ExecuteReader(); if (!dr1.HasRows) { return("diffrent code"); } string query = "update LH_User set Password = @password where id = @id"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@id", id); cmd.Parameters.AddWithValue("@password", password); SqlDataReader dr = cmd.ExecuteReader(); con.Close(); Login.sendEmail(email, "Password Reset Finished. ;)"); return("Password Reset Done."); } catch (Exception) { con.Close(); return("Failed to reset the password."); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["c"] != null) { string code = Request.QueryString["c"]; SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "select id,Email from LH_User where resetCode = @code"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@code", code); SqlDataReader dr = cmd.ExecuteReader(); if (!dr.HasRows) { Response.Redirect("Login.aspx"); } while (dr.Read()) { idtxt.Value = dr["id"].ToString(); emailtxt.Value = dr["email"].ToString(); HttpCookie myCookie = new HttpCookie("code"); // Set the cookie value. myCookie.Value = code; // Add the cookie. Response.Cookies.Add(myCookie); } con.Close(); } else { Response.Redirect("Login.aspx"); } }
protected void search_Click(object sender, EventArgs e) { try { string searchValue = programSearchtxt.Value; int categoryID = int.Parse(programCategory.Value); SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "select * from LH_programs_list where id not in(select program from LH_Programs where user_Id = @userID) "; if (categoryID != -1) { query += " and category = @category "; } if (searchValue != "") { query += " and name like @search"; } con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@userID", userID); if (categoryID != -1) { cmd.Parameters.AddWithValue("@category", categoryID); } if (searchValue != "") { cmd.Parameters.AddWithValue("@search", "%" + searchValue + "%"); } SqlDataReader dr = cmd.ExecuteReader(); programList.InnerHtml = ""; while (dr.Read()) { createProgram(int.Parse(dr["id"].ToString()), dr["logo"].ToString()); } } catch (Exception) { throw; } }
protected void Page_Load(object sender, EventArgs e) { int userID = -1; SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "update LH_User set isLoggedIn = 0 where id = @id"; if (Session["id"] != null) { int.TryParse(clsRidjindalEncryption.Decrypt(Session["id"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256), out userID); } con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@id", userID); SqlDataReader dr = cmd.ExecuteReader(); Session.Clear(); HttpCookie aCookie; string cookieName; int limit = Request.Cookies.Count; for (int i = 0; i < limit; i++) { cookieName = Request.Cookies[i].Name; aCookie = new HttpCookie(cookieName); aCookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(aCookie); } Response.Redirect("Login.aspx"); }
public static int UserLHP(int userID) { try { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "select LHP from LH_User where ID = @userID"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@userID", userID); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); return(int.Parse(dr[0].ToString())); } catch (Exception e) { return(0); } }
public static string sendForgot(string email) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); string query = "select id,email,UserName,Mobile from LH_User where userName = @email or Email = @email"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@email", email); SqlDataReader dr = cmd.ExecuteReader(); if (!dr.HasRows) { return("No Such UserName Or Email."); } else { while (dr.Read()) { Guid resetCode = Guid.NewGuid(); string baseURL = "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port; string message = baseURL + "/resetPassword.aspx?c=" + resetCode.ToString(); con1.Open(); string query1 = "update LH_User set resetCode = @resetCode where id = @id"; SqlCommand cmd1 = new SqlCommand(query1, con1); cmd1.Parameters.AddWithValue("@resetCode", resetCode.ToString()); cmd1.Parameters.AddWithValue("@id", int.Parse(dr["id"].ToString())); cmd1.ExecuteReader(); bool emailSent = sendEmail(dr["email"].ToString(), message); con1.Close(); return("Activation Link Sent To Your Email."); } return("Activation Link Sent To Your Email."); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["login"] != null) { string username = null; if (Session["id"] != null) { int.TryParse(clsRidjindalEncryption.Decrypt(Session["id"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256), out userID); } if (Session["userName"] != null) { username = clsRidjindalEncryption.Decrypt(Session["userName"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string email = null; if (Session["email"] != null) { email = clsRidjindalEncryption.Decrypt(Session["email"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string pwd = null; if (Session["pwd"] != null) { pwd = clsRidjindalEncryption.Decrypt(Session["pwd"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } if (Login.checkLogin(username, email, pwd, clsRidjindalEncryption.Decrypt(Session["login"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256) == "1") == null || userID == -1) { Response.Redirect("Login.aspx"); } int cnt = 0; lhptxt.InnerText = (Login.UserLHP(userID) + Login.getProgramsCount(userID)).ToString();; hdfuserid.Value = userID.ToString(); int nuserid = Convert.ToInt32(hdfuserid.Value); GetCountWishlist(nuserid); GetCountofCart(nuserid); cartuser.InnerText = username; SqlConnection conn = new SqlConnection(Login.GetConnectionString()); string strsql1 = "select * from LH_Programs join LH_Rates on LH_Programs.program = LH_Rates.Program_ID join LH_programs_list on LH_Programs.program = LH_programs_list.ID where LH_Rates.Approved = 1 and LH_Programs.User_Id = @userID"; conn.Open(); SqlCommand cmd1 = new SqlCommand(strsql1, conn); cmd1.Parameters.AddWithValue("@userID", hdfuserid.Value); SqlDataReader dr2 = cmd1.ExecuteReader(); int i = 0; while (dr2.Read()) { i++; Createprogram(int.Parse(dr2["User_Id"].ToString()), double.Parse(dr2["Rate"].ToString()), dr2["logo"].ToString(), dr2["name"].ToString(), dr2["points"].ToString(), dr2["program"].ToString(), i, dr2["username"].ToString()); // wishlistbar(dr2[16].ToString()); } conn.Close(); SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); string strsql = "select * from LH_product LHP join LH_Cart LHC on LHC.product_ID = LHP.ID " + "join LH_product_image LHI on LHI.ID = (select top 1 LHII.ID from LH_product_image LHII where LHII.product_id = LHP.ID) WHERE LHC.user_ID=@userID"; con1.Open(); SqlCommand cmd = new SqlCommand(strsql, con1); cmd.Parameters.AddWithValue("@userID", hdfuserid.Value); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { cnt++; CreateCart(dr["title"].ToString(), dr["description"].ToString(), float.Parse(dr["price"].ToString()), dr["image"].ToString(), dr["ID"].ToString()); kk.InnerText = Convert.ToString(cnt); // string totlpts = totalpnts.InnerText; } con1.Close(); } else { Response.Redirect("logout.aspx"); } }
public static int AddWishlist(int userid, int productid) { // int userid = int.Parse(Request.Form["userID"]); int productid = int.Parse(Request.Form["productID"]); // Response.Write("AAA----UserID:"+userid.ToString()+"----productID:"+productid.ToString()); int cnt = 0; bool BRecExist = false; try { SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); SqlCommand cmd1 = new SqlCommand("select ProductID from LH_WishList where UserId = " + userid + " and ProductID=" + productid + " ", con1); // SqlParameter param = new SqlParameter(); //param.ParameterName = "@UserID"; //param.Value = userid; // cmd1.Parameters.Add(param); con1.Open(); SqlDataReader reader = cmd1.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); con1.Close(); int numRows = dt.Rows.Count; if (numRows > 0) { BRecExist = true; return(0); } else { BRecExist = false; } if (userid > 0 && productid > 0 && BRecExist == false) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string Sql = "insert into LH_WishList(UserId,ProductID)values(@val1,@val2)"; con.Open(); SqlCommand cmd = new SqlCommand(Sql, con); cmd.Parameters.AddWithValue("@val1", userid); cmd.Parameters.AddWithValue("@val2", productid); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); con.Close(); cnt = GetCount(userid); } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } if (BRecExist == false) { return(cnt); } else { return(0); } }
protected void Page_Load(object sender, EventArgs e) { try { if (Session["login"] != null) { string username = null; if (Session["id"] != null) { int.TryParse(clsRidjindalEncryption.Decrypt(Session["id"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256), out userID); } if (Session["userName"] != null) { username = clsRidjindalEncryption.Decrypt(Session["userName"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string email = null; if (Session["email"] != null) { email = clsRidjindalEncryption.Decrypt(Session["email"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string pwd = null; if (Session["pwd"] != null) { pwd = clsRidjindalEncryption.Decrypt(Session["pwd"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } bool isSession = (Session["login"] != null) ? clsRidjindalEncryption.Decrypt(Session["login"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256) == "1" : false; if (Login.checkLogin(username, email, pwd, isSession) == null || userID == -1) { Response.Redirect("Login.aspx"); } usernametxt.InnerText = username; lhptxt.InnerText = (Login.UserLHP(userID) + Login.getProgramsCount(userID)).ToString(); hdfuserid.Value = userID.ToString(); int nuserid = Convert.ToInt32(hdfuserid.Value); GetCountWishlist(nuserid); GetCountofCart(nuserid); SqlConnection con = new SqlConnection(Login.GetConnectionString()); string strsql = "select * from LH_product LHP join LH_wishList LHW on LHW.productID = LHP.ID " + "join LH_product_image LHI on LHI.ID = (select top 1 LHII.ID from LH_product_image LHII where LHII.product_id = LHP.ID) WHERE LHW.userID=@UserId"; con.Open(); SqlCommand cmd = new SqlCommand(strsql, con); // cmd.Parameters.AddWithValue("@hdfuserid", hdfuserid.Value); cmd.Parameters.AddWithValue("@UserId", hdfuserid.Value); SqlDataReader dr = cmd.ExecuteReader(); int i = 0; while (dr.Read()) { createProduct(int.Parse(dr[0].ToString()), dr["image"].ToString(), dr["title"].ToString(), dr["description"].ToString(), float.Parse(dr["price"].ToString()), i, int.Parse(dr["earnedLP"].ToString())); i++; } con.Close(); con.Open(); strsql = "select * from LH_Programs join LH_Rates on LH_Programs.Id = LH_Rates.Program_ID join LH_programs_list on LH_Programs.program = LH_programs_list.ID where LH_Rates.Approved = 1 and LH_Programs.User_Id = @userID"; cmd = new SqlCommand(strsql, con); cmd.Parameters.AddWithValue("userID", 4); dr = cmd.ExecuteReader(); while (dr.Read()) { HtmlGenericControl walletGrid = new HtmlGenericControl("div"); walletContainer.Controls.Add(walletGrid); } con.Close(); //if ((Session["id"] == null || !int.TryParse(Session["id"].ToString(), out userID)) && (Request.Cookies["id"] == null || !int.TryParse(Request.Cookies["id"].Value, out userID))) //{ // Response.Redirect("Login.aspx"); //} //else //{ // // wishIconList_ex.InnerText = Session["Count"].ToString(); // //txtuserid.Text = Session["Id"].ToString(); // if ((Session["username"] == null || !int.TryParse(Session["username"].ToString(), out Username)) && (Request.Cookies["username"] == null || !int.TryParse(Request.Cookies["Username"].Value, out Username))) // wishuser.InnerText = Session["username"].ToString(); //} } else { Response.Redirect("logout.aspx"); } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["login"] != null) { string username = null; if (Session["id"] != null) { int.TryParse(clsRidjindalEncryption.Decrypt(Session["id"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256), out userID); } if (Session["userName"] != null) { username = clsRidjindalEncryption.Decrypt(Session["userName"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string email = null; if (Session["email"] != null) { email = clsRidjindalEncryption.Decrypt(Session["email"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string pwd = null; if (Session["pwd"] != null) { pwd = clsRidjindalEncryption.Decrypt(Session["pwd"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } if (Login.checkLogin(username, email, pwd, clsRidjindalEncryption.Decrypt(Session["login"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256) == "1") == null || userID == -1) { Response.Redirect("Login.aspx"); } int productID; if (Request.QueryString["id"] == null || !int.TryParse(Request.QueryString["id"], out productID)) { Response.Redirect("Products.aspx"); } else { lhptxt.InnerText = (Login.UserLHP(userID) + Login.getProgramsCount(userID)).ToString(); usernametxt.InnerText = username; hdfuserid.Value = userID.ToString(); wishListTxt.InnerText = Login.countWishList(userID).ToString(); cartTxt.InnerText = Login.countCart(userID).ToString(); title_label.InnerText = productID.ToString(); SqlConnection con = new SqlConnection(Login.GetConnectionString()); SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); string strsql = "select * from LH_product join LH_category on LH_product.category = LH_category.id where LH_product.id =@productID"; con.Open(); SqlCommand cmd = new SqlCommand(strsql, con); cmd.Parameters.AddWithValue("@productID", productID); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { title_label.InnerText = dr["title"].ToString(); titleTxt.InnerText = dr["title"].ToString(); categoryLink.HRef = "products.aspx?id=" + dr["id"].ToString(); categoryLink.InnerText = dr["category_name"].ToString(); wishList.Attributes["onclick"] = "javascript: fnAddWishIcon(" + productID + ");"; price.InnerText = dr["price"].ToString(); strsql = "select * from LH_product_image where product_id =@productID"; con1.Open(); cmd = new SqlCommand(strsql, con1); cmd.Parameters.AddWithValue("@productID", productID); SqlDataReader dr1 = cmd.ExecuteReader(); bool firstImageFlag = true; while (dr1.Read()) { HtmlGenericControl li = new HtmlGenericControl("li"); if (firstImageFlag) { li.Attributes["class"] = "active"; firstImageFlag = false; firstImage.Src = dr1["image"].ToString(); } HtmlGenericControl img = new HtmlGenericControl("img"); img.Attributes["src"] = dr1["image"].ToString(); li.Controls.Add(img); productImage.Controls.Add(li); } } SqlConnection conn = new SqlConnection(Login.GetConnectionString()); string strsql1 = "select * from LH_Programs join LH_Rates on LH_Programs.program = LH_Rates.Program_ID join LH_programs_list on LH_Programs.program = LH_programs_list.ID where LH_Rates.Approved = 1 and LH_Programs.User_Id = @userID"; conn.Open(); SqlCommand cmd1 = new SqlCommand(strsql1, conn); cmd1.Parameters.AddWithValue("@userID", hdfuserid.Value); SqlDataReader dr2 = cmd1.ExecuteReader(); int i = 0; while (dr2.Read()) { i++; Createprogram(int.Parse(dr2[1].ToString()), dr2[10].ToString(), dr2["logo"].ToString(), dr2["name"].ToString(), dr2["points"].ToString(), dr2["program"].ToString(), i); // wishlistbar(dr2[16].ToString()); } conn.Close(); } } else { Response.Redirect("logout.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["login"] != null) { string username = null; if (Session["id"] != null) { int.TryParse(clsRidjindalEncryption.Decrypt(Session["id"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256), out userID); } if (Session["userName"] != null) { username = clsRidjindalEncryption.Decrypt(Session["userName"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string email = null; if (Session["email"] != null) { email = clsRidjindalEncryption.Decrypt(Session["email"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } string pwd = null; if (Session["pwd"] != null) { pwd = clsRidjindalEncryption.Decrypt(Session["pwd"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256); } if (Login.checkLogin(username, email, pwd, clsRidjindalEncryption.Decrypt(Session["login"].ToString(), "P@ssword", "123", "SHA1", 2, "%1234567890@#$%^", 256) == "1") == null || userID == -1) { Response.Redirect("Login.aspx"); } int id = Convert.ToInt32(userID.ToString()); GetCount(id); wishListTxt.InnerText = Session["Count"].ToString(); GetCartCount(id); cartTxt.InnerText = Session["CartCount"].ToString(); usernametxt.InnerText = username; //wishListTxt.InnerText = Login.countWishList(userID).ToString(); //cartTxt.InnerText = Login.countCart(userID).ToString(); lhptxt.InnerText = (Login.UserLHP(userID) + Login.getProgramsCount(userID)).ToString(); if (!IsPostBack) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "select * from LH_programs_list where id not in(select program from LH_Programs where user_Id = @userID)"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@userID", userID); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { createProgram(int.Parse(dr["id"].ToString()), dr["logo"].ToString()); } programList.Controls.Add(new HtmlGenericControl("li")); con.Close(); query = "select * from LH_category"; con.Open(); cmd = new SqlCommand(query, con); dr = cmd.ExecuteReader(); while (dr.Read()) { ListItem option = new ListItem(dr["category_name"].ToString(), dr["id"].ToString()); programCategory.Items.Add(option); } } SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); string query1 = "select * from LH_Programs join LH_Programs_List on LH_Programs.program = LH_programs_list.id where user_Id = @userID"; con1.Open(); SqlCommand cmd1 = new SqlCommand(query1, con1); cmd1.Parameters.AddWithValue("@userID", userID); SqlDataReader dr1 = cmd1.ExecuteReader(); while (dr1.Read()) { createRegisteredProgram(int.Parse(dr1["id"].ToString()), dr1["logo"].ToString()); } registered.Controls.Add(new HtmlGenericControl("li")); con1.Close(); } else { Response.Redirect("Logout.aspx"); } }
public static bool AddProceed(int userid, string[] arrSubProducts, string[] arrSubPoints, int quantity) { bool result = false; try { string Sql = ""; for (int i = 0; i < arrSubPoints.Length; i++) { int calPoints = 0; int points = 0; string Sqlex = ""; Sqlex = "select Points from lh_programs where User_Id=" + userid + " and program=" + arrSubProducts[i]; try { SqlConnection con = new SqlConnection(Login.GetConnectionString()); con.Open(); SqlCommand cmd = new SqlCommand(Sqlex, con); cmd.CommandType = CommandType.Text; points = (Int32)cmd.ExecuteScalar(); con.Close(); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; result = false; throw new Exception(msg); } if (arrSubProducts[i].Length > 0 && arrSubPoints[i].Length > 0) { if (points == -1) { points = 0; } if (String.IsNullOrEmpty(arrSubPoints[i])) { arrSubPoints[i] = "0"; } int npointa = points; int npointb = Convert.ToInt32(arrSubPoints[i]); calPoints = npointa - npointb; if (i == 0) { Sql = " update LH_Programs set Points=" + calPoints + ", Update_Date=getDate() where User_Id=" + userid + " AND program=" + arrSubProducts[i] + "; "; Sql += " insert into LH_Order(Product_ID,UseID,Quantity,Shipment_status,CreateDate,Updatedate) values(" + arrSubProducts[i] + ", " + userid + "," + quantity + ",0,getdate(),getdate())"; } else { Sql += " update LH_Programs set Points=" + calPoints + ", Update_Date=getDate() where User_Id=" + userid + " AND program=" + arrSubProducts[i] + "; "; Sql += " insert into LH_Order(Product_ID,UseID,Quantity,Shipment_status,CreateDate,Updatedate) values(" + arrSubProducts[i] + ", " + userid + "," + quantity + ",0,getdate(),getdate())"; } } } if (userid.ToString().Length > 0) { SqlConnection con = new SqlConnection(Login.GetConnectionString()); con.Open(); SqlCommand cmd = new SqlCommand(Sql, con); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); con.Close(); result = true; } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; result = false; throw new Exception(msg); } return(result); }
protected void Button1_Click(object sender, EventArgs e) { if (txtUname.Text == "" || txtEmail.Value == "" || txtFname.Value == "" || txtLname.Value == "" || txtMobile.Text == "" || txtPswd.Text == "" || txtremail.Value == "" || txtrePswd.Text == "") { return; } SqlConnection con1 = new SqlConnection(Login.GetConnectionString()); SqlCommand cmd1 = new SqlCommand("select UserName from LH_User where UserName = @name", con1); con1.Open(); cmd1.Parameters.AddWithValue("@name", txtUname.Text); SqlDataReader reader = cmd1.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); con1.Close(); int numRows = dt.Rows.Count; if (numRows > 0) { lbluname.Visible = true; lbluname.Text = "username exist"; return; } SqlConnection con2 = new SqlConnection(Login.GetConnectionString()); SqlCommand cmd2 = new SqlCommand("select Email from LH_User where Email = '" + txtEmail.Value + "'", con2); con2.Open(); SqlDataReader reader1 = cmd2.ExecuteReader(); DataTable dt1 = new DataTable(); dt1.Load(reader1); con2.Close(); int numRows1 = dt1.Rows.Count; if (numRows1 > 0) { lblemail.Visible = true; lblemail.Text = "Email already exist"; return; } SqlConnection con3 = new SqlConnection(Login.GetConnectionString()); SqlCommand cmd3 = new SqlCommand("select Mobile from LH_User where Mobile = '" + txtMobile.Text + "'", con3); con3.Open(); SqlDataReader reader2 = cmd3.ExecuteReader(); DataTable dt2 = new DataTable(); dt2.Load(reader2); con3.Close(); int numRows2 = dt2.Rows.Count; if (numRows2 > 0) { lblmobile.Visible = true; lblmobile.Text = "Mobile number already exist"; return; } InsertInfo(); Console.WriteLine("Registered Successfully"); txtUname.Text = ""; txtremail.Value = ""; txtMobile.Text = ""; txtLname.Value = ""; txtFname.Value = ""; txtEmail.Value = ""; login.Visible = false; activation.Visible = true; }
private static bool saveCheckout(int userid, string[][] products) { try { //save checkout SqlConnection con = new SqlConnection(Login.GetConnectionString()); string query = "insert into LH_Order([UseID],[Shipment_status],[CreateDate],[Updatedate]) OUTPUT INSERTED.ID values(@userID,0,getDate(),getDate())"; con.Open(); SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@userID", userid); int orderID = (int)cmd.ExecuteScalar(); con.Close(); for (int j = 0; j < products.Length; j++) { query = "INSERT INTO [LH_order_details]([OrderId],[ProductId],[Quantity],[CreateDate],[UpdateDate]) OUTPUT INSERTED.ID VALUES(@OrderId,@ProductId,@Quantity,getDate(),getDate())"; con.Open(); cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@orderId", orderID); cmd.Parameters.AddWithValue("@ProductId", products[j][0]); cmd.Parameters.AddWithValue("@Quantity", products[j][1]); cmd.ExecuteReader(); con.Close(); } for (int i = 0; i < products.Length; i++) { query = "delete from LH_cart where user_ID = @userID and product_ID = @productID"; con.Open(); cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@userID", userid); cmd.Parameters.AddWithValue("@ProductID", products[i][0]); cmd.ExecuteReader(); con.Close(); } int totalEarned = 0; for (int i = 0; i < products.Length; i++) { query = "select * from LH_Product where ID = @productID"; con.Open(); cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@ProductID", products[i][0]); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { int earned = int.Parse(dr["earnedLP"].ToString()); totalEarned += earned; } con.Close(); } query = "update LH_User set LHP = LHP+@earned where id=@id"; con.Open(); cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@earned", totalEarned); cmd.Parameters.AddWithValue("@id", userid); cmd.ExecuteReader(); con.Close(); return(true); } catch (Exception e) { return(false); } }