/*
'' ============================================================================================
'' 项目名称：{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;

namespace {fyp_namespace}.Web
{
    public partial class {file_detail_name type="2"} : System.Web.UI.Page
    {
        {fields_loop type="3" distinct="true"}
        {field_code_datatype_name code="cs" type="3" compatible="false"} req_{field_source_name}; {/fields_loop}

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

            if ({fields_loop type="3" separator=" && " distinct="true"}!StringExtend.IsEmpty(this.Request.QueryString["{control_name}"]){/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"}
                req_{field_source_name} = {field_code_datatype_name code="cs" type="3" compatible="false"}.Parse(this.Request.QueryString["{control_name}"]);
                {/value_match_check}

                {remark}字符串参数，直接使用{/remark}
                {value_match_check value1='{field_code_datatype_name code="cs" type="3" compatible="false"}' value2="string" extend_match="equal"}
                req_{field_source_name} = this.Request.QueryString["{control_name}"];
                {/value_match_check}
            {/fields_loop}
            }
            if ({fields_loop type="3" separator=" || " distinct="true"}StringExtend.IsEmpty(req_{field_source_name}){/fields_loop})
            {
                //如找不到指定记录，提示
                FypSystem.Common.WebPage.JsAlert(this, "未指定合法的参数！");
            }
            else if (!this.Page.IsPostBack)
            {
                Initialize();
            }
        }

        /// <summary>
        /// 读取数据库指定记录
        /// </summary>
        /// <returns></returns>
        private {fyp_namespace}.Model.Model_{table_source_name} GetModelData()
        {
            {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=", "}req_{field_source_name}{/fields_loop});

            return model_{table_source_name};
        }

        /// <summary>
        /// 导入默认值、数据
        /// </summary>
        private void Initialize()
        {
            {fyp_namespace}.Model.Model_{table_source_name} model_{table_source_name} = GetModelData();
            if (model_{table_source_name} != null)
            {
                try
                {
					string strValue;
            {fields_loop}
                    strValue = "";
                {control_style_check value="上载到库|图片到库" match="false"}
                    if (model_{table_source_name}.{field_variable} != null)
    					strValue = model_{table_source_name}.{field_variable}.ToString();
                {/control_style_check}

                {field_seltable_name_check value="不链接表" match="false"}
                    if (strValue.Length > 0)
                    {
                        {fyp_namespace}.Model.Model_{field_seltable_name} model_{field_seltable_name} = new {fyp_namespace}.BLL.BLL_{field_seltable_name}().GetModel(model_{table_source_name}.{field_variable});
                        if (model_{field_seltable_name} != null && model_{field_seltable_name}.{field_seltable_text} != null)
                            strValue = model_{field_seltable_name}.{field_seltable_text}.ToString();
                    }
                {/field_seltable_name_check}

                    {control_style_check value="日期选择" match="true"}
                    strValue = RegExp.RegMatch(@"([^\s]+)", strValue, "$1", true);{/control_style_check}

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

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

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

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

                    {field_display_style_check value="链接文件" match="true"}
                        {control_style_check value="上载到库|图片到库" match="false"}
                    strValue = "<a href='" + strValue + "'>打开文件 " + strValue + "</a>";
                        {/control_style_check}
                    {/field_display_style_check}

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

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

                    {field_display_style_check value="显示图片" match="true"}
                        {control_style_check value="上载到库|图片到库" match="false"}
                    if (strValue.Length > 0)
                        strValue = "<img src='" + strValue + "'>";
                        {/control_style_check}
                    {/field_display_style_check}

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

                    {field_display_style_check value="显示文字|前20字符" match="false"}
                    this.lab_{control_name}_Show.Text = strValue;
                    {/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"}req_{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)
        {
            {fyp_namespace}.Model.Model_{table_source_name} model_{table_source_name} = GetModelData();
            if (model_{table_source_name} != null)
            {
                strFileName = this.Server.UrlPathEncode(strFileName);
                FypSystem.Common.FileSys fileSys = new FileSys();
            {fields_loop}
                {control_style_check value="上载到库|图片到库" match="true"}
                if (strFieldName == "{field_source_name}")
                    fileSys.DownloadFileInDB(strFileName, (byte[])model_{table_source_name}.{field_variable});
                {/control_style_check}
            {/fields_loop}
            }
        }
        {/control_style_all_check}
    }
}