Exemplo n.º 1
0
    protected void btn_submitinfo_ServerClick(object sender, EventArgs e)
    {
        #region  务器端验证



        #endregion

        #region 信息保存

        Transaction t   = new Transaction();
        int         uid = CurrentUserId;
        if (uid > 0)
        {
            XiHuan_UserInfoEntity updateRegInfo = XiHuan_UserInfoEntityAction.RetrieveAXiHuan_UserInfoEntity(uid);
            if (updateRegInfo != null)
            {
                string savepath = string.Empty;
                string filepath = string.Empty;
                string filename = string.Empty;
                if (headImage.HasFile)
                {
                    if (headImage.PostedFile.ContentLength < 50 * 1024)
                    {
                        string hz = System.IO.Path.GetExtension(headImage.PostedFile.FileName);

                        if (CommonMethod.IsUploadImageValid("", hz))
                        {
                            filepath = "images/userupload/headimage/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/";
                            filename = DateTime.Now.ToString("yyyymmddhhmmssfff") + "_" + uid + hz;
                            if (!Directory.Exists(Server.MapPath(filepath)))
                            {
                                Directory.CreateDirectory(Server.MapPath(filepath));
                            }
                            savepath = Server.MapPath(filepath + filename);
                            headImage.PostedFile.SaveAs(savepath);
                        }
                        else
                        {
                            Alert("头像格式不符合要求,请重新选择头像!");
                            return;
                        }
                    }
                    else
                    {
                        Alert("头像大小超出50k,请换个小点的图片吧!");
                        return;
                    }
                }

                if (savepath.Length > 0)
                {
                    if (updateRegInfo.HeadImage.Length > 0 && System.IO.File.Exists(Server.MapPath(updateRegInfo.HeadImage)))
                    {
                        if (!updateRegInfo.HeadImage.Equals("images/nophoto.gif"))
                        {
                            System.IO.File.Delete(Server.MapPath(updateRegInfo.HeadImage));
                        }
                    }
                    updateRegInfo.HeadImage = filepath + filename;
                }
                updateRegInfo.Email        = txtEmail.Text.Trim();
                updateRegInfo.Gender       = byte.Parse(rbtSex.SelectedValue.Trim());
                updateRegInfo.ProvinceId   = CommonMethod.ConvertToInt(ddlProvince.SelectedValue, 0);
                updateRegInfo.ProvinceName = ddlProvince.SelectedItem.Text.Trim();
                updateRegInfo.CityId       = CommonMethod.ConvertToInt(Request["ddlCity"], 0);
                updateRegInfo.CityName     = CommonMethodFacade.GetCityNameById(updateRegInfo.CityId.ToString());
                updateRegInfo.AreaId       = CommonMethod.ConvertToInt(Request["ddlArea"], 0);
                if (updateRegInfo.AreaId > 0)
                {
                    updateRegInfo.AreaName = CommonMethodFacade.GetAreaNameById(updateRegInfo.AreaId.ToString());
                }
                int schoolid = CommonMethod.ConvertToInt(Request["ddlSchool"], 0);
                updateRegInfo.SchoolId = schoolid;
                if (schoolid > 0)
                {
                    updateRegInfo.SchoolName = CommonMethodFacade.GetSchoolNameById(ddlProvince.SelectedValue, Request["ddlCity"], schoolid.ToString());
                }
                else
                {
                    updateRegInfo.SchoolName = "";
                }

                updateRegInfo.Question  = txtQuestion.Text.Trim();
                updateRegInfo.Answer    = txtAnswer.Text.Trim();
                updateRegInfo.TelePhone = txtTel.Value.Trim();
                updateRegInfo.WangWang  = txtWangWang.Value.Trim();
                updateRegInfo.QQ        = txt_qq.Value.Trim();
                updateRegInfo.Msn       = txt_msn.Value.Trim();
                updateRegInfo.OtherLink = txtOtherLink.Text.Trim();
                updateRegInfo.SignNote  = CommonMethod.ClearInputText(txtSingnNote.Text, 200);
                t.DoSaveObject(updateRegInfo);
                //更新换品浏览人信息里的头像地址
                t.DoSqlNonQueryString("update XiHuan_GoodsViewUser set VisitorHeadImage='" + updateRegInfo.HeadImage + "' where VisitorId=" + CurrentUserId, GlobalVar.DataBase_Name);
                try
                {
                    t.Commit();
                    headPic.ImageUrl = filepath + filename;
                    LoadUserInfo();
                    Alert("恭喜:您的注册信息已成功更改!");
                    DataTable dt = Query.ProcessSql("select Id,DetailUrl from XiHuan_UserGoods with(nolock) where OwnerId= " + CurrentUserId + " and IsChecked=1 ", GlobalVar.DataBase_Name);
                    foreach (DataRow dr in dt.Rows)
                    {
                        CommonMethod.readAspxAndWriteHtmlSoruce("showdetail.aspx?id=" + dr["Id"], dr["DetailUrl"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    Alert("抱歉:修改信息时出错," + ex.Message + "请稍后重试!");
                    return;
                }
            }
        }
        else
        {
            Alert("登陆超时,请重新登陆再继续当前的操作!");
            return;
        }

        #endregion
    }
Exemplo n.º 2
0
    protected void lnkSubmit_Click(object sender, EventArgs e)
    {
        #region  务器端验证

        int provinceid = CommonMethod.ConvertToInt(ddlProvince.SelectedValue, 0);
        int cityid     = CommonMethod.ConvertToInt(ddlCity.SelectedValue, 0);
        int areaid     = CommonMethod.ConvertToInt(ddlArea.SelectedValue, 0);
        int schoolid   = CommonMethod.ConvertToInt(ddlSchool.SelectedValue, 0);
        if (txtUserName.Text.Trim().Length == 0)
        {
            Alert(" 请您填写换客名!");
            Select(txtUserName);
            return;
        }

        else if (XiHuan_UserFacade.IsUserNameAlreayUse(txtUserName.Text))
        {
            Alert("您填写的换客名已经被占用,请您换个换客名重试!");
            Select(txtUserName);
            return;
        }

        if (txtPassWord.Text.Trim().Length == 0)
        {
            Alert("请您填写密码!");
            Select(txtPassWord);
            return;
        }

        if (txtPassWord2.Text.Trim().Length == 0)
        {
            Alert("请您再次输入密码!");
            Select(txtPassWord2);
            return;
        }

        if (!txtPassWord.Text.Trim().Equals(txtPassWord2.Text.Trim()))
        {
            Alert("两次密码输入不一致,请重新输入!");
            Select(txtPassWord2);
            return;
        }

        if (txtEmail.Text.Trim().Length > 0)
        {
            Regex reg = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
            if (!reg.IsMatch(txtEmail.Text.Trim()))
            {
                Alert("您的邮箱格式填写不正确!");
                Select(txtEmail);
                return;
            }
        }

        if (provinceid == 0)
        {
            Alert("请您选择省份!");
            return;
        }

        if (cityid == 0)
        {
            Alert("请您选择城市!");
            return;
        }

        if (txtQuestion.Text.Trim().Length == 0)
        {
            Alert("请您填写安全提问问题!");
            Select(txtQuestion);
            return;
        }

        if (txtAnswer.Text.Trim().Length == 0)
        {
            Alert("请您填写安全提问答案!");
            Select(txtAnswer);
            return;
        }

        #endregion

        #region 用户基本信息

        Transaction           t       = new Transaction();
        XiHuan_UserInfoEntity NewUser = new XiHuan_UserInfoEntity();
        NewUser.UserType     = (int)XiHuan_UserFacade.UserType.个人注册;
        NewUser.UserName     = txtUserName.Text.Trim();
        NewUser.OrignalPwd   = txtPassWord.Text.Trim();
        NewUser.Md5Pwd       = CommonMethod.MD5Encrypt(txtPassWord.Text.Trim());
        NewUser.Email        = txtEmail.Text.Trim();
        NewUser.Gender       = Rad_sex_0.Checked ? (byte)1 : (byte)0;
        NewUser.ProvinceId   = provinceid;
        NewUser.ProvinceName = ddlProvince.SelectedItem.Text;
        NewUser.CityId       = cityid;
        if (cityid > 0)
        {
            NewUser.CityName = CommonMethodFacade.GetCityNameById(cityid.ToString());
        }
        NewUser.AreaId = areaid;
        if (areaid > 0)
        {
            NewUser.AreaName = CommonMethodFacade.GetAreaNameById(areaid.ToString());
        }
        if (schoolid > 0)
        {
            NewUser.SchoolId   = schoolid;
            NewUser.SchoolName = CommonMethodFacade.GetSchoolNameById(provinceid.ToString(), cityid.ToString(), schoolid.ToString());
        }

        NewUser.HuanBi       = SystemConfigFacade.Instance().RegisterAddHuanBi();
        NewUser.Score        = SystemConfigFacade.Instance().RegisterAddScore();
        NewUser.RegisterDate = NewUser.LastLoginTime = DateTime.Now;
        NewUser.Question     = txtQuestion.Text.Trim();
        NewUser.Answer       = txtAnswer.Text.Trim();
        NewUser.HeadImage    = "images/nophoto.gif";
        t.DoSaveObject(NewUser);

        #endregion

        #region 推荐人积分换币更新
        if (txtTuiJianMember.Text.Trim().Length > 0)
        {
            string updateTJ = string.Format("update XiHuan_UserInfo set Score=Score+{0},HuanBi=HuanBi+{1} where UserName='******' ",
                                            SystemConfigFacade.Instance().TuiJianAddScore(), SystemConfigFacade.Instance().TuiJianAddHuanBi(), txtTuiJianMember.Text.Trim());

            t.DoSqlNonQueryString(updateTJ, GlobalVar.DataBase_Name);
        }
        #endregion

        #region 给新注册用户发送短消息

        XiHuan_MessageFacade.SendNewMessage(1, NewUser.ID, "喜换网", NewUser.UserName, "尊敬的会员" + NewUser.UserName + "," + SystemConfigFacade.Instance().RegMesContent(), t, true);

        #endregion

        try
        {
            t.Commit();

            #region 注册完成后自动登陆调转到个人管理中心

            Alert("恭喜:您的注册信息已成功提交!");
            CommonMethod.AddLoginCookie(NewUser.ID, NewUser.UserName, DateTime.MinValue);
            SendMailFacade.sendEmail(CommonMethodFacade.GetConfigValue("NoticeEmail"), "有人在喜换网注册了", "有人在喜换网注册了:" + txtUserName.Text);
            Response.Redirect("membercenter.aspx?action=" + Server.UrlEncode("membermanageindex.aspx"));

            #endregion
        }
        catch (Exception ex)
        {
            t.RollBack();
            Alert("抱歉:注册信息提交失败," + ex.Message + "请重试!");
            return;
        }
    }