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

'' 项目升级时需读取以下生成工具的版权信息
'' 生成工具：风越代码生成器 [FireCode Creator]
'' 当前版本：通用版 V1.8
'' 官方网站：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 YongHuXinXi_list : 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()
        {
            //标头文字
            string strHeader = @"<a href='YongHuXinXi_add.aspx' target='_blank'> 新增 </a> ";
            this.GridView1.Columns[10].HeaderText = strHeader;
            this.GridView1.Columns[10].FooterText = strHeader;
        }
        

        /// <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 = " [USER_ID] desc, [USER_NAME] desc";

            //this.Response.Write(strWhere);
            DataTable tabSrouce = new Fyp_3TierCommon.BLL.BLL_USER().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)
                {

                    //设置删除提示
                    if (e.Row.FindControl("LinkButton_Del") != null)
                        ((LinkButton)e.Row.FindControl("LinkButton_Del")).Attributes.Add("onclick", "javascript:return confirm('是否确认删除本条记录?')");

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

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_USER_ID).Text = WebString.HtmlEncodeExtend(str_USER_ID_value);
                        

                        
                    

                    
                    }
    
                    object objLab_USER_NAME = e.Row.FindControl("lab_USER_NAME_Show");
                    if (objLab_USER_NAME is Label)
                    {
                        string str_USER_NAME_value = ((Label)objLab_USER_NAME).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_USER_NAME).Text = WebString.HtmlEncodeExtend(str_USER_NAME_value);
                        

                        
                    

                    
                    }
    
                    object objLab_USER_PWD = e.Row.FindControl("lab_USER_PWD_Show");
                    if (objLab_USER_PWD is Label)
                    {
                        string str_USER_PWD_value = ((Label)objLab_USER_PWD).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_USER_PWD).Text = WebString.HtmlEncodeExtend(str_USER_PWD_value);
                        

                        
                    

                    
                    }
    
                    object objLab_USER_EMAIL = e.Row.FindControl("lab_USER_EMAIL_Show");
                    if (objLab_USER_EMAIL is Label)
                    {
                        string str_USER_EMAIL_value = ((Label)objLab_USER_EMAIL).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_USER_EMAIL).Text = WebString.HtmlEncodeExtend(str_USER_EMAIL_value);
                        

                        
                    

                    
                    }
    
                    object objLab_USER_BIRTHDAY = e.Row.FindControl("lab_USER_BIRTHDAY_Show");
                    if (objLab_USER_BIRTHDAY is Label)
                    {
                        string str_USER_BIRTHDAY_value = ((Label)objLab_USER_BIRTHDAY).Text;
                    
                                                
                        str_USER_BIRTHDAY_value = RegExp.RegMatch(@"([^\s]+)", str_USER_BIRTHDAY_value, "$1", true);

                        

                        

                        

                        

                        

                        

                        

                        
                        ((Label)objLab_USER_BIRTHDAY).Text = WebString.HtmlEncodeExtend(str_USER_BIRTHDAY_value);
                        

                        
                    

                    
                    }
    
                    object objLab_USER_PHOTO = e.Row.FindControl("lab_USER_PHOTO_Show");
                    if (objLab_USER_PHOTO is Label)
                    {
                        string str_USER_PHOTO_value = ((Label)objLab_USER_PHOTO).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        
                        if (str_USER_PHOTO_value.Length > 0)
                            str_USER_PHOTO_value = "<img src='" + str_USER_PHOTO_value + "'>";

                        

                        
                        ((Label)objLab_USER_PHOTO).Text = str_USER_PHOTO_value;
                        
                    

                    
                    }
    
                    object objLab_USER_PHOTOS2 = e.Row.FindControl("lab_USER_PHOTOS2_Show");
                    if (objLab_USER_PHOTOS2 is Label)
                    {
                        string str_USER_PHOTOS2_value = ((Label)objLab_USER_PHOTOS2).Text;
                    
                        

                        

                        

                        

                        

                        

                        

                        
                        if (str_USER_PHOTOS2_value.Length > 0)
                            str_USER_PHOTOS2_value = "<img src='" + str_USER_PHOTOS2_value + "'>";

                        

                        
                        ((Label)objLab_USER_PHOTOS2).Text = str_USER_PHOTOS2_value;
                        
                    

                    
                    }
    
                    object objLab_USER_NATION = e.Row.FindControl("lab_USER_NATION_Show");
                    if (objLab_USER_NATION is Label)
                    {
                        string str_USER_NATION_value = ((Label)objLab_USER_NATION).Text;
                    

                    
                        if (str_USER_NATION_value.Length > 0)
                        {
                            
                            Fyp_3TierCommon.Model.Model_NATION model_NATION = new Fyp_3TierCommon.BLL.BLL_NATION().GetModel(int.Parse(str_USER_NATION_value));
                            

                            

                            if (model_NATION != null)
                            {
                                string str_USER_NATION = model_NATION.NATION_NAME.ToString();
                                ((Label)objLab_USER_NATION).Text = WebString.HtmlEncodeExtend(str_USER_NATION);
                            }
                        }
                    
                    }
    
                    object objLab_USER_COUNTRY = e.Row.FindControl("lab_USER_COUNTRY_Show");
                    if (objLab_USER_COUNTRY is Label)
                    {
                        string str_USER_COUNTRY_value = ((Label)objLab_USER_COUNTRY).Text;
                    

                    
                        if (str_USER_COUNTRY_value.Length > 0)
                        {
                            
                            Fyp_3TierCommon.Model.Model_COUNTRY model_COUNTRY = new Fyp_3TierCommon.BLL.BLL_COUNTRY().GetModel(int.Parse(str_USER_COUNTRY_value));
                            

                            

                            if (model_COUNTRY != null)
                            {
                                string str_USER_COUNTRY = model_COUNTRY.COUNTRY_CN.ToString();
                                ((Label)objLab_USER_COUNTRY).Text = WebString.HtmlEncodeExtend(str_USER_COUNTRY);
                            }
                        }
                    
                    }
    
                    object objLab_USER_PROVINCE = e.Row.FindControl("lab_USER_PROVINCE_Show");
                    if (objLab_USER_PROVINCE is Label)
                    {
                        string str_USER_PROVINCE_value = ((Label)objLab_USER_PROVINCE).Text;
                    

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

                            

                            if (model_PROVINCE != null)
                            {
                                string str_USER_PROVINCE = model_PROVINCE.PROVINCE_CN.ToString();
                                ((Label)objLab_USER_PROVINCE).Text = WebString.HtmlEncodeExtend(str_USER_PROVINCE);
                            }
                        }
                    
                    }
    
                }
            }
        }

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




    
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            this.GridView1.EditIndex = e.NewEditIndex;
            //当前编辑行背景色高亮
            this.GridView1.EditRowStyle.CssClass = "tableTitle1";
            //this.GridView1.EditRowStyle.BackColor = System.Drawing.Color.FromName("#F7CE90");
            FillGrid();
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            this.GridView1.EditIndex = -1;
            FillGrid();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int i = e.RowIndex;
        
            
            
            int req_USER_ID = int.Parse(this.GridView1.DataKeys[i].Values["USER_ID"].ToString());
            

            
            
        
            
            

            
            
            string req_USER_NAME = this.GridView1.DataKeys[i].Values["USER_NAME"].ToString();
            
        
            Fyp_3TierCommon.Model.Model_USER model_USER = new Fyp_3TierCommon.BLL.BLL_USER().GetModel(req_USER_ID, req_USER_NAME);
        
            
            model_USER.USER_NAME = ((TextBox)(GridView1.Rows[i].FindControl("USER_NAME"))).Text;
            
        
            new Fyp_3TierCommon.BLL.BLL_USER().Update(model_USER);

            this.GridView1.EditIndex = -1;
            FillGrid();
        }
    

        

        
        //单条删除记录
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int i = e.RowIndex;
        
            
            
            int var_USER_ID = int.Parse(this.GridView1.DataKeys[i].Values["USER_ID"].ToString());
            

            
            
        
            
            

            
            
            string var_USER_NAME = this.GridView1.DataKeys[i].Values["USER_NAME"].ToString();
            
        
            Fyp_3TierCommon.Model.Model_USER model_USER = new Fyp_3TierCommon.BLL.BLL_USER().GetModel(var_USER_ID, var_USER_NAME);

             //如有上载到磁盘的文件，需先删除
            string strFileName;
            string strFilePath;
            FypSystem.Common.FileSys fileSys = new FileSys();
            
            
            strFileName = model_USER.USER_PHOTO.ToString().Trim();
            if (strFileName.Length > 0)
            {
                strFilePath = fileSys.GetAbsPath(strFileName);
                System.IO.File.Delete(strFilePath);
                //this.Response.Write(strFilePath);
            }
            
            
            //然后再删除记录
            new Fyp_3TierCommon.BLL.BLL_USER().Delete(var_USER_ID, var_USER_NAME);

            this.GridView1.EditIndex = -1;
            FillGrid();
        }
        



    }
}