using System;
using System.Collections;
using System.Diagnostics;
using Business.FileFlow.Vo;
using Business.System.Op.Vo;
using Business.System.User.Entity;
using LogisticsSystem.Control;
using LogisticsSystem.Control.Helper;

namespace LogisticsSystem.SysMain.Login
{
    public partial class Login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //检查是否通过正确途径登录
            if ((string) Session["islogin"] == "" || Session["islogin"] == null)
            {
                Response.Redirect(@"..\..\Default.aspx");
            }
        }

        //登录事件
        protected void btn_login_Click(object sender, EventArgs e)
        {
            var loginHelper = new LoginHelper();
            string result=  loginHelper.Login(tb_acc.Text, tb_pwd.Text);
            if (result.Equals(string.Empty))
            {
                //登录成功
                SetSession(loginHelper.User);
                LogHelper.Log("用户:" + loginHelper.User.Username + " 登陆成功");
                Response.Redirect(@"..\Main\MainFrm.aspx");
            }
            else
            {
                LogHelper.Log("账号:" + tb_acc.Text + " 登陆失败");
                //登录失败
                Alert(result);
            }
        }

        //登录成功后,将用户信息保存到session
        private void SetSession(UserEty user)
        {
            Session["Userid"] = user.Userid;
            Session["Username"] = user.Username;
            Session["Depid"] = user.Depid;
            Session["Mobile"] = user.Mobile;
            Session["Userroleid"] = user.Userroleid;
            Session["Addtime"] = user.Addtime;
            Session["Adduserid"] = user.Adduserid;

            //保存上传文件
            Session["upload"] = new Hashtable();

            //保存文件地址
            Session["SAddr"] = new Hashtable();

            //登录成功后获取用户权限
            Session["lmt"] = new LmtVo().GetLmt(user.Userid);
        }
    }
}