using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
namespace ComResProSystem
{
    public partial class UserLeave:BasePage
    {
        BaseBLL bll = new BaseBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindLeaveinfo(1);
                PageCount(3);
            }
        }
        public void PageCount(int Page)
        {
            Lb_Total.Text = bll.SelPageCount("Userleave", Condition(), Page).ToString();
            Lb_Now.Text = "1";
        }
        protected void Ibt_select_Click(object sender, ImageClickEventArgs e)
        {
            BindLeaveinfo(1);
            PageCount(3);
            setEnable();
        }
        public string Condition()
        {
            string conditon = "Applicationstate='申请离职'";
            if (Dd_Part.Text != "-请选择-")
            {
                conditon = conditon + " and UserPart='" + Dd_Part.Text + "'";
            }

            if (Dd_UserPos.Text != "-请选择-")
            {
                conditon = conditon + " and UserPos='" + Dd_UserPos.Text + "'";
            }
            return conditon;
        }
        public void BindLeaveinfo(int pageindex)
        {
            List<object> list = bll.SelctObjectByPage(typeof(Model.UserLeave), "Userleave", "*", Condition(), pageindex, 3, "ID", "ID");
            Repeater1.DataSource = list;
            Repeater1.DataBind();
            if (list.Count > 0)
            {
                preup.Attributes.Add("style", "display:block;margin-right:5%;");
            }
            else
            {
                preup.Attributes.Add("style", "display:none");
            }
        }
        public void setEnable()
        {
            Ibt_Firsr.Enabled = Lb_Now.Text == "1" ? false : true;
            Ibt_Pre.Enabled = Lb_Now.Text == "1" ? false : true; ;
            Ibt_Next.Enabled = Lb_Now.Text == Lb_Total.Text ? false : true;
            Ibt_Last.Enabled = Lb_Now.Text == Lb_Total.Text ? false : true;
        }

        protected void Ibt_Firsr_Click(object sender, ImageClickEventArgs e)
        {
            int pageindex = 1;
            BindLeaveinfo(pageindex);
            Lb_Now.Text = pageindex.ToString();
            setEnable();
        }

        protected void Ibt_Pre_Click(object sender, ImageClickEventArgs e)
        {
            int pageindex = Convert.ToInt32(Lb_Now.Text) - 1;
            BindLeaveinfo(pageindex);
            Lb_Now.Text = pageindex.ToString();
            setEnable();
        }

        protected void Ibt_Next_Click(object sender, ImageClickEventArgs e)
        {
            int pageindex = Convert.ToInt32(Lb_Now.Text) + 1;
            BindLeaveinfo(pageindex);
            Lb_Now.Text = pageindex.ToString();
            setEnable();
        }

        protected void Ibt_Last_Click(object sender, ImageClickEventArgs e)
        {
            int pageindex = Convert.ToInt32(Lb_Total.Text);
            BindLeaveinfo(pageindex);
            Lb_Now.Text = pageindex.ToString();
            setEnable();
        }

        protected void Ibt_goto_Click(object sender, ImageClickEventArgs e)
        {
            if (Tb_goto.Text != "")
            {
                int go = Convert.ToInt32(Tb_goto.Text);
                int total = Convert.ToInt32(Lb_Total.Text);
                if (go >= 1 && go <= total)
                {
                    BindLeaveinfo(go);
                    Lb_Now.Text = go.ToString();
                    setEnable();
                    Tb_goto.Text = "";
                    PageCount(3);
                }
                else
                {
                    Tb_goto.Text = "";
                }
            }
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Aduit")
            {
                string pageindex = Lb_Now.Text;
                string ID = e.CommandArgument.ToString().Split('@')[0];
                string UserID = e.CommandArgument.ToString().Split('@')[1];
                System.Web.UI.ScriptManager.RegisterStartupScript(this, Page.GetType(), "ajaxjs", " var sReturn=window.showModalDialog('LeaveDetail.aspx?ID=" + ID + "&&UserID="+UserID+"','window','dialogWidth:600px;dialogHeight:560px;help:0;scroll:1;status:no;');if(sReturn=='1'){document.getElementById('" + this.Tb_goto.UniqueID + "').value=" + pageindex + ";document.getElementById('" + this.Ibt_goto.UniqueID + "').click();}", true);
            }
        }
    }
}