using System;
using System.Collections;
using System.Collections.Generic;

namespace Stat.web
{

    /// <summary>
    /// 
    /// </summary>
    public partial class Message1 : System.Web.UI.Page
    {
        Model.Message messageModel = new Stat.Model.Message();
        Model.PageInfo pageModel = new Stat.Model.PageInfo(5);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

            string ac = Plugin.Common.Rq("ac");

            if (ac.ToLower() == "add")
            {
                AddMsg();
            }
            else
            {
                pageModel.PageIndex = Plugin.Common.Rq_Int("page");
                pageModel.PageIndex = pageModel.PageIndex < 1 ? 1 : pageModel.PageIndex;
                messageModel.IsPass = 1;
                GetList();
            }
        }

        private void AddMsg()
        {
            //Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
            //if (!security.CheckCode("CheckCode", Plugin.Common.Rq("CheckCode"))) { return; }
            Model.Message model = new Stat.Model.Message();
            model.title = Plugin.Common.Rq("title");
            model.Author = Plugin.Common.Rq("uName");
            model.content = Plugin.Common.Rq("Content");
            

            if (BLL.Message.Insert(model))
            {
                Plugin.Common.Alert("提交成功！等待管理员处理。", "?");
            }
            else
            {
                Plugin.Common.Alert("提交失败！");
            }
        }
        private void GetList()
        {
            IList<Model.Message> list = BLL.Message.Get(messageModel, ref pageModel);
            this.ltrList.Text = Html.Message.Get(list, pageModel);
            this.LtrIndex.Text = JPageIndex.GetIndex.Get(pageModel.RecordCount, pageModel.PageIndex, pageModel.PageSize, "", 1, 0, 1, 7);
        }
    }
}
