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

namespace FineUIPro.Web.SES
{
    public partial class SESRelatedDataSearch : PageBase
    {
        #region 加载
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //是否交工资料
                this.drpConstRecords.DataTextField = "ConstText";
                this.drpConstRecords.DataValueField = "ConstValue";
                this.drpConstRecords.DataSource = BLL.ConstValue.drpConstItemList(ConstValue.Group_YesOrNo);
                this.drpConstRecords.DataBind();
                Funs.FineUIPleaseSelect(this.drpConstRecords);
                //状态
                this.drpFCStatus.DataTextField = "ConstText";
                this.drpFCStatus.DataValueField = "ConstValue";
                this.drpFCStatus.DataSource = BLL.ConstValue.drpConstItemList(ConstValue.Group_FC_Status);
                this.drpFCStatus.DataBind();
                Funs.FineUIPleaseSelect(this.drpFCStatus);

                BLL.ContractorService.InitDropDownList(this.drpContractor, true);//存Value
                //BLL.Sys_UserService.InitUserDropDownList(this.drpContractAdmin, true);//存Value
                this.drpContractAdmin.DataTextField = "UserName";
                this.drpContractAdmin.DataValueField = "UserId";
                this.drpContractAdmin.DataSource = BLL.Sys_UserService.getUserListByRoleId(BLL.Const.Role_ContractAdministratorId, false);
                this.drpContractAdmin.DataBind();
                Funs.FineUIPleaseSelect(this.drpContractAdmin);

                BLL.Sys_UserService.InitUserDropDownList(this.drpBuyer, true);//存Text
                BLL.Sys_UserService.InitUserDropDownList(this.drpMainCoord, true);//存Value
                BLL.DepartService.InitDropDownList(this.drpMCDepartment, true); //存Text
                BLL.DisciplineService.InitDropDownList(this.drpDiscipline, true);
                BLL.FOTypeService.InitDropDownList(this.drpFoType, true);//存Value

                string s = Request.Params["s"];

                List<string> lists = Funs.GetStrListByStr(s, '|');
                if (!string.IsNullOrEmpty(lists[0]))
                {
                    this.drpConstRecords.SelectedValue = lists[0];
                }
                if (!string.IsNullOrEmpty(lists[1]))
                {
                    this.txtFoNo.Text = lists[1];
                }
                if (!string.IsNullOrEmpty(lists[2]))
                {
                    this.drpDiscipline.SelectedValue = lists[2];
                }
                if (!string.IsNullOrEmpty(lists[3]))
                {
                    this.drpContractor.SelectedValue = lists[3];
                }
                if (!string.IsNullOrEmpty(lists[4]))
                {
                    this.drpContractAdmin.SelectedValue = lists[4];
                }
                if (!string.IsNullOrEmpty(lists[5]))
                {
                    var u = BLL.Sys_UserService.getUserIdByUserName(lists[5]);
                    if (u!=null)
                    {
                        this.drpBuyer.SelectedValue = u.UserId;
                    }                    
                }
                if (!string.IsNullOrEmpty(lists[6]))
                {
                    this.drpMainCoord.SelectedValue = lists[6];
                }
                if (!string.IsNullOrEmpty(lists[7]))
                {
                    var dep = BLL.DepartService.GetDepartByName(lists[7]);
                    if (dep != null)
                    {
                        this.drpMCDepartment.SelectedValue = dep.DepartId;
                    }
                }
                if (!string.IsNullOrEmpty(lists[8]))
                {
                    this.drpFCStatus.SelectedValue = lists[8];
                }
                if (!string.IsNullOrEmpty(lists[9]))
                {
                    this.drpFoType.SelectedValue = lists[9];
                }
            }
        }
        #endregion

        #region 确定
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSure_Click(object sender, EventArgs e)
        {
            string constRecords = "";
            string foNo = this.txtFoNo.Text.Trim();
            string discipline = "";
            string contractor = "";
            string ContractAdmin = "";
            string Buyer = "";
            string MainCoord = "";
            string MCDepartment = "";
            string FCStatus = "";
            string foType = "";
            if (this.drpConstRecords.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpConstRecords.SelectedValue))
            {
                constRecords = this.drpConstRecords.SelectedItem.Text.Trim();
            }
            if (this.drpContractor.SelectedValue!=BLL.Const._Null&&!string.IsNullOrEmpty(this.drpContractor.SelectedValue))
            {
                contractor = this.drpContractor.SelectedValue;
            }
            if (this.drpContractAdmin.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpContractAdmin.SelectedValue))
            {
                ContractAdmin = this.drpContractAdmin.SelectedValue;
            }
            if (this.drpBuyer.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpBuyer.SelectedValue))
            {
                Buyer = this.drpBuyer.SelectedItem.Text.Trim();
            }
            if (this.drpMainCoord.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpMainCoord.SelectedValue))
            {
                MainCoord = this.drpMainCoord.SelectedValue;
            }
            if (this.drpMCDepartment.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpMCDepartment.SelectedValue))
            {
                MCDepartment = this.drpMCDepartment.SelectedItem.Text.Trim();
            }
            if (this.drpFCStatus.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpFCStatus.SelectedValue))
            {
                FCStatus = this.drpFCStatus.SelectedItem.Text.Trim();
            }
            if (this.drpDiscipline.SelectedValue!=BLL.Const._Null&&!string.IsNullOrEmpty(this.drpDiscipline.SelectedValue))
            {
                discipline = this.drpDiscipline.SelectedValue;
            }
            if (this.drpFoType.SelectedValue!=BLL.Const._Null&&!string.IsNullOrEmpty(this.drpFoType.SelectedValue))
            {
                foType = this.drpFoType.SelectedValue;
            }
            string result = constRecords + "|" + foNo + "|" + discipline + "|" + contractor + "|" + ContractAdmin + "|" + Buyer + "|" + MainCoord + "|" + MCDepartment + "|" + FCStatus + "|" + foType;

            PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(result)
                   + ActiveWindow.GetHidePostBackReference());
        }
        #endregion

        #region 重置
        /// <summary>
        /// 重置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnReset_Click(object sender, EventArgs e)
        {
            this.drpConstRecords.SelectedIndex = 0;
            this.txtFoNo.Text = string.Empty;
            this.drpDiscipline.SelectedIndex = 0;
            this.drpContractor.SelectedIndex = 0;
            this.drpContractAdmin.SelectedIndex = 0;
            this.drpBuyer.SelectedIndex = 0;
            this.drpMainCoord.SelectedIndex = 0;
            this.drpMCDepartment.SelectedIndex = 0;
            this.drpFCStatus.SelectedIndex = 0;
            this.drpFoType.SelectedIndex = 0;
        }
        #endregion
    }
}