using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FineUIPro.Web.common
{
    public partial class MainSearch : PageBase
    {
        #region 加载
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                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.PriceSchemeService.InitDropDownList(this.drpPricingScheme, true);//存Value

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

                List<string> lists = Funs.GetStrListByStr(s, '|');
                if (!string.IsNullOrEmpty(lists[0]))
                {
                    this.txtKeyword.Text = lists[0];
                }
                if (!string.IsNullOrEmpty(lists[1]))
                {
                    this.txtContractNo.Text = lists[1];
                }
                if (!string.IsNullOrEmpty(lists[2]))
                {
                    this.drpContractAdmin.SelectedValue = lists[2];
                }
                if (!string.IsNullOrEmpty(lists[3]))
                {
                    this.drpPricingScheme.SelectedValue = lists[3];
                }
            }
        }
        #endregion

        #region 确定
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSure_Click(object sender, EventArgs e)
        {
            string keyword = this.txtKeyword.Text.Trim();
            string contractNo = this.txtContractNo.Text.Trim();            
            string ContractAdmin = "";
            string pricingScheme = "";  
            if (this.drpContractAdmin.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpContractAdmin.SelectedValue))
            {
                ContractAdmin = this.drpContractAdmin.SelectedValue;
            }
            if (this.drpPricingScheme.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpPricingScheme.SelectedValue))
            {
                pricingScheme = this.drpPricingScheme.SelectedValue;
            }
            string result = keyword + "|" + contractNo + "|" + ContractAdmin + "|" + pricingScheme + "|" + ContractAdmin;

            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.txtKeyword.Text = string.Empty;
            this.txtContractNo.Text = string.Empty;
            this.drpContractAdmin.SelectedIndex = 0;
            this.drpPricingScheme.SelectedIndex = 0;
        }
        #endregion
    }
}