using Apache.NMS.ActiveMQ.Commands;
using BLL;
using FineUIPro.Web.DataShow;
using FineUIPro.Web.SysManage;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using static System.Windows.Forms.AxHost;
namespace FineUIPro.Web
{
    public partial class WorkBench : PageBase
    {
        #region 定义变量
        /// 
        /// 当前登录人Id
        /// 
        public string UserId
        {
            get
            {
                return (string)ViewState["UserId"];
            }
            set
            {
                ViewState["UserId"] = value;
            }
        }
        #endregion
        #region Init
        /// 
        /// Init
        /// 
        /// 
        /// 
        protected void Page_Init(object sender, EventArgs e)
        {
            string themeStr = Request.QueryString["theme"];
            string menuStr = Request.QueryString["menu"];
            string https = ConfigurationManager.AppSettings["Https"];
            if (!String.IsNullOrEmpty(themeStr) || !String.IsNullOrEmpty(menuStr))
            {
                if (!String.IsNullOrEmpty(themeStr))
                {
                    HttpCookie cookie = new HttpCookie("Theme_Pro", "Cupertino")
                    {
                        Expires = DateTime.Now.AddYears(1)
                    };
                    Response.Cookies.Add(cookie);
                }
                if (!String.IsNullOrEmpty(menuStr))
                {
                    HttpCookie cookie = new HttpCookie("MenuStyle_Pro", menuStr)
                    {
                        Expires = DateTime.Now.AddYears(1)
                    };
                    if (https == "true")
                    {
                        cookie.Secure = true;
                    }
                    Response.Cookies.Add(cookie);
                }
                PageContext.Redirect("~/default.aspx");
                return;
            }
            ////////////////////////////////////////////////////////////////
            if (!IsPostBack)
            {
            }
        }
        #endregion
        #region 加载页面
        /// 
        /// 加载页面
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var user = BLL.UserService.GetUserByUserId(this.CurrUser.UserId);
                if (user != null)
                {
                    this.UserId = this.CurrUser.UserId;
                    this.lName.Text = user.UserName;
                    this.lblName.Text = "欢迎回来," + user.UserName;
                    this.lAccount.Text = user.Account;
                    this.lUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(user.UnitId);
                    this.lEmail.Text = user.Email;
                    if (!string.IsNullOrEmpty(user.IdentityCard))
                    {
                        var person = BLL.PersonService.GetPersonImgByIdentityCard(user.IdentityCard);
                        if (person != null)
                        {
                            this.imgPic.Src = ("~/" + person.PhotoUrl);
                        }
                    }
                    //this.lPostName.Text = user.WorkPostId;
                }
                //公司级看板权限
                if (this.CurrUser.IsOffice == true || this.CurrUser.UserId == Const.sysglyId || this.CurrUser.UserId == Const.hfnbdId)
                {
                    divgsj.Visible = true;
                }
                else
                {
                    divgsj.Visible = false;
                }
                if (Request.Cookies["SelectLan"] != null)
                {
                    HttpCookie lanCookie = Request.Cookies["SelectLan"];
                    if (lanCookie["lan"] != null)
                    {
                        drpSelectLan.SelectedValue = lanCookie["lan"];
                    }
                }
            }
        }
        #endregion
        #region 待办预警    
        [WebMethod]
        public static string getGztm(string userId, string sType)
        {
            string returnDbHtml = "";
            var getDataList = Funs.DB.Sp_WorkBench_GetToDoItems(userId, sType).ToList();
            //调人力预警接口
            if (sType != "2")
            {
                var sgList = SGManPowerService.CheckAndSendPersonWarning(userId);
                if (sgList != null)
                {
                    foreach (var item in sgList)
                    {
                        getDataList.Add(item);
                    }
                }
            }
            //把getDataList和sgList的数据合并
            foreach (var item in getDataList)
            {
                returnDbHtml += "
" + item.ProjectCode + "   " + "" + item.MenuName + "    " + item.Content + "
" + item.DataTime.ToString().Replace('/', '-').Split(' ')[0] + "
 + ") " + tb.Rows[i][2].ToString() + "
" + tb.Rows[i][2].ToString() + "
进入项目
 + ") " + tb.Rows[i][2].ToString() + "
" + tb.Rows[i][2].ToString() + "
进入项目
 + ") " + tb.Rows[i][2].ToString() + "
" + tb.Rows[i][2].ToString() + "
进入项目
 + ") " + tb.Rows[i][2].ToString() + "
" + tb.Rows[i][2].ToString() + "
进入项目
 + ") " + tb.Rows[i][2].ToString() + "
" + tb.Rows[i][2].ToString() + "
进入项目