/*
'' ============================================================================================
'' 项目名称：{fyp_title}
'' 项目版本：{fyp_version}
'' 项目描述：{fyp_description}
'' 文件名称：{file_add_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;

public partial class {file_add_name type="2"} : System.Web.UI.Page
{
    /// <summary>
    /// 当前页面是否编辑状态
    /// </summary>
    private bool bIsEdit = false;
    {fields_loop type="3" distinct="true"}
    string strReq_{field_source_name} = ""; {/fields_loop}
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = WebPage.GetConfig("fypWebName");
        {fields_loop type="3" distinct="true"}
        strReq_{field_source_name} = DBString.ConvertInSql(this.Request.QueryString["{control_name}"]); {/fields_loop}

        if ({fields_loop type="3" separator=" && " distinct="true"}!StringExtend.IsEmpty(strReq_{field_source_name}){/fields_loop})
            bIsEdit = true;

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

    /// <summary>
    /// 编辑记录时，读取数据库指定记录
    /// </summary>
    /// <returns></returns>
    {db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="false"}
    private FypSystem.DBManager.SortedItem GetRecordData(FypSystem.DBManager.Access dbManager){/db_type_check}
    {db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="true"}
    private FypSystem.DBManager.SortedItem GetRecordData(FypSystem.DBManager.SqlServer dbManager){/db_type_check}
    {
        FypSystem.DBManager.SortedItem itemCurrent = new SortedItem();
        if (bIsEdit)
        {
            //string strSql = "select {fields_loop separator=", " type="5"}[{field_name}]{/fields_loop} from [{table_name}] where {fields_loop type="3" separator=" and " distinct="true"}{field_bracket_name} = {field_single_quote}" + strReq_{field_source_name} + "{field_single_quote}{/fields_loop}";

            string strSql = "select * from [{table_name}] where {fields_loop type="3" separator=" and " distinct="true"}{field_bracket_name} = {field_single_quote}" + strReq_{field_source_name} + "{field_single_quote}{/fields_loop}";
            itemCurrent = dbManager.Read(strSql);
        }
        return itemCurrent;
    }

    /// <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}

        //默认值
        {fields_loop}
        {control_style_check value="时分秒框" match="true"}
        this.{control_name}.Text = DateTime.Now.ToString("H:mm:ss");
        {/control_style_check}
        {control_style_check value="时分框" match="true"}
        this.{control_name}.Text = DateTime.Now.ToString("H:mm");
        {/control_style_check}
        {control_style_check value="日时选择" match="true"}
        this.{control_name}.Text = DateTime.Now.ToString();
        {/control_style_check}
        {control_style_check value="日期选择" match="true"}
        this.{control_name}.Text = DateTime.Now.ToString("yyyy-MM-dd");
        {/control_style_check}
        {/fields_loop}
{db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="false"}
        using (FypSystem.DBManager.Access dbManager = new FypSystem.DBManager.Access())
{/db_type_check}
{db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="true"}
        using (FypSystem.DBManager.SqlServer dbManager = new FypSystem.DBManager.SqlServer())
{/db_type_check}
        {
{field_seltable_name_all_check value="不链接表" match="false"}
            //直接填充下拉框
{fields_loop}
    {field_seltable_name_check value="不链接表" match="false"}
            {remark note="说明："}当前字段是级联下拉框的第一级，或不是级联下拉框时，不需判断where条件{/remark}
            {field_seltable_level_check value="0|1" match="true"}
            string strSql_{field_source_name} = "select [{field_seltable_text}], [{field_seltable_value}] from [{field_seltable_name}]";
            dbManager.FillListControl(this.{control_name}, strSql_{field_source_name}, "{field_seltable_text}", "{field_seltable_value}", "{text translate="auto"}--请选择--{/text}", "");
        {/field_seltable_level_check}
    {/field_seltable_name_check}
{/fields_loop}
{/field_seltable_name_all_check}
            //编辑记录时导入数据，并设置相应属性
            if (bIsEdit)
            {
                //设置相应属性
                this.btnSubmit.Text = "{text translate="auto"}修改{/text}";

                //编辑时设置只读状态
            {fields_loop}
                {field_edit_readonly_check value="true" match="true"}
                this.{control_name}.ReadOnly = true;
                {/field_edit_readonly_check}
            {/fields_loop}

                //导入数据
                FypSystem.DBManager.SortedItem item = GetRecordData(dbManager);
                if (item.Count > 0)
                {
                    try
                    {
        {field_seltable_name_all_check value="不链接表" match="false"}
                        //根据条件填充下拉框
            {fields_loop}
                {field_seltable_name_check value="不链接表" match="false"}
                    {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 (item.ContainsKey("{field_source_name next="-1"}") && item["{field_source_name next="-1"}"].ToString().Length > 0)
                        {
                            string strWhere_{field_source_name} = "";
                            strWhere_{field_source_name} = " Where [{field_seltable_parent_id}]={get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_parent_id}"}" + item["{field_source_name next="-1"}"].ToString() + "{get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_parent_id}"}";
                            string strSql_{field_source_name} = "select [{field_seltable_text}], [{field_seltable_value}] from [{field_seltable_name}] " + strWhere_{field_source_name};
                            dbManager.FillListControl(this.{control_name}, strSql_{field_source_name}, "{field_seltable_text}", "{field_seltable_value}", "{text translate="auto"}--请选择--{/text}", "");
                        }
                        {/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 (item.ContainsKey("{field_source_name next="-1"}") && item["{field_source_name next="-1"}"].ToString().Length > 0)
                        {
                            string strWhere_{field_source_name} = "";
                            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"}"}" + item["{field_source_name next="-1"}"].ToString() + "{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();
                            strWhere_{field_source_name} = " Where [{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}"}";
                            string strSql_{field_source_name} = "select [{field_seltable_text}], [{field_seltable_value}] from [{field_seltable_name}] " + strWhere_{field_source_name};
                            dbManager.FillListControl(this.{control_name}, strSql_{field_source_name}, "{field_seltable_text}", "{field_seltable_value}", "{text translate="auto"}--请选择--{/text}", "");
                        }
                        {/value_match_check}

                    {/field_seltable_level_check}
                {/field_seltable_name_check}
            {/fields_loop}
        {/field_seltable_name_all_check}

                        //导入数据库中保存的信息
                        {fields_loop}
                        {control_style_check value="密码框|隐藏域|时分框|时分秒框|日时选择|日期选择|上载文件|上载到库|上载图片|图片到库" match="false"}
                        this.{control_name}.Text = item["{field_source_name}"].ToString();
                        {/control_style_check}

                        {control_style_check value="隐藏域" match="true"}
                        this.{control_name}.Value = item["{field_source_name}"].ToString();
                        {/control_style_check}

                        {control_style_check value="上载文件|上载图片" match="true"}
                        this.{control_name}.ToolTip = item["{field_source_name}"].ToString();
                        if (item["{field_source_name}"].ToString().Length > 0)
                        {
                            this.lab_{control_name}_file.Text = "<br><a href='" + item["{field_source_name}"].ToString() + "' target='_blank'> >> 查看 " + item["{field_source_name}"].ToString() + "</a>";
                            this.btn_{control_name}_file_del.Text = " >> 删除文件";
                            this.btn_{control_name}_file_del.CommandArgument = item["{field_source_name}"].ToString();
                        }
                        {/control_style_check}
                        {control_style_check value="上载到库|图片到库" match="true"}
                        if (!FypSystem.Common.StringExtend.IsEmpty(item["{field_source_name}"]))
                        {
                            this.btn_{control_name}_file.Text = "<br> >> 下载文件";
                            this.btn_{control_name}_file_del.Text = " >> 删除文件";
                        }
                        {/control_style_check}

                        {control_style_check value="密码框" match="true"}
                        //密码框
                        this.{control_name}.Attributes.Add("value", item["{field_source_name}"].ToString());
                        {/control_style_check}

                        {control_style_check value="时分框" match="true"}
                        //显示时分
                        if (item["{field_source_name}"].ToString().Length > 0)
                            this.{control_name}.Text = FypSystem.Common.StringExtend.FormatDateTime(item["{field_source_name}"], "hh:mm");
                        {/control_style_check}
                        {control_style_check value="时分秒框" match="true"}
                        //显示时分秒
                        if (item["{field_source_name}"].ToString().Length > 0)
                            this.{control_name}.Text = FypSystem.Common.StringExtend.FormatDateTime(item["{field_source_name}"], "hh:mm:ss");
                        {/control_style_check}
                        {control_style_check value="日时选择" match="true"}
                        //显示日期时间
                        if (item["{field_source_name}"].ToString().Length > 0)
                            this.{control_name}.Text = FypSystem.Common.StringExtend.FormatDateTime(item["{field_source_name}"], "yyyy-MM-dd hh:mm:ss");
                        {/control_style_check}
                        {control_style_check value="日期选择" match="true"}
                        //显示日期
                        if (item["{field_source_name}"].ToString().Length > 0)
                            this.{control_name}.Text = FypSystem.Common.StringExtend.FormatDateTime(item["{field_source_name}"], "yyyy-MM-dd");
                        {/control_style_check}

                        {field_input_again_check value="true" match="true"}
                        //要求两次输入
                        {control_style_check value="密码框|时分框|时分秒框|日时选择|日期选择" match="false"}
                        this.{control_name}_again.Text = item["{field_source_name}"].ToString();
                        {/control_style_check}

                        {control_style_check value="密码框" match="true"}
                        //密码框
                        this.{control_name}_again.Attributes.Add("value", item["{field_source_name}"].ToString());
                        {/control_style_check}
                        {/field_input_again_check}
                        {/fields_loop}
                    }
                    catch (System.Exception err)
                    {
                        FypSystem.Common.WebPage.JsAlert(this, err.Message);
                    }
                }
                else
                {
                    //找不到指定记录时
                    FypSystem.Common.WebPage.JsAlert(this, "未找到指定记录！");
                }
            }
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SaveData();
    }

    /// <summary>
    /// 保存数据
    /// </summary>
    private void SaveData()
    {
        bool bSta = false;
        string strMsg = "";
        string strUrl = this.Request.Url.ToString();

{remark}校验码{/remark}
{valid_code_check value="true" match="true"}
        if (FypSystem.Common.StringExtend.NullToEmptyStr(Session["valid_code"]).ToLower() != this.ctrl_ValidCode.Text.ToLower())
        {
            strMsg = "{text translate="auto"}输入的校验码不正确。{/text}";
        }
        else {/valid_code_check}if (this.Page.IsValid)
        {
{db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="false"}
            using (FypSystem.DBManager.Access dbManager = new FypSystem.DBManager.Access())
{/db_type_check}
{db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="true"}
            using (FypSystem.DBManager.SqlServer dbManager = new FypSystem.DBManager.SqlServer())
{/db_type_check}
            {
                try
                {
{control_style_all_check value="上载到库|上载文件|上载图片|图片到库|批量上载" match="true"}
                    //读取保存的记录信息
                    FypSystem.DBManager.SortedItem itemOld = GetRecordData(dbManager);
                    //读取保存上载文件的设置
                    FypSystem.Common.FileSys fileSys = new FypSystem.Common.FileSys();
                    string strSavePath = WebPage.GetConfig("fypSavePath");
                    string strWaterMarkPath = WebPage.GetConfig("fypWaterMarkPath");
                    string strAllowExt = WebPage.GetConfig("fypAllowExt");
                    int iMaxSize = Convert.ToInt32(WebPage.GetConfig("fypMaxSize"));
{/control_style_all_check}

{remark}使用参数输入数据------------------------------------------------------------------{/remark} 
{data_transmit_type_check value="使用参数" match="true"}
                    FypSystem.DBManager.SortedItem item = new SortedItem();
                    {fields_loop}
                    {control_style_check value="上载到库|上载文件|上载图片|图片到库" match="false"}
                    item["{field_source_name}"] = this.{control_name}.Text;
                    {/control_style_check}

                    {control_style_check value="上载文件|上载图片" match="true"}
                    //选择文件后才进行上载
                    if (this.{control_name}.FileName.Length > 0)
                    {
                        //使用原文件名上载
                        //item["{field_source_name}"] = strSavePath + this.{control_name}.FileName;
                        //使用系统生成的新文件名
                        item["{field_source_name}"] = strSavePath + MathExtend.NumToStrJZ("datetime", 36) + System.IO.Path.GetExtension(this.{control_name}.FileName);
                        if (bIsEdit)
                        {
                            //保存文件时，如已经上载文件，则使用旧文件名
                            string str{field_source_name}_old = itemOld["{field_source_name}"].ToString();
                            if (str{field_source_name}_old.Length > 0)
                            {
                                item["{field_source_name}"] = fileSys.RemoveExtName(str{field_source_name}_old) + System.IO.Path.GetExtension(this.{control_name}.FileName);
                                System.IO.File.Delete(fileSys.GetAbsPath(str{field_source_name}_old));
                            }
                        }
                        {control_style_check value="上载文件" match="true"}
                        //上载文件到服务器
                        fileSys.UploadFile(this.{control_name}, false, item["{field_source_name}"].ToString(), strAllowExt, iMaxSize, true);
                        {/control_style_check}
                        {control_style_check value="上载图片" match="true"}
                        //上载图片到服务器，并添加水印
                        fileSys.UploadFile(this.{control_name}, false, item["{field_source_name}"].ToString(), strAllowExt, iMaxSize, true, true, strWaterMarkPath, 9);
                        {/control_style_check}
                    }
                    {/control_style_check}

                    {control_style_check value="上载到库" match="true"}
                    //上载文件到数据库中
                    if (this.{control_name}.FileBytes.Length > 0)
                        item["{field_source_name}"] = this.{control_name}.FileBytes;
                    {/control_style_check}
                    {control_style_check value="图片到库" match="true"}
                    //上载图片到数据库中，并添加水印
                    if (this.{control_name}.FileBytes.Length > 0)
                    {
                        FypSystem.Common.ImageExtend image = new ImageExtend();
                        item["{field_source_name}"] = image.AddWaterMark(strWaterMarkPath, 9, 0.5f, this.{control_name}.FileBytes, this.{control_name}.FileName);
                    }
                    {/control_style_check}
                    {/fields_loop}

                    if (bIsEdit)
                    {
                        dbManager.Update(item, "{table_name}", "{fields_loop type="3" separator=" and " distinct="true"}{field_bracket_name} = {field_single_quote}" + strReq_{field_source_name} + "{field_single_quote}{/fields_loop}");
                    }
                    else
                    {
                        dbManager.Insert(item, "{table_name}");
                    }
{/data_transmit_type_check}

{remark}使用存储过程输入数据------------------------------------------------------------------{/remark}
{data_transmit_type_check value="使用存储过程" match="true"}
                    System.Data.SqlClient.SqlParameter[] sqlParams = new System.Data.SqlClient.SqlParameter[{fields_count type="5" distinct="false"}];
                    //记录未改变时的主键值，用于在修改记录时，传入检索参数值
                    {fields_loop type="3"}
                    sqlParams[{i}] = new System.Data.SqlClient.SqlParameter("@{field_source_name}_PKValueIn", {field_sqldbtype_name});
                    sqlParams[{i}].Value = strReq_{field_source_name};
                    {/fields_loop}

                    //需保存字段信息的值
                    {fields_loop}
                    sqlParams[{i from="{fields_count type='3'}"}] = new System.Data.SqlClient.SqlParameter("@{field_source_name}", {field_sqldbtype_name});
                    {control_style_check value="上载到库|上载文件|上载图片|图片到库" match="false"}
                    sqlParams[{i from="{fields_count type='3'}"}].Value = this.{control_name}.Text;
                    {/control_style_check}

                    {control_style_check value="上载文件|上载图片" match="true"}
                    //编辑文件时先使用字段的原值
                    if (bIsEdit)
                        sqlParams[{i from="{fields_count type='3'}"}].Value = itemOld["FileLink"].ToString();

                    //选择文件后才进行上载
                    if (this.{control_name}.FileName.Trim().Length > 0)
                    {
                        string str{field_source_name}_new = "";
                        //使用原文件名上载
                        //str{field_source_name}_new = strSavePath + this.{control_name}.FileName;
                        //使用系统生成的新文件名
                        str{field_source_name}_new = strSavePath + MathExtend.NumToStrJZ("datetime", 36) + System.IO.Path.GetExtension(this.{control_name}.FileName);
                        if (bIsEdit)
                        {
                            //保存文件时，如已经上载文件，则使用旧文件名
                            string str{field_source_name}_old = itemOld["{field_source_name}"].ToString();
                            if (str{field_source_name}_old.Length > 0)
                            {
                                str{field_source_name}_new = fileSys.RemoveExtName(str{field_source_name}_old) + System.IO.Path.GetExtension(this.{control_name}.FileName);
                                System.IO.File.Delete(fileSys.GetAbsPath(str{field_source_name}_old));
                            }
                        }
                        {control_style_check value="上载文件" match="true"}
                        //上载文件到服务器
                        fileSys.UploadFile(this.{control_name}, false, str{field_source_name}_new, strAllowExt, iMaxSize, true);
                        {/control_style_check}

                        {control_style_check value="上载图片" match="true"}
                        //上载图片到服务器，并添加水印
                        fileSys.UploadFile(this.{control_name}, false, str{field_source_name}_new, strAllowExt, iMaxSize, true, true, strWaterMarkPath, 9);
                        {/control_style_check}

                        sqlParams[{i from="{fields_count type='3'}"}].Value = str{field_source_name}_new;
                    }
                    {/control_style_check}

                    {control_style_check value="上载到库" match="true"}
                    //上载文件到数据库中
                    sqlParams[{i from="{fields_count type='3'}"}].Value = this.{control_name}.FileBytes;
                    {/control_style_check}
                    {control_style_check value="图片到库" match="true"}
                    //上载图片到数据库中，并添加水印
                    if (this.{control_name}.FileBytes.Length > 0)
                    {
                        FypSystem.Common.ImageExtend image = new ImageExtend();
                        sqlParams[{i from="{fields_count type='3'}"}].Value = image.AddWaterMark(strWaterMarkPath, 9, 0.5f, this.{control_name}.FileBytes, this.{control_name}.FileName);
                    }
                    {/control_style_check}
                    {/fields_loop}

                    dbManager.ExecStoredProcedure("P_{table_source_name}_AddEdit", sqlParams);
{/data_transmit_type_check}

                    strMsg = "{text translate="auto"}保存数据成功{/text}";
                    bSta = true;
                }
                catch (System.Exception err)
                {
                    strMsg = "{text translate="auto"}保存数据时出错：{/text}" + err.Message;
                }
            }
        }
        else
        {
            strMsg = "{text translate="auto"}输入信息不正确{/text}";
        }
        if (bSta)
            FypSystem.Common.WebPage.JsRun(this, "ShowMsg(\"" + FypSystem.Common.WebPage.FormatJsStr(strMsg) + "\");try{window.opener.location.reload(); window.close();}catch(e){GoUrl('" + strUrl + "')}");
        else
            FypSystem.Common.WebPage.JsAlert(this, strMsg, "");
    }

{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)
        {
{db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="false"}
            using (FypSystem.DBManager.Access dbManager = new FypSystem.DBManager.Access())
{/db_type_check}
{db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="true"}
            using (FypSystem.DBManager.SqlServer dbManager = new FypSystem.DBManager.SqlServer())
{/db_type_check}
            {
                string strWhere = "";
                {remark note="说明："}如ID与value不同，需通过value获取ID，如相同，可直接使用上句{/remark}
                {value_match_check value1="{field_seltable_id}" value2="{field_seltable_value}" extend_match="equal"}
                strWhere = " Where [{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();
                strWhere = " Where [{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}

                dbManager.FillListControl(this.{control_name next="1"}, "select [{field_seltable_text next="1"}], [{field_seltable_value next="1"}] from [{field_seltable_name next="1"}] " + strWhere, "{field_seltable_text next="1"}", "{field_seltable_value next="1"}", "{text translate="auto"}--请选择--{/text}", "");
            }
        }
    }
{/field_seltable_level_check}
{/field_seltable_level_check}
{control_style_check value="上载到库|图片到库" match="true"}
    protected void btn_{control_name}_file_Click(object sender, EventArgs e)
    {
        DownLoadFile("{control_name}_" + {fields_loop type="3" separator=' + "_" + ' distinct="true"}strReq_{field_source_name}{/fields_loop}, "{field_name}");
    }

    protected void btn_{control_name}_file_del_Click(object sender, EventArgs e)
    {
        DelFile("{field_name}", "");
    }
{/control_style_check}
{control_style_check value="上载文件|上载图片" match="true"}
    protected void btn_{control_name}_file_del_Command(object sender, CommandEventArgs e)
    {
        DelFile("{field_name}", e.CommandArgument.ToString());
    }
{/control_style_check}
{/fields_loop}

{control_style_all_check value="上载文件|上载到库|上载图片|图片到库" match="true" type="1"}
    /// <summary>
    /// 删除保存于数据库或磁盘文件
    /// </summary>
    /// <param name="strFieldName">保存文件名或文件字节信息的字段名</param>
    /// <param name="strFileName">文件名，如文件保存于数据库，传入空值</param>
    private void DelFile(string strFieldName, string strFileName)
    {
        string strMsg = "";
        string strUrl = "";
        string strSql = "Update [{table_name}] set [" + strFieldName + "] = null where {fields_loop type="3" separator=" and " distinct="true"}{field_bracket_name} = {field_single_quote}" + strReq_{field_source_name} + "{field_single_quote}{/fields_loop}";
        try
        {
            if (strFileName.Length > 0)
            {
                FypSystem.Common.FileSys fileSys = new FileSys();
                string strFilePath = fileSys.GetAbsPath(strFileName);
                System.IO.File.Delete(strFilePath);
            }
{db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="false"}
            using (FypSystem.DBManager.Access dbManager = new FypSystem.DBManager.Access())
{/db_type_check}
{db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="true"}
            using (FypSystem.DBManager.SqlServer dbManager = new FypSystem.DBManager.SqlServer())
{/db_type_check}
            {
                dbManager.ExecNonQuery(strSql);
            }
            strMsg = "{text translate="auto"}成功删除文件{/text}";
            strUrl = this.Request.Url.ToString();
        }
        catch (System.Exception err)
        {
            strMsg = "{text translate="auto"}出错提示：{/text}" + err.Message;
        }
        FypSystem.Common.WebPage.JsAlert(this, strMsg, strUrl);
    }
{/control_style_all_check}
{control_style_all_check value="上载到库|图片到库" match="true" type="1"}
    /// <summary>
    /// 下载保存于数据库中的文件
    /// </summary>
    /// <param name="strFileName">指定的下载文件名</param>
    /// <param name="strFieldName">字段名</param>
    private void DownLoadFile(string strFileName, string strFieldName)
    {
        {db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="false"}
        using (FypSystem.DBManager.Access dbManager = new FypSystem.DBManager.Access())
        {/db_type_check}
        {db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="true"}
        using (FypSystem.DBManager.SqlServer dbManager = new FypSystem.DBManager.SqlServer())
        {/db_type_check}
        {
            FypSystem.DBManager.SortedItem itemOld = GetRecordData(dbManager);
            if (itemOld.Count > 0)
            {
                strFileName = this.Server.UrlPathEncode(strFileName);
                FypSystem.Common.FileSys fileSys = new FileSys();
                fileSys.DownloadFileInDB(strFileName, (byte[])itemOld[strFieldName]);
            }
        }
    }
{/control_style_all_check}
}