/*
'' ============================================================================================
'' 项目名称：风越项目范例ASPX普通三层结构
'' 项目版本：V1.0
'' 项目描述：风越项目范例，用于建立ASPX普通三层结构
'' 文件名称：ChengShi_search.aspx
'' 文件描述：信息搜索文件 （城市）
'' 公司名称：中极网盛
'' 开发人员：刘怒
'' 创建日期：2008-12-25 20:23:50
'' 修订日期：2009-01-14 12:12:23
'' 版权信息：Copyright (C) 2008

'' 项目升级时需读取以下生成工具的版权信息
'' 生成工具：风越代码生成器 [FireCode Creator]
'' 当前版本：通用版 V1.5
'' 官方网站：http://www.sino8848.com
'' ============================================================================================
*/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FypSystem.Common;
using FypSystem.DBManager;

namespace Fyp_3TierCommon.Web
{
    public partial class ChengShi_search : System.Web.UI.Page
    {
        /// <summary>
        /// 数据库是否为空
        /// </summary>
        bool bEmptyDataTable = false;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = WebPage.GetConfig("fypWebName");

            if (!Page.IsPostBack)
            {
                Initialize();
                FillGrid();
            }
        }

    
        /// <summary>
        /// 导入搜索框的默认值、数据
        /// </summary>
        private void Initialize()
        {
            //绑定属性
            


            //直接填充下拉框
            FypSystem.DBManager.FillCtrlData fillCtrlData = new FillCtrlData();
    
        
            

        
            Fyp_3TierCommon.BLL.BLL_PROVINCE bll_PROVINCE = new Fyp_3TierCommon.BLL.BLL_PROVINCE();
            DataTable dt_PROVINCE = bll_PROVINCE.GetDataTable("");
            fillCtrlData.FillListControl(this.PROVINCE_ID, dt_PROVINCE, "PROVINCE_ID", "PROVINCE_ID", "--请选择--", "");
            dt_PROVINCE.Dispose();
        

        
        
    

        }
    

    
    
    

    
        //执行搜索
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                string strWhere = "";
                

                
                if (this.CITY_ID.Text.Length > 0)
                    strWhere += " And [CITY_ID] like '%" + this.CITY_ID.Text + "%' ";
                

                
                

                

                
                if (this.PROVINCE_ID.Text.Length > 0)
                    strWhere += " And [PROVINCE_ID] = " + this.PROVINCE_ID.SelectedValue + " ";
                
                

                
                if (this.CITY_CN.Text.Length > 0)
                    strWhere += " And [CITY_CN] like '%" + this.CITY_CN.Text + "%' ";
                

                
                

                
                if (this.CITY_EN.Text.Length > 0)
                    strWhere += " And [CITY_EN] like '%" + this.CITY_EN.Text + "%' ";
                

                
                

                
                if (this.CITY_AREA_CODE.Text.Length > 0)
                    strWhere += " And [CITY_AREA_CODE] like '%" + this.CITY_AREA_CODE.Text + "%' ";
                

                
                

                if (strWhere.Trim().Length > 4)
                    strWhere = strWhere.Substring(4);

                ViewState["WhereCondition"] = strWhere;
                FillGrid();
            }
        }
    

        /// <summary>
        /// 填充数据网格
        /// </summary>
        private void FillGrid()
        {
            string strOrderBy = "";
            string strSortExpression = StringExtend.NullToEmptyStr(ViewState["SortExpression"]);
            string strSortDirection = StringExtend.NullToEmptyStr(ViewState["SortDirection"]);
            string strWhere = StringExtend.NullToEmptyStr(ViewState["WhereCondition"]);

            if (strSortExpression.Length > 0)
                strOrderBy = " [" + strSortExpression + "] " + strSortDirection;
            else
                strOrderBy = " [CITY_ID] desc";

            //this.Response.Write(strWhere);
            DataTable tabSrouce = new Fyp_3TierCommon.BLL.BLL_CITY().GetDataTable(strWhere, strOrderBy);

            //如数据库中无记录，则生成一条空值记录，以便显示表格
            if (tabSrouce.Rows.Count == 0)
            {
                DataRow rowEmpty = tabSrouce.NewRow();
                //rowEmpty[0] = DBNull.Value;
                tabSrouce.Rows.Add(rowEmpty);
                bEmptyDataTable = true;
            }

            
            this.GridView1.DataSource = tabSrouce;
            this.GridView1.DataBind();
            tabSrouce.Dispose();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //如数据库中无记录，设置临时行状态
                if (bEmptyDataTable)
                {
                    e.Row.Enabled = false;
                    return;
                }

                //鼠标进入、离开表格行时设置其背景色
                if (e.Row.RowState == DataControlRowState.Normal)
                {
                    e.Row.Attributes.Add("onmouseover", "SetTRcolorOver(this, 'tableContent001', 'tableContentOn001', 'tableContentClick001', 'tableContentClickOn001')");
                    e.Row.Attributes.Add("onmouseout", "SetTRcolorOut(this, 'tableContent001', 'tableContentOn001', 'tableContentClick001', 'tableContentClickOn001')");
                    e.Row.Attributes.Add("onclick", "SetTRcolorClick(true, " + this.GridView1.ClientID + ", this, '', '', true, 'tableContent001', 'tableContentOn001', 'tableContentClick001', 'tableContentClickOn001')");
                }
                else if (e.Row.RowState == DataControlRowState.Alternate)
                {
                    e.Row.Attributes.Add("onmouseover", "SetTRcolorOver(this, 'tableContentAlternating001', 'tableContentAlternatingOn001', 'tableContentClick001', 'tableContentClickOn001')");
                    e.Row.Attributes.Add("onmouseout", "SetTRcolorOut(this, 'tableContentAlternating001', 'tableContentAlternatingOn001', 'tableContentClick001', 'tableContentClickOn001')");
                    e.Row.Attributes.Add("onclick", "SetTRcolorClick(true, " + this.GridView1.ClientID + ", this, '', '', true, 'tableContentAlternating001', 'tableContentAlternatingOn001', 'tableContentClick001', 'tableContentClickOn001')");
                }

                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {

                    //格式化输出字段
    
                    object objLab_CITY_ID = e.Row.FindControl("lab_CITY_ID_Show");
                    if (objLab_CITY_ID is Label)
                    {
                        string str_CITY_ID_value = ((Label)objLab_CITY_ID).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_CITY_ID).Text = WebString.HtmlEncodeExtend(str_CITY_ID_value);
                        

                        
                    

                    
                    }
    
                    object objLab_PROVINCE_ID = e.Row.FindControl("lab_PROVINCE_ID_Show");
                    if (objLab_PROVINCE_ID is Label)
                    {
                        string str_PROVINCE_ID_value = ((Label)objLab_PROVINCE_ID).Text;
                    

                    
                        if (str_PROVINCE_ID_value.Length > 0)
                        {
                            
                            Fyp_3TierCommon.Model.Model_PROVINCE model_PROVINCE = new Fyp_3TierCommon.BLL.BLL_PROVINCE().GetModel(int.Parse(str_PROVINCE_ID_value));
                            

                            

                            if (model_PROVINCE != null)
                            {
                                string str_PROVINCE_ID = model_PROVINCE.PROVINCE_ID.ToString();
                                ((Label)objLab_PROVINCE_ID).Text = WebString.HtmlEncodeExtend(str_PROVINCE_ID);
                            }
                        }
                    
                    }
    
                    object objLab_CITY_CN = e.Row.FindControl("lab_CITY_CN_Show");
                    if (objLab_CITY_CN is Label)
                    {
                        string str_CITY_CN_value = ((Label)objLab_CITY_CN).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_CITY_CN).Text = WebString.HtmlEncodeExtend(str_CITY_CN_value);
                        

                        
                    

                    
                    }
    
                    object objLab_CITY_EN = e.Row.FindControl("lab_CITY_EN_Show");
                    if (objLab_CITY_EN is Label)
                    {
                        string str_CITY_EN_value = ((Label)objLab_CITY_EN).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_CITY_EN).Text = WebString.HtmlEncodeExtend(str_CITY_EN_value);
                        

                        
                    

                    
                    }
    
                    object objLab_CITY_AREA_CODE = e.Row.FindControl("lab_CITY_AREA_CODE_Show");
                    if (objLab_CITY_AREA_CODE is Label)
                    {
                        string str_CITY_AREA_CODE_value = ((Label)objLab_CITY_AREA_CODE).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_CITY_AREA_CODE).Text = WebString.HtmlEncodeExtend(str_CITY_AREA_CODE_value);
                        

                        
                    

                    
                    }
    
                }
            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            FillGrid();
        }






    }
}