/*
'' ============================================================================================
'' 项目名称：{fyp_title}
'' 项目版本：{fyp_version}
'' 项目描述：{fyp_description}
'' 文件名称：{file_search_name}
'' 文件描述：信息搜索文件{value_match_check value1="{table_description}" value2="" extend_match="unequal"} （{table_description}）{/value_match_check}
'' 公司名称：{fyp_company}
'' 开发人员：{fyp_designer}
'' 创建日期：{fyp_created_date}
'' 修订日期：{system_date_time format="yyyy-MM-dd hh:mm:ss"}
'' 版权信息：{fyp_copyright}

'' 项目升级时需读取以下生成工具的版权信息
'' 生成工具：{fysoft_name}
'' 当前版本：{fysoft_version}
'' 官方网站：{fysoft_website}
'' ============================================================================================
*/

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_namespace}.Web
{
    public partial class {file_search_name type="2"} : 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();
            }
        }

    {remark note="说明："}导入搜索框的默认值、数据，用于search文件，如是list文件，删除此代码 begin{/remark}
        /// <summary>
        /// 导入搜索框的默认值、数据
        /// </summary>
        private void Initialize()
        {
            //绑定属性
            {fields_loop}
            {control_style_check value="日时选择" match="true"}
            this.{control_name}.Attributes.Add("onFocus", "WdatePicker({dateFmt:'yyyy-MM-dd H:mm:ss'})");
            {/control_style_check}
            {control_style_check value="日期选择" match="true"}
            this.{control_name}.Attributes.Add("onFocus", "WdatePicker({dateFmt:'yyyy-MM-dd'})");
            {/control_style_check}
            {control_style_check value="时分秒框" match="true"}
            this.{control_name}.Attributes.Add("onFocus", "WdatePicker({dateFmt:'H:mm:ss'})");
            {/control_style_check}
            {control_style_check value="时分框" match="true"}
            this.{control_name}.Attributes.Add("onFocus", "WdatePicker({dateFmt:'H:mm'})");
            {/control_style_check}
            {/fields_loop}

{field_seltable_name_all_check value="不链接表" match="false"}
            //直接填充下拉框
            FypSystem.DBManager.FillCtrlData fillCtrlData = new FillCtrlData();
    {fields_loop}
        {field_seltable_name_check value="不链接表" match="false"}
            {remark note="说明："}当前字段是级联下拉框的第一级，或不是级联下拉框时，不需判断where条件{/remark}

        {field_seltable_level_check value="0|1" match="true"}
            {fyp_namespace}.BLL.BLL_{field_seltable_name} bll_{field_seltable_name} = new {fyp_namespace}.BLL.BLL_{field_seltable_name}();
            DataTable dt_{field_seltable_name} = bll_{field_seltable_name}.GetDataTable("");
            fillCtrlData.FillListControl(this.{control_name}, dt_{field_seltable_name}, "{field_seltable_text}", "{field_seltable_value}", "--请选择--", "");
            dt_{field_seltable_name}.Dispose();
        {/field_seltable_level_check}

        {field_seltable_level_check value="0|1" match="false"}
            {remark note="说明："}如ID与value相同，可直接读取{/remark}

            {value_match_check value1="{field_seltable_id}" value2="{field_seltable_value}" extend_match="equal"}
            if (this.{control_name next="-1"}.SelectedIndex >= 0 && this.{control_name next="-1"}.SelectedValue.Length > 0)
            {
                {fyp_namespace}.BLL.BLL_{field_seltable_name} bll_{field_seltable_name} = new {fyp_namespace}.BLL.BLL_{field_seltable_name}();
                DataTable dt_{field_seltable_name} = bll_{field_seltable_name}.GetDataTable("{field_seltable_parent_id}={get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_parent_id}"}" + this.{control_name next="-1"}.SelectedValue + "{get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_parent_id}"}");
                fillCtrlData.FillListControl(this.{control_name}, dt_{field_seltable_name}, "{field_seltable_text}", "{field_seltable_value}", "--请选择--", "");
                dt_{field_seltable_name}.Dispose();
            }
            {/value_match_check}

            {remark note="说明："}如ID与value不同，需通过value获取ID（待调整）{/remark}
            {value_match_check value1="{field_seltable_id}" value2="{field_seltable_value}" extend_match="unequal"}
            if (this.{control_name next="-1"}.SelectedIndex >= 0 && this.{control_name next="-1"}.SelectedValue.Length > 0)
            {
                //string strIndex = dbManager.Read("select [{field_seltable_id next="-1"}] from [{field_seltable_name next="-1"}] where [{field_seltable_value next="-1"}]={get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name next="-1"}" field="{field_seltable_value next="-1"}"}" + this.{control_name next="-1"}.SelectedValue + "{get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name next="-1"}" field="{field_seltable_value next="-1"}"}")["{field_seltable_id next="-1"}"].ToString();
                string strIndex = new {fyp_namespace}.BLL.BLL_{field_seltable_name next="-1"}().GetModel(this.{control_name next="-1"}.SelectedValue).{field_seltable_id next="-1"}.ToString();

                {fyp_namespace}.BLL.BLL_{field_seltable_name} bll_{field_seltable_name} = new {fyp_namespace}.BLL.BLL_{field_seltable_name}();
                DataTable dt_{field_seltable_name} = bll_{field_seltable_name}.GetDataTable("{field_seltable_parent_id}={get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_parent_id}"}" + strIndex + "{get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_parent_id}"}");
                fillCtrlData.FillListControl(this.{control_name}, dt_{field_seltable_name}, "{field_seltable_text}", "{field_seltable_value}", "--请选择--", "");
                dt_{field_seltable_name}.Dispose();
            }
            {/value_match_check}

        {/field_seltable_level_check}
        {/field_seltable_name_check}
    {/fields_loop}
{/field_seltable_name_all_check}
        }
    {remark note="说明："}导入搜索框的默认值、数据，用于search文件，如是list文件，删除此代码 end{/remark}

    {remark note="说明："}填充下拉框，用于search文件，如是list文件，删除此代码 begin{/remark}
    {fields_loop}
        {remark note="说明："}当前字段及下级字段设置的级别不为0，才生成级联代码{/remark}
        {field_seltable_level_check value="0|null" match="false" next="1"}
            {field_seltable_level_check value="0|null" match="false"}
        protected void {control_name}_SelectedIndexChanged(object sender, EventArgs e)
        {
            //填充下拉框
            if (this.{control_name}.SelectedValue.Length > 0)
            {
                string strWhere = "";
                {remark note="说明："}如ID与value不同，需通过value获取ID，如相同，可直接使用上句{/remark}
                {value_match_check value1="{field_seltable_id}" value2="{field_seltable_value}" extend_match="equal"}
                strWhere = " {field_seltable_parent_id next="1"}={get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name next='1'}" field="{field_seltable_parent_id next='1'}"}" + this.{control_name}.SelectedValue + "{get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name next='1'}" field="{field_seltable_parent_id next='1'}"}";
                {/value_match_check}

                {value_match_check value1="{field_seltable_id}" value2="{field_seltable_value}" extend_match="unequal"}
                //string strIndex = dbManager.Read("select [{field_seltable_id}] from [{field_seltable_name}] where [{field_seltable_value}]={get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_value}"}" + this.{control_name}.SelectedValue + "{get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_value}"}")["{field_seltable_id}"].ToString();
                string strIndex = new {fyp_namespace}.BLL.BLL_{field_seltable_name next="-1"}().GetModel(model_{table_source_name}.{field_source_name next="-1"}).{field_seltable_id next="-1"}.ToString();
                strWhere = " [{field_seltable_parent_id next="1"}]={get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name next="1"}" field="{field_seltable_parent_id next="1"}"}" + strIndex + "{get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name next="1"}" field="{field_seltable_parent_id next="1"}"}";
                {/value_match_check}

                {fyp_namespace}.BLL.BLL_{field_seltable_name next="1"} bll_{field_seltable_name next="1"} = new {fyp_namespace}.BLL.BLL_{field_seltable_name next="1"}();
                DataTable dtTable = bll_{field_seltable_name next="1"}.GetDataTable(strWhere);
                FypSystem.DBManager.FillCtrlData fillCtrlData = new FillCtrlData();
                fillCtrlData.FillListControl(this.{control_name next="1"}, dtTable, "{field_seltable_text next="1"}", "{field_seltable_value next="1"}", "--请选择--", "");
            }
        }
           {/field_seltable_level_check}
        {/field_seltable_level_check}
    {/fields_loop}
    {remark note="说明："}填充下拉框，用于search文件，如是list文件，删除此代码 end{/remark}

    {remark note="说明："}执行搜索，用于search文件，如是list文件，删除此代码 begin{/remark}
        //执行搜索
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                string strWhere = "";
                {fields_loop}

                {control_style_check value="文本框|文本域|UBB文本|密码框|隐藏域|时分框|时分秒框|日时选择|日期选择" match="true"}
                if (this.{control_name}.Text.Length > 0)
                    strWhere += " And [{field_name}] like '%" + this.{control_name}.Text + "%' ";
                {/control_style_check}

                {control_style_check value="单选按钮|多选按钮|下拉列表|单选列表|多选列表" match="true"}
                if (this.{control_name}.Text.Length > 0)
                    strWhere += " And [{field_name}] = {field_single_quote}" + this.{control_name}.SelectedValue + "{field_single_quote} ";
                {/control_style_check}
                {/fields_loop}

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

                ViewState["WhereCondition"] = strWhere;
                FillGrid();
            }
        }
    {remark note="说明："}执行搜索，用于search文件，如是list文件，删除此代码 end{/remark}

        /// <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 = " {fields_loop type="3" separator=", "}[{field_name}] desc{/fields_loop}";

            //this.Response.Write(strWhere);
            DataTable tabSrouce = new {fyp_namespace}.BLL.BLL_{table_source_name}().GetDataTable(strWhere, strOrderBy);

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

            {remark note="说明：备用"}
            //格式化输出“字符型”字段
            /*
            foreach (DataRow row in tabSrouce.Rows)
            {
                {fields_loop}{field_usetype_name_check value="文本" match="true"}
                row["{field_name}"] = WebString.HtmlEncodeExtend(row["{field_name}"].ToString());{/field_usetype_name_check}{/fields_loop}
            }
            */
            {/remark}
            this.GridView1.DataSource = tabSrouce;
            this.GridView1.DataBind();
            tabSrouce.Dispose();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        {remark note="说明：备用"}
        {batch_manage_check value="true" match="true"}
            //添加批量删除按钮
            if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.Footer)
            {
                HyperLink linkNew = new HyperLink();
                linkNew.Text = "新增 ";
                linkNew.NavigateUrl = "{file_add_name}";
                linkNew.Target = "_blank";
                //e.Row.Cells[e.Row.Cells.Count - 1].Controls.Add(linkNew);
                //this.GridView1.HeaderRow.Cells[this.GridView1.HeaderRow.Cells.Count - 1].Text = "";

                LinkButton lnkBtnDel = new LinkButton();
                lnkBtnDel.Text = " 删除";
                lnkBtnDel.Click += new EventHandler(lnkBtn_Del_Click);
                //e.Row.Cells[e.Row.Cells.Count - 1].Controls.Add(lnkBtnDel);
                //this.GridView1.HeaderRow.Cells[this.GridView1.HeaderRow.Cells.Count - 1].Text = "";
            }
        {/batch_manage_check}
        {/remark}

            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, '{batch_manage_check value="true" match="true"}CheckBox_RecMain{/batch_manage_check}', '{batch_manage_check value="true" match="true"}CheckBox_RecID{/batch_manage_check}', 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, '{batch_manage_check value="true" match="true"}CheckBox_RecMain{/batch_manage_check}', '{batch_manage_check value="true" match="true"}CheckBox_RecID{/batch_manage_check}', true, 'tableContentAlternating001', 'tableContentAlternatingOn001', 'tableContentClick001', 'tableContentClickOn001')");
                }

                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
{create_manage_check value="true" match="true"}
                    //设置删除提示
                    if (e.Row.FindControl("LinkButton_Del") != null)
                        ((LinkButton)e.Row.FindControl("LinkButton_Del")).Attributes.Add("onclick", "javascript:return confirm('是否确认删除本条记录?')");
{/create_manage_check}
                    //格式化输出字段
    {fields_loop}
                    object objLab_{field_source_name} = e.Row.FindControl("lab_{control_name}_Show");
                    if (objLab_{field_source_name} is Label)
                    {
                        string str_{field_source_name}_value = ((Label)objLab_{field_source_name}).Text;
                    {field_seltable_name_check value="不链接表" match="true"}
                        {control_style_check value="日期选择" match="true"}                        
                        str_{field_source_name}_value = RegExp.RegMatch(@"([^\s]+)", str_{field_source_name}_value, "$1", true);{/control_style_check}

                        {control_style_check value="时分框" match="true"}                        
                        str_{field_source_name}_value = RegExp.RegMatch(@"(\d+:\d+)(:\d+)", str_{field_source_name}_value, "$1", true);{/control_style_check}

                        {control_style_check value="时分秒框" match="true"}
                        str_{field_source_name}_value = RegExp.RegMatch(@"(\d+:\d+:\d+)", str_{field_source_name}_value, "$1", true);{/control_style_check}

                        {field_display_style_check value="前20字符" match="true"}
                        str_{field_source_name}_value = StringExtend.Left(str_{field_source_name}_value, 20);{/field_display_style_check}

                        {field_display_style_check value="链接文件" match="true"}
                        str_{field_source_name}_value = "<a href='" + str_{field_source_name}_value + "'>打开文件 " + str_{field_source_name}_value + "</a>";{/field_display_style_check}

                        {field_display_style_check value="文本框" match="true"}
                        str_{field_source_name}_value = "<input value='" + str_{field_source_name}_value + "'>";{/field_display_style_check}

                        {field_display_style_check value="文本域" match="true"}
                        str_{field_source_name}_value = "<textarea>" + str_{field_source_name}_value + "</textarea>";{/field_display_style_check}

                        {field_display_style_check value="显示图片" match="true"}
                        if (str_{field_source_name}_value.Length > 0)
                            str_{field_source_name}_value = "<img src='" + str_{field_source_name}_value + "'>";{/field_display_style_check}

                        {field_display_style_check value="显示文字|前20字符" match="true"}
                        ((Label)objLab_{field_source_name}).Text = WebString.HtmlEncodeExtend(str_{field_source_name}_value);
                        {/field_display_style_check}

                        {field_display_style_check value="显示文字|前20字符" match="false"}
                        ((Label)objLab_{field_source_name}).Text = str_{field_source_name}_value;
                        {/field_display_style_check}
                    {/field_seltable_name_check}

                    {field_seltable_name_check value="不链接表" match="false"}
                        if (str_{field_source_name}_value.Length > 0)
                        {
                            {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="unequal"}
                            {fyp_namespace}.Model.Model_{field_seltable_name} model_{field_seltable_name} = new {fyp_namespace}.BLL.BLL_{field_seltable_name}().GetModel({field_code_datatype_name code="cs" type="3" compatible="false"}.Parse(str_{field_source_name}_value));
                            {/value_match_check}

                            {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="equal"}
                            {fyp_namespace}.Model.Model_{field_seltable_name} model_{field_seltable_name} = new {fyp_namespace}.BLL.BLL_{field_seltable_name}().GetModel(str_{field_source_name}_value);
                            {/value_match_check}

                            if (model_{field_seltable_name} != null)
                            {
                                string str_{field_source_name} = model_{field_seltable_name}.{field_seltable_text}.ToString();
                                ((Label)objLab_{field_source_name}).Text = WebString.HtmlEncodeExtend(str_{field_source_name});
                            }
                        }
                    {/field_seltable_name_check}
                    }
    {/fields_loop}
                }
            }
        }

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

{create_order_by_check value="true" match="true"}
        //排序
        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            string strSortExpression= e.SortExpression;
            if (StringExtend.NullToEmptyStr(ViewState["SortExpression"]) == strSortExpression)
            {
                //点击相同标题时，转换排序顺序
                if (StringExtend.NullToEmptyStr(ViewState["SortDirection"]) == "desc")
                    ViewState["SortDirection"] = "asc";
                else
                    ViewState["SortDirection"] = "desc";
            }
            else
            {
                //点击不同标题时，默认倒序排序
                ViewState["SortExpression"] = strSortExpression;
                ViewState["SortDirection"] = "desc";
            }

            //添加排序标识符号
            foreach (DataControlField field in this.GridView1.Columns)
            {
                //if (field is BoundField)
                //((BoundField)field).HtmlEncode = false;

                //field.HeaderText = field.HeaderText.Replace("▲", "").Replace("▼", "");
                field.HeaderText = field.HeaderText.Replace("<font face='webdings'>5</font>", "").Replace("<font face='webdings'>6</font>", "");
                //((BoundField)(this.GridView1.Columns[0])).DataField

                if (field.SortExpression.ToLower() == strSortExpression.ToLower())
                {
                    if (ViewState["SortDirection"].ToString() == "desc")
                        field.HeaderText = field.HeaderText.Trim() + " <font face='webdings'>6</font>";
                    else
                        field.HeaderText = field.HeaderText.Trim() + " <font face='webdings'>5</font>";
                }
            }
            FillGrid();
        }
{/create_order_by_check}

{create_manage_check value="true" match="true"}
    {field_edit_in_list_all_check value="true" match="true" type="1"}
        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;
        {fields_loop type="3" distinct="true"}
            {remark}非字符串参数，转换类型{/remark}
            {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="unequal"}
            {field_code_datatype_name code="cs" type="3" compatible="false"} req_{field_source_name} = {field_code_datatype_name code="cs" type="3" compatible="false"}.Parse(this.GridView1.DataKeys[i].Values["{field_name}"].ToString());
            {/value_match_check}

            {remark}字符串参数，直接使用{/remark}
            {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="equal"}
            {field_code_datatype_name code="cs" type="3" compatible="false"} req_{field_source_name} = this.GridView1.DataKeys[i].Values["{field_name}"].ToString();
            {/value_match_check}
        {/fields_loop}
            {fyp_namespace}.Model.Model_{table_source_name} model_{table_source_name} = new {fyp_namespace}.BLL.BLL_{table_source_name}().GetModel({fields_loop type="3" distinct="true" separator=", "}req_{field_source_name}{/fields_loop});
        {fields_loop distinct="true"}
            {field_edit_in_list_check value="true" match="true"}
            model_{table_source_name}.{field_source_name} = ((TextBox)(GridView1.Rows[i].FindControl("{control_name}"))).Text;
            {/field_edit_in_list_check}
        {/fields_loop}
            new {fyp_namespace}.BLL.BLL_{table_source_name}().Update(model_{table_source_name});

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

        {batch_manage_check value="true" match="true"}
        //批量删除记录
        protected void lnkBtn_Del_Click(object sender, EventArgs e)
        {
            bool bFindChecked = false;
            {fields_loop type="3"}
            string strAllID_{field_source_name} = "";
            {/fields_loop}
            for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
            {
                CheckBox cbx = (CheckBox)GridView1.Rows[i].FindControl("CheckBox_RecID");
                if (cbx.Checked)
                {
                    {fields_loop type="3"}
                    strAllID_{field_source_name} += "{field_single_quote}" + this.GridView1.DataKeys[i].Values["{field_name}"].ToString() + "{field_single_quote},";
                    {/fields_loop}
                    bFindChecked = true;
                }
            }

            if (bFindChecked == true)
            {
                {fields_loop type="3"}
                strAllID_{field_source_name} = FypSystem.Common.StringExtend.TrimRight(strAllID_{field_source_name}, ",");
                {/fields_loop}
                string strWhere = " {fields_loop type="3" separator=" and "}[{field_name}] in (" + strAllID_{field_source_name} + ") {/fields_loop}";
                //如有上载到磁盘的文件，需先删除
                {control_style_all_check value="上载文件|上载图片" match="true" type="3"}
                DataTable tabFileName = new {fyp_namespace}.BLL.BLL_{table_source_name}().GetDataTable(strWhere);
                foreach (DataRow row in tabFileName.Rows)
                {
                    string strFileName;
                    string strFilePath;
                    FypSystem.Common.FileSys fileSys = new FileSys();
                    {fields_loop type="-1"}
                    {control_style_check value="上载文件|上载图片" match="true"}
                    strFileName = row["{field_name}"].ToString().Trim();
                    if (strFileName.Length > 0)
                    {
                        strFilePath = fileSys.GetAbsPath(strFileName);
                        System.IO.File.Delete(strFilePath);
                        //this.Response.Write(strFilePath);
                    }
                    {/control_style_check}
                    {/fields_loop}
                    //删除库中记录
                {fields_loop type="3" distinct="true"}
                    {remark}非字符串参数，转换类型{/remark}
                    {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="unequal"}
                    {field_code_datatype_name code="cs" type="3" compatible="false"} var_{field_source_name} = {field_code_datatype_name code="cs" type="3" compatible="false"}.Parse(row["{field_name}"].ToString());
                    {/value_match_check}

                    {remark}字符串参数，直接使用{/remark}
                    {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="equal"}
                    {field_code_datatype_name code="cs" type="3" compatible="false"} var_{field_source_name} = row["{field_name}"].ToString();
                    {/value_match_check}
                {/fields_loop}
                    new {fyp_namespace}.BLL.BLL_{table_source_name}().Delete({fields_loop type="3" separator=", "}var_{field_source_name}{/fields_loop});
                }
                {/control_style_all_check}
            }

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

        {batch_manage_check value="false" match="true"}
        //单条删除记录
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int i = e.RowIndex;
        {fields_loop type="3" distinct="true"}
            {remark}非字符串参数，转换类型{/remark}
            {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="unequal"}
            {field_code_datatype_name code="cs" type="3" compatible="false"} var_{field_source_name} = {field_code_datatype_name code="cs" type="3" compatible="false"}.Parse(this.GridView1.DataKeys[i].Values["USER_ID"].ToString());
            {/value_match_check}

            {remark}字符串参数，直接使用{/remark}
            {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="equal"}
            {field_code_datatype_name code="cs" type="3" compatible="false"} var_{field_source_name} = this.GridView1.DataKeys[i].Values["USER_NAME"].ToString();
            {/value_match_check}
        {/fields_loop}
            {fyp_namespace}.Model.Model_{table_source_name} model_{table_source_name} = new {fyp_namespace}.BLL.BLL_{table_source_name}().GetModel({fields_loop type="3" separator=", "}var_{field_source_name}{/fields_loop});

             //如有上载到磁盘的文件，需先删除
            string strFileName;
            string strFilePath;
            FypSystem.Common.FileSys fileSys = new FileSys();
            {fields_loop type="-1"}
            {control_style_check value="上载文件|上载图片" match="true"}
            strFileName = model_{table_source_name}.{field_source_name}.ToString().Trim();
            if (strFileName.Length > 0)
            {
                strFilePath = fileSys.GetAbsPath(strFileName);
                System.IO.File.Delete(strFilePath);
                //this.Response.Write(strFilePath);
            }
            {/control_style_check}
            {/fields_loop}
            //然后再删除记录
            new {fyp_namespace}.BLL.BLL_{table_source_name}().Delete({fields_loop type="3" separator=", "}var_{field_source_name}{/fields_loop});

            this.GridView1.EditIndex = -1;
            FillGrid();
        }
        {/batch_manage_check}
{/create_manage_check}

{remark note="说明：备用"}
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string strID = e.CommandArgument.ToString();
            string[] arrID = strID.Split(new string[] { "|||" }, StringSplitOptions.None);

            if (e.CommandName == "Modify")
            {
                this.Response.Redirect("{file_edit_name}?{fields_loop type="3" separator="&"}{control_name}=" + arrID[{i}] + "{/fields_loop}");
            }
            else if (e.CommandName == "View")
            {
                this.Response.Redirect("{file_detail_name}?{fields_loop type="3" separator="&"}{control_name}=" + arrID[{i}] + "{/fields_loop}");
            }
        }
{/remark}
    }
}