using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Mall.Member
{
    public partial class Reg_Mobile : System.Web.UI.Page
    {
        public MODEL.MOrder model_order = new MODEL.MOrder();
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Redirect("/member/reg_mobileok.aspx");
            
            BLL.Models.MemberModels models_member = new BLL.Models.MemberModels();
            string username = models_member.CheckUserId();// CheckUserId();

            

            DataTable dt = new DataTable();
            dt = models_member.GetuserInfoByFiter(" username='" + username + "'");
            DataRow dr = dt.Rows[0];
            model_order.RecAddress = dr["address"].ToString();
            model_order.RecMobile = dr["mobile"].ToString();
            model_order.RecName = dr["name"].ToString();
            model_order.RecZip = dr["zipcode"].ToString();
            //TempData["regmobilemodel_order"] = model_order;

            Random rad = new Random();
            string r_code = rad.Next(1000, 9999).ToString();
            string sms_code = string.Empty;
            MODEL.MMember model_menber = new MODEL.MMember();
            string sep = Request["sep"] == null ? string.Empty : Request["sep"].ToString();
            string mobile = Request["mobile"] == null ? string.Empty : Request["mobile"].ToString();
            string num = Request["num"] == null ? string.Empty : Request["num"].ToString();
            if (!string.IsNullOrEmpty(num))
            {

                if (num == Session["sms_code"].ToString())
                {
                    Response.Redirect("/member/reg_mobileok.aspx");

                }
                else
                {

                    Response.Write("<script language='javascript'>");
                    Response.Write("alert('验证码错误,请确认。');");
                    Response.Write("</script>");
                    Response.Write("<meta http-equiv=refresh content='0;URL=/member/reg_mobile.aspx?sep=2&mobile=" + mobile + "'>");

                }
            }
            string str_script_int = string.Empty;
            StringBuilder str_script = new StringBuilder();
            if (sep == "2")
            {
                str_script.Append("document.getElementById('newCustomerdiv').style.display = 'none';");
                str_script.Append("document.getElementById('step1').style.display = 'None';");
                str_script.Append("document.getElementById('step2').style.display = 'block';");
                // str_script.Append("document.getElementById('hidValidate').value = result1;");
                str_script.Append("document.title = '手机认证，填写手机验证码 – 微维网';");
                model_menber.Mobile = mobile;


                str_script_int = str_script.ToString();
            }
           // TempData["str_script_int"] = str_script_int;

            if (Request["ctl00_MainPlace_txtCellphone1"] != null)
            {



                sms_code = rad.Next(100000, 999999).ToString();
                Session["sms_code"] = sms_code;
                model_menber.UserName = username;
                model_menber.Id = Convert.ToInt32(models_member.GetUserIdByName(username));
                model_menber.Mobile = Request["ctl00_MainPlace_txtCellphone1"];
                model_menber.ZipCode = Request["ctl00_MainPlace_txtPostCode1"];
                model_menber.Address = Request["ctl00_MainPlace_cmbProvince"] + Request["ctl00_MainPlace_cmbCity"] + Request["ctl00_MainPlace_txtAddress"];
                model_menber.Name = Request["ctl00_MainPlace_txtCustomerName"];
                models_member.UpdateSimgUser(model_menber);
                string smscontent = "您的短信验证码是：" + sms_code + ",微维网络科技技术支持。";
                smscontent = Server.UrlEncode(smscontent);
                string smspass = string.Empty;
                string smsrpass = string.Empty;
                string sitepass = string.Empty;
                string smsrpassn = string.Empty;
                models_member.GetSmsPassInfo(ref smspass, ref sitepass, ref smsrpass);
                models_member.SendMsg(smspass, smsrpass, sitepass, model_menber.Mobile, smscontent, ref smsrpassn);
                models_member.SetSmsPass(smsrpassn);

                Response.Redirect("reg_mobile.aspx?sep=2&mobile=13232323232");
                //return RedirectToAction("order_ship", "order");
            }
            //TempData["regmobile_mobile"] = model_menber.Mobile;
            //TempData["regmobile_r_code"] = r_code;
            //TempData["smscode"] = HttpContext.Session["sms_code"] == null ? string.Empty : HttpContext.Session["sms_code"].ToString();

        }
    }
}