using System;
using System.Collections.Generic;
namespace Stat.web
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Register : System.Web.UI.Page
    {
        Stat.Cache.IConfig config = Stat.Cache.CacheFatory.CreateConfig();
        Security.ISecurity security = Security.DataFatory.CreateSecurity();
        Model.Users model = new Stat.Model.Users();
        string txtCheckCode = "";

        /// <summary>
        /// 
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {


            if (Plugin.Common.Rq("ac").ToLower() == "add")
            {
                model.UserName = Plugin.Common.Rq("txtUname");
                model.UserPwd = Plugin.Common.Rq("txtUserPWD1");
                model.UserEmail = Plugin.Common.Rq("txtUEmail");
                model.UserQQ = Plugin.Common.Rq_Int("txtUQQ").ToString();
                model.IsPwdMD5 = config.IsUserPwdMd5();
                txtCheckCode = Plugin.Common.Rq("txtCheckCode");
                SaveUser();
            }

            if (!IsPostBack)
            {
                GetTop1();
            }

            this.ltrCopyRight.Text = config.WebCopy();

        }
        /// <summary>
        /// 
        /// </summary>
        protected void GetTop1()
        {
            IList<Stat.Model.Notify> list = Stat.BLL.Notify.GetTop1(1, 1);
            if (list.Count > 0)
            {
                this.LtrTitle.Text = "<a href=\"/Notice.aspx?id=" + list[0].ID + "\" target=\"_blank\">" + list[0].title + " (查看详细)</a>";
                this.LtrContent.Text = Plugin.Common.Cut(Plugin.Common.DealHtml(list[0].content), 401);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private void SaveUser()
        {
            //检查是否开启
            if (!config.IsAllowRegister())
            {
                Plugin.Common.Alert("系统暂时停止新用户注册！");
                return;
            }



            //检查填写的表单
            if (!security.CheckCode("CheckCode", txtCheckCode))
            {
                return;
            }
            /*--------------------------------------------*/
            if (Plugin.Common.IsNumeric(model.UserName)) { Plugin.Common.Alert("用户名不能全是数字组成！"); return; }
            if (model.UserName.Length == 0) { return; }
            if (model.UserPwd.Length == 0) { return; }
            /*--------------------------------------------*/
            if (Stat.BLL.Users.Add(model))
            {
                Plugin.Common.Alert("注册成功！", "Default.aspx");
            }
            else
            {
                Plugin.Common.Alert("操作失败！");
            }
        }

    }
}

