/*
'' ============================================================================================
'' 项目名称：{fyp_title}
'' 项目版本：{fyp_version}
'' 项目描述：{fyp_description}
'' 文件名称：{file_detail_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_detail_name type="2"} : System.Web.UI.Page
{
    {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} = this.Request.QueryString["{control_name}"]; {/fields_loop}

        if ({fields_loop type="3" separator=" || " distinct="true"}StringExtend.IsEmpty(strReq_{field_source_name}){/fields_loop})
        {
            //找不到指定记录时
            FypSystem.Common.WebPage.JsAlert(this, "未指定合法的参数！");
        }
        else 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();
        //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()
    {
{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 strSql = "";
            FypSystem.DBManager.SortedItem item = GetRecordData(dbManager);
            if (item.Count > 0)
            {
                try
                {
            {fields_loop}
                {field_seltable_name_check value="不链接表" match="false"}
                    if (item["{field_name}"].ToString().Length > 0)
                    {
                        strSql = "select [{field_seltable_text}] 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}"}" + item["{field_name}"].ToString() + "{get_table_field_settings tag_name="field_single_quote" table="{field_seltable_name}" field="{field_seltable_value}"}";
                        if (dbManager.Read(strSql).Count > 0)
                        {
                            string str_{field_source_name} = dbManager.Read(strSql)["{field_seltable_text}"].ToString();
                            item["{field_name}"] = WebString.HtmlEncodeExtend(str_{field_source_name});
                        }
                    }
                {/field_seltable_name_check}

                    {control_style_check value="日时选择" match="true"}
                    item["{field_name}"] = FypSystem.Common.StringExtend.FormatDateTime(item["{field_name}"], "yyyy-MM-dd HH:mm:ss");{/control_style_check}

                    {control_style_check value="日期选择" match="true"}
                    item["{field_name}"] = FypSystem.Common.StringExtend.FormatDateTime(item["{field_name}"], "yyyy-MM-dd");{/control_style_check}

                    {control_style_check value="时分框" match="true"}
                    item["{field_name}"] = FypSystem.Common.StringExtend.FormatDateTime(item["{field_name}"], "HH:mm");{/control_style_check}

                    {control_style_check value="时分秒框" match="true"}
                    item["{field_name}"] = FypSystem.Common.StringExtend.FormatDateTime(item["{field_name}"], "HH:mm:ss");{/control_style_check}

                    {control_style_check value="上载到库|图片到库" match="true"}
                    this.lab_{control_name}_Show.Visible = false;
                    if (FypSystem.Common.StringExtend.IsEmpty(item["{field_name}"]))
                        this.btn_{control_name}_file.Visible = false;
                    else
                        item["{field_name}"] = "";
                    {/control_style_check}

                    {field_display_style_check value="前20字符" match="true"}
                    item["{field_name}"] = StringExtend.Left(item["{field_name}"].ToString(), 20);{/field_display_style_check}

                    {field_display_style_check value="链接文件" match="true"}{control_style_check value="上载到库|图片到库" match="false"}
                    item["{field_name}"] = "<a href='" + item["{field_name}"].ToString() + "'>打开文件 " + item["{field_name}"].ToString() + "</a>";{/control_style_check}{/field_display_style_check}

                    {field_display_style_check value="文本框" match="true"}
                    item["{field_name}"] = "<input value='" + item["{field_name}"].ToString() + "'>";{/field_display_style_check}

                    {field_display_style_check value="文本域" match="true"}
                    item["{field_name}"] = "<textarea>" + item["{field_name}"].ToString() + "</textarea>";{/field_display_style_check}

                    {field_display_style_check value="显示图片" match="true"}
                    if (item["{field_name}"].ToString().Length > 0)
                        item["{field_name}"] = "<img src='" + item["{field_name}"].ToString() + "'>";{/field_display_style_check}

                    {remark}如以文本方式输出，则进行HTML编码，否则使用原义字符{/remark}
                    {field_display_style_check value="显示文字|前20字符" match="true"}
                    this.lab_{control_name}_Show.Text = WebString.HtmlEncodeExtend(item["{field_name}"].ToString());
                    {/field_display_style_check}

                    {field_display_style_check value="显示文字|前20字符" match="false"}
                    this.lab_{control_name}_Show.Text = item["{field_name}"].ToString();
                    {/field_display_style_check}
            {/fields_loop}
                }
                catch (System.Exception err)
                {
                    FypSystem.Common.WebPage.JsAlert(this, err.Message);
                }
            }
            else
            {
                //找不到指定记录时
                FypSystem.Common.WebPage.JsAlert(this, "未找到指定记录！");
            }
        }
    }

    {fields_loop}
    {control_style_check value="上载到库|图片到库" match="true"}
    protected void btn_{control_name}_file_Click(object sender, EventArgs e)
    {
        DownLoadFile("{field_source_name}" + {fields_loop type="3" separator=' + "_" + ' distinct="true"}strReq_{field_source_name}{/fields_loop}, "{field_name}");
    }
    {/control_style_check}
    {/fields_loop}

    {control_style_all_check value="上载到库|图片到库" match="true" type="1"}
    //下载文件
    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)
            {
                FypSystem.Common.FileSys fileSys = new FileSys();
                fileSys.DownloadFileInDB(strFileName, (byte[])itemOld[strFieldName]);
            }
        }
    }
    {/control_style_all_check}
}