Exemple #1
0
        protected void ImageButtonActionsFriend_Click(object sender, ImageClickEventArgs e)
        {
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ProfilesConnectionString"].ConnectionString);
            sqlConn.Open();
            SqlDataAdapter sda = new SqlDataAdapter("sp_friendExists", sqlConn);
            sda.SelectCommand.CommandType = CommandType.StoredProcedure;
            sda.SelectCommand.Parameters.Add("@ProfileId", SqlDbType.Int).Value = Convert.ToInt32(Page.RouteData.Values["Id"]);
            sda.SelectCommand.Parameters.Add("@UserId", SqlDbType.Int).Value = Convert.ToInt32(Page.RouteData.Values["Id"]);
            sda.Fill(ds);
            dt = ds.Tables[0];

            if (dt.Rows.Count == 0)
            {
                DataTable dtRequest1 = new DataTable();
                DataTable dtRequest2 = new DataTable();
                DataSet dsRequest = new DataSet();
                SqlDataAdapter sdaRequest = new SqlDataAdapter("sp_friendRequestExists", sqlConn);
                sdaRequest.SelectCommand.CommandType = CommandType.StoredProcedure;
                sdaRequest.SelectCommand.Parameters.Add("@ProfileId", SqlDbType.Int).Value = Convert.ToInt32(Page.RouteData.Values["Id"]);
                sdaRequest.SelectCommand.Parameters.Add("@UserId", SqlDbType.Int).Value = Convert.ToInt32(Session["UserId"]);
                sdaRequest.Fill(dsRequest);
                dtRequest1 = dsRequest.Tables[0];
                dtRequest2 = dsRequest.Tables[0];

                if (dtRequest1.Rows.Count == 0) // add request
                {
                    if (dtRequest2.Rows.Count == 0) // add request
                    {
                        SqlCommand sqlCmd = new SqlCommand("sp_friendRequestAdd", sqlConn);
                        sqlCmd.CommandType = CommandType.StoredProcedure;
                        sqlCmd.Parameters.Add("@ProfileId", SqlDbType.Int).Value = Convert.ToInt32(Page.RouteData.Values["Id"]);
                        sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = Convert.ToInt32(Session["UserId"]);

                        sqlCmd.ExecuteNonQuery();
                        sqlCmd.Dispose();

                        PanelActionsShowMessage.Visible = true;
                        HyperLinkActionsMessage.Text = "درخواست اضافه شدن به دوستان شما برای پروفایل ارسال گردید.";
                    }
                    else // do nothing
                    {
                        PanelActionsShowMessage.Visible = true;
                        HyperLinkActionsMessage.Text = "درخواست اضافه شدن به دوستان شما برای پروفایل ارسال گردید.";
                    }
                }
                else // accept request
                {
                    SqlCommand sqlCmd = new SqlCommand("sp_friendRequestAccept", sqlConn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.Add("@SenderId", SqlDbType.Int).Value = Convert.ToInt32(dtRequest1.Rows[0]["SenderId"].ToString());
                    sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = Convert.ToInt32(Session["UserId"]);
                    sqlCmd.ExecuteNonQuery();

                    Classes.ProfileInformation pi = new Classes.ProfileInformation();
                    string FriendName = pi.getInformation(Convert.ToInt32(dtRequest1.Rows[0]["SenderId"].ToString()), "FullName");

                    Classes.Notifications no = new Classes.Notifications();
                    no.addNotification(Convert.ToInt32(dtRequest1.Rows[0]["SenderId"].ToString()), 2, FriendName, "ProfileId");

                    PanelActionsShowMessage.Visible = true;
                    HyperLinkActionsMessage.Text = "با تایید درخواست پروفایل به فهرست دوستان شما اضافه گردید.";
                }
            }
            else
            {
                SqlCommand sqlCmd = new SqlCommand("sp_friendDelete", sqlConn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@ProfileId", SqlDbType.Int).Value = Convert.ToInt32(Page.RouteData.Values["Id"]);
                sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = Convert.ToInt32(Session["UserId"]);

                sqlCmd.ExecuteNonQuery();
                sqlCmd.Dispose();

                ImageButtonActionsFriend.ImageUrl = "~/Images/Buttons/friendadd-off.png";
                //Mouseover
                ImageButtonActionsFriend.Attributes.Add("onmouseover", "this.src='" + HostUrl + "/Images/Buttons/friendadd-on.png'");
                ImageButtonActionsFriend.Attributes.Add("onmouseout", "this.src='" + HostUrl + "/Images/Buttons/friendadd-off.png'");
                PanelActionsShowMessage.Visible = true;
                HyperLinkActionsMessage.Text = "پروفایل از فهرست دوستان شما حذف گردید.";
            }
        }
Exemple #2
0
        protected void ImageButtonRegister_Click(object sender, ImageClickEventArgs e)
        {
            if (TextBoxEmail.Text.Length == 0)
            {
                LabelError.Visible = true;
                LabelError.Text = "پست الکترونیکی را وارد نمایید!";
            }
            else
            {
                string mail = TextBoxEmail.Text;
                string expression = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + @"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]" + @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";

                Match match = Regex.Match(mail, expression, RegexOptions.IgnoreCase);
                if (!match.Success)
                {
                    LabelError.Visible = true;
                    LabelError.Text = "پست الکترونیکی صحیح نمی باشد!";
                }
                else
                {
                    DataTable dt = new DataTable();
                    DataSet ds = new DataSet();
                    SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ProfilesConnectionString"].ConnectionString);
                    SqlDataAdapter sda = new SqlDataAdapter("sp_registerCheckEmail", sqlConn);
                    SqlCommand sqlCmd = new SqlCommand("sp_register", sqlConn);
                    SqlDataAdapter sda2 = new SqlDataAdapter("sp_userIdByEmail", sqlConn);

                    try
                    {
                        sda.SelectCommand.CommandType = CommandType.StoredProcedure;
                        sda.SelectCommand.Parameters.Add(new SqlParameter("@Email", SqlDbType.VarChar));
                        sda.SelectCommand.Parameters["@Email"].Value = TextBoxEmail.Text;
                        sda.Fill(ds);
                        dt = ds.Tables[0];

                        if (dt.Rows.Count > 0) //email registered before
                        {
                            LabelError.Visible = true;
                            LabelError.Text = "پست الکترونیکی وارد شده در سیستم وجود دارد!";
                            sqlConn.Close();
                            sqlConn.Dispose();
                            sda.Dispose();
                        }
                        else
                        {
                            if (TextBoxMobile.Text.Length == 0)
                            {
                                LabelError.Visible = true;
                                LabelError.Text = "تلفن همراه را وارد نمایید!";
                            }
                            else
                            {
                                if (TextBoxMobile.Text.Length < 10)
                                {
                                    LabelError.Visible = true;
                                    LabelError.Text = "تلفن همراه صحیح نمی باشد!";
                                }
                                else
                                {
                                    if (TextBoxPassword1.Text.Length == 0)
                                    {
                                        LabelError.Visible = true;
                                        LabelError.Text = "کلمه عبور را وارد نمایید!";
                                    }
                                    else
                                    {
                                        if (TextBoxPassword1.Text.Length < 4)
                                        {
                                            LabelError.Visible = true;
                                            LabelError.Text = "کلمه عبور حداقل می بایست 4 کاراکتر باشد!";
                                        }
                                        else
                                        {
                                            if (TextBoxPassword1.Text != TextBoxPassword2.Text)
                                            {
                                                LabelError.Visible = true;
                                                LabelError.Text = "کلمه عبور و تکرار کلمه عبور می بایست یکسان باشند!";
                                            }
                                            else
                                            {
                                                MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
                                                byte[] hashedBytes;
                                                UTF8Encoding encoder = new UTF8Encoding();
                                                hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBoxPassword1.Text));

                                                sqlCmd.CommandType = CommandType.StoredProcedure;
                                                sqlCmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = TextBoxEmail.Text;
                                                sqlCmd.Parameters.Add("@Mobile", SqlDbType.NVarChar).Value = TextBoxMobile.Text;
                                                sqlCmd.Parameters.Add("@Password", SqlDbType.Binary, 16).Value = hashedBytes;

                                                sqlConn.Open();
                                                sqlCmd.ExecuteNonQuery();

                                                DataTable dt2 = new DataTable();
                                                DataSet ds2 = new DataSet();

                                                sda2.SelectCommand.CommandType = CommandType.StoredProcedure;
                                                sda2.SelectCommand.Parameters.Add(new SqlParameter("@Email", SqlDbType.VarChar));
                                                sda2.SelectCommand.Parameters["@Email"].Value = TextBoxEmail.Text;
                                                sda2.Fill(ds2);
                                                dt2 = ds2.Tables[0];

                                                Session["UserId"] = Convert.ToInt32(dt2.Rows[0]["UserId"].ToString());

                                                Classes.Notifications no = new Classes.Notifications();
                                                no.addNotification(Convert.ToInt32(dt2.Rows[0]["UserId"].ToString()), 1, "", "");

                                                sqlConn.Close();
                                                sqlConn.Dispose();


                                                int Hours = 4;
                                                string VerificationCode = Convert.ToString(Guid.NewGuid());

                                                Classes.LoginSession ls = new Classes.LoginSession();
                                                ls.setLoginSession(Convert.ToInt32(dt2.Rows[0]["UserId"].ToString()), VerificationCode, Hours);

                                                HttpCookie _userInfoCookies = new HttpCookie("VC");
                                                _userInfoCookies["VC"] = VerificationCode;
                                                _userInfoCookies.Expires = DateTime.Now.AddHours(Hours);
                                                Response.Cookies.Add(_userInfoCookies);

                                                Response.Redirect("~/Instruction");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                    finally
                    {
                        sqlConn.Close();
                        sda.Dispose();
                        sda2.Dispose();
                        sqlCmd.Dispose();
                        sqlConn.Dispose();
                    }
                }
            }
            
        }