コード例 #1
0
        public CY.HotelBooking.Core.Business.User GetUserByName(string name)
        {
            SqlServerUtility db = new SqlServerUtility();

            db.AddParameter("@User_Name", SqlDbType.VarChar, name);

            SqlDataReader reader = db.ExecuteSqlReader(SqlSelectUserByName);

            if (reader != null && !reader.IsClosed && reader.Read())
            {
                CY.HotelBooking.Core.Business.User user = new CY.HotelBooking.Core.Business.User();

                user.Id = reader.GetInt32(0);
                if (!reader.IsDBNull(1)) user.Name = reader.GetString(1);
                if (!reader.IsDBNull(2)) user.Pass = reader.GetString(2);
                if (!reader.IsDBNull(3)) user.RealName = reader.GetString(3);
                if (!reader.IsDBNull(4)) user.TelNum = reader.GetString(4);
                if (!reader.IsDBNull(5)) user.Email = reader.GetString(5);
                if (!reader.IsDBNull(6)) user.Identify = reader.GetString(6);
                if (!reader.IsDBNull(7)) user.IdentifyNum = reader.GetString(7);
                if (!reader.IsDBNull(8)) user.Gender = reader.GetInt32(8);
                if (!reader.IsDBNull(9)) user.Birthdate = reader.GetDateTime(9);
                if (!reader.IsDBNull(10)) user.DateCreated = reader.GetDateTime(10);
                if (!reader.IsDBNull(11)) user.Address = reader.GetString(11);
                if (!reader.IsDBNull(12)) user.User_Activation = reader.GetString(12);
                if (!reader.IsDBNull(13)) user.User_Key = reader.GetString(13);
                reader.Close();
                return user;
            }
            else
            {
                if (reader != null &&!reader.IsClosed&& !reader.IsClosed)
                    reader.Close();

                return null;
            }
        }
コード例 #2
0
        /// <summary>
        /// 注册按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAgree_Click(object sender, EventArgs e)
        {
            CY.HotelBooking.Core.Business.User registerUser = new CY.HotelBooking.Core.Business.User();
            bool registerFlag = false;

            // 注册用户名
            registerUser.Name = name.Text;
            // 真实姓名
            registerUser.RealName = realName.Text;
            // 注册电话
            registerUser.TelNum = telephone.Text;
            // 通讯地址
            registerUser.Address = address.Text;
            // 生日
            registerUser.Birthdate = DateTime.Now.Date;
            // 注册日期
            registerUser.DateCreated = DateTime.Now.Date;
            // 注册邮箱
            registerUser.Email = email.Text;
            // 密码
            registerUser.Pass = CY.HotelBooking.Core.Business.PasswordEncrypt.DESEncryptMethod(pwd.Text);
            // 用户性别
            if (ddlsex.SelectedValue == "male")
            {
                registerUser.Gender = CY.HotelBooking.Core.Business.Gender.Male;
            }
            else
            {
                registerUser.Gender = CY.HotelBooking.Core.Business.Gender.Female;
            }

            // 注册证件信息
            switch (identifyType.SelectedItem.Value)
            {
                case "IdentifyID":
                    registerUser.Identify = CY.HotelBooking.Core.Business.Identify.ShenFenZheng;
                    break;
                case "StudentID":
                    registerUser.Identify = CY.HotelBooking.Core.Business.Identify.XueShengZheng;
                    break;
                case "DriveID":
                    registerUser.Identify = CY.HotelBooking.Core.Business.Identify.JiaShiZheng;
                    break;
                default:
                    registerUser.Identify = CY.HotelBooking.Core.Business.Identify.other;
                    break;
            }
            registerUser.IdentifyNum = identifyNbr.Text;
            registerUser.User_Activation = "否";
            registerUser.User_Key = System.Guid.NewGuid().ToString();

            registerFlag = CY.HotelBooking.Core.Business.User.UserRegister(registerUser);

            if (registerFlag)
            {
                MailMessage mail = new System.Net.Mail.MailMessage();
                mail.To.Add(registerUser.Email);

                XmlDocument xml = new XmlDocument();
                xml.Load(Server.MapPath("/") + "Web.config");
                string SmtpClient = System.Configuration.ConfigurationManager.AppSettings["SmtpClient"];
                string port = System.Configuration.ConfigurationManager.AppSettings["Port"];
                string addemail = System.Configuration.ConfigurationManager.AppSettings["Email"];
                string ps = System.Configuration.ConfigurationManager.AppSettings["password"];
                //读取web.config邮件配置

                mail.From = new MailAddress(addemail, "润澳花园大酒店", System.Text.Encoding.UTF8);
                mail.Subject = "润澳花园大酒店用户激活邮件";
                mail.SubjectEncoding = System.Text.Encoding.UTF8;

                CY.HotelBooking.Core.Business.Settings setting = CY.HotelBooking.Core.Business.Settings.Load(0);
                string body = setting.EmailBody;
                //读取自定义邮件内容
                string webaddress = System.Configuration.ConfigurationManager.AppSettings["address"] + "/UserActive.sapx?Key=" + registerUser.User_Key;
                //设置激活链接
                mail.Body = body + "    " + webaddress.Trim();
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                mail.IsBodyHtml = true;
                mail.Priority = MailPriority.High;

                SmtpClient client = new SmtpClient();
                //设置GMail邮箱和密码

                client.Credentials = new System.Net.NetworkCredential(addemail, ps);
                client.Port = int.Parse(port);
                client.Host = SmtpClient;
                client.EnableSsl = true;
                object userState = mail;
                try
                {
                    client.Send(mail);

                }
                catch (System.Net.Mail.SmtpException ex)
                {

                }

                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('注册用户成功,激活链接已发送至邮箱');window.location.href='../Default.aspx';</script>");

                // 获取注册用户信息,给该用户发送短消息
                CY.HotelBooking.Core.Business.User user = CY.HotelBooking.Core.Business.User.GetUserByName(registerUser.Name);
                CY.HotelBooking.Core.Business.Message msg = new CY.HotelBooking.Core.Business.Message();

                CY.HotelBooking.Core.Business.User.SendRegisterMsg(user, msg);
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('注册用户失败(用户已存或用户信息填写不完整)!');</script>");
            }
        }