using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using EKETEAM.Data;
using EKETEAM.UserControl;
using EKETEAM.FrameWork;

namespace eFrameWork.Customs
{
    public partial class Home : System.Web.UI.Page
    {
        public string UserArea = "Application";
        public eModel model;
        public eUser user;       
        public string AppId = "";
        public string AppItem = eParameters.Request("AppItem");
        public string ModelID = "";
        string sql = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            user = new eUser(eBase.getUserArea(UserArea));
            if (AppItem.Length > 0)
            {
                DataRow[] appRows = eBase.a_eke_sysApplicationItems.Select("ApplicationItemID='" + AppItem + "'");
                if (appRows.Length == 0) Response.End();

                AppId = appRows[0]["ApplicationID"].ToString();
                ModelID = appRows[0]["ModelID"].ToString();
                model = new eModel(AppItem, ModelID, user);

            }
            else
            {
                model = new eModel(ModelID, user);
            }

            StringBuilder sb = new StringBuilder();


            sb.Append("欢迎登录" + eConfig.systemName() + "!<br>");
            sb.Append("用户名：" + user["Name"] + "<br>");
            sb.Append("用户ID：" + user.ID + "<br>");
            sb.Append("SiteID：" + user["SiteID"] + "<br>");


            DataTable tb = eOleDB.getDataTable("select LoginCount,LastLoginTime from a_eke_sysUsers where UserID='" + user["ID"].ToString() + "'");
            if (tb.Rows.Count > 0)
            {
                string logincount = tb.Rows[0]["LoginCount"].ToString();
                string lastlt = string.Format("{0:yyyy-MM-dd HH:mm:ss}", tb.Rows[0]["LastLoginTime"]);

                sb.Append("登录次数：" + logincount + "<br>");
                sb.Append("上次登录时间：" + lastlt + "<br>");
            }
            sb.Append("默认密码非常不安全,点此<a href=\"ModifyPass.aspx?AppItem=" + AppItem + "\">修改密码</a>");
            litBody.Text = sb.ToString();
           
        }


        protected void Page_PreRender3(object sender, EventArgs e)
        {
            /*
            Literal lit = (Literal)Master.FindControl("LitTitle");
            if (lit != null)
            {
                lit.Text = model.ModelInfo["mc"].ToString() + " - " + eOleDB.getValue("select mc from a_eke_sysApplications where ApplicationID='" + AppId + "'");
            }
            */
        }
    }
}