/*
'' ============================================================================================
'' 项目名称：{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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using FypSystem.Common;
using FypSystem.DBManager;

namespace {fyp_namespace}
{
    public partial class {file_add_name type="2"} : Form
    {
        /// <summary>
        /// 当前页面是否编辑状态
        /// </summary>
        private bool bIsEdit = false;
        {fields_loop type="3" distinct="true"}
        string strReq_{field_source_name} = ""; {/fields_loop}

        public {file_add_name type="2"}()
        {
            Initialize();
        }

        public {file_add_name type="2"}({fields_loop type="3" separator=", "}string str{field_source_name}{/fields_loop})
        {
            bIsEdit = true;
            {fields_loop type="3" distinct="true"}
            strReq_{field_source_name} = DBString.ConvertInSql(str{field_source_name}); {/fields_loop}

            Initialize();
            //MessageBox.Show({fields_loop type="3" separator=' + "" + '}str{field_source_name}{/fields_loop});
        }

        /// <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);

                string strSql = "select * from [{table_name}] where {fields_loop type="3" separator=" and "}[{field_name}] = @{field_source_name}{/fields_loop}";
                {db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="false"}
                System.Data.OleDb.OleDbParameter[] parameters = new System.Data.OleDb.OleDbParameter[{fields_count type="3"}];
                {fields_loop type="3"}
                parameters[{i}] = new System.Data.OleDb.OleDbParameter("@{field_source_name}", strReq_{field_source_name});{/fields_loop}
				{/db_type_check}
                {db_type_check value="sqlserver|sqlserver2005|sqlserver2008" match="true"}
                System.Data.SqlClient.SqlParameter[] parameters = new System.Data.SqlClient.SqlParameter[{fields_count type="3"}];
                {fields_loop type="3"}
                parameters[{i}] = new System.Data.SqlClient.SqlParameter("@{field_source_name}", strReq_{field_source_name});{/fields_loop}
				{/db_type_check}
                itemCurrent = dbManager.Read(strSql, parameters);
            }
            return itemCurrent;
        }

        /// <summary>
        /// 导入默认值、数据
        /// </summary>
        private void Initialize()
        {
            InitializeComponent();
            this.Text += " - " + FypSystem.Common.WebPage.GetConfig("fypAppName");

            //默认值
            {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}", "--请选择--", "");
                {/field_seltable_level_check}
            {/field_seltable_name_check}
        {/fields_loop}
    {/field_seltable_name_all_check}
                //编辑记录时导入数据，并设置相应属性
                if (bIsEdit)
                {
                    //设置相应属性
                    this.btn_Submit.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}", "--请选择--", "");
                            }
                            {/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}", "--请选择--", "");
                            }
                            {/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}.SelectedValue = item["{field_source_name}"].ToString();
                            {/control_style_check}

                            {control_style_check value="上载文件|上载图片" match="true"}
                            if (item["{field_source_name}"].ToString().Length > 0)
                            {
                                //this.lab_{control_name}_file.Text = "查看 " + item["{field_source_name}"].ToString() + "";
                                //this.btn_{control_name}_file_del.Text = " >> 删除文件";
                            }
                            {/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"}
                            //显示时分
                            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="true"}
                            this.{control_name}_again.Text = item["{field_source_name}"].ToString();
                            {/control_style_check}
                            {/field_input_again_check}
                            {/fields_loop}
                        }
                        catch (System.Exception err)
                        {
                            MessageBox.Show(err.Message, "出错提示：");
                        }
                    }
                    else
                    {
                        //找不到指定记录时
                        MessageBox.Show("未找到指定记录！", "出错提示：");
                    }
                }
            }
        }

        private void btn_Submit_Click(object sender, EventArgs e)
        {
            SaveData();
        }

        #region 检测输入数据
        {fields_loop}
        private void {control_name}_Validated(object sender, EventArgs e)
        {
            CheckInputData_{field_source_name}();
        }

        private bool CheckInputData_{field_source_name}()
        {
            bool bValue = true;
            this.errorProvider.SetError(this.label_{field_source_name}, "");
            {control_style_check value="下拉列表|单选列表|多选列表" match="false"}
            string str{field_source_name} = this.{control_name}.Text;
            {/control_style_check}
            {control_style_check value="下拉列表|单选列表|多选列表" match="true"}
            string str{field_source_name} = "";
            if (this.{control_name}.SelectedValue != null)
                str{field_source_name} = this.{control_name}.SelectedValue.ToString();
            {/control_style_check}

            {field_mininput_check value="必填字段" match="true"}
            if (str{field_source_name}.Length == 0)
            {
                this.errorProvider.SetError(this.label_{field_source_name}, "{text translate="auto"}不允许为空值{/text}");
                bValue = false;
            }
            {/field_mininput_check}

            if (str{field_source_name}.Length < {field_minlength} || str{field_source_name}.Length > {field_maxlength})
            {
                this.errorProvider.SetError(this.label_{field_source_name}, "{text translate="auto"}所输入 [{field_caption translate="auto"}] 的内容有误：值必须为{field_minlength}-{field_maxlength}个字符{/text}");
                bValue = false;
            }

            {field_allow_text_type_check value="不检测" match="false"}
            if (!FypSystem.Common.RegExp.RegCheck(@"{replace find_str1='"' replace_str1="&quot;"}{field_allow_text_type_regex}{/replace}", str{field_source_name}))
            {
                this.errorProvider.SetError(this.label_{field_source_name}, "{text translate="auto"}所输入 [{field_caption translate="auto"}] 的内容有误：{field_allow_text_type_desc}{/text}");
                bValue = false;
            }
            {/field_allow_text_type_check}

            return bValue;
        }
		

        {remark}两次输入设置，仅文本框允许两次输入{/remark}
        {field_input_again_check value="true" match="true"}
        {control_style_check value="文本框|密码框" match="true"}
        private void {control_name}_again_Validated(object sender, EventArgs e)
        {
            CheckInputData_again_{field_source_name}();
        }

        private bool CheckInputData_again_{field_source_name}()
        {
            bool bValue = true;
            this.errorProvider.SetError(this.label_{field_source_name}_again, "");
            {control_style_check value="下拉列表|单选列表|多选列表" match="false"}
            string str{field_source_name} = this.{control_name}_again.Text;
            {/control_style_check}
            {control_style_check value="下拉列表|单选列表|多选列表" match="true"}
            string str{field_source_name} = "";
            if (this.{control_name}_again.SelectedValue != null)
                str{field_source_name} = this.{control_name}_again.SelectedValue.ToString();
            {/control_style_check}

            {field_mininput_check value="必填字段" match="true"}
            if (str{field_source_name}.Length == 0)
            {
                this.errorProvider.SetError(this.label_{field_source_name}_again, "{text translate="auto"}不允许为空值{/text}");
                bValue = false;
            }
            {/field_mininput_check}

            if (str{field_source_name}.Length < {field_minlength} || str{field_source_name}.Length > {field_maxlength})
            {
                this.errorProvider.SetError(this.label_{field_source_name}_again, "{text translate="auto"}再次输入 [{field_caption translate="auto"}] 的内容有误：值必须为{field_minlength}-{field_maxlength}个字符{/text}");
                bValue = false;
            }

            {field_allow_text_type_check value="不检测" match="false"}
            if (!FypSystem.Common.RegExp.RegCheck(@"{replace find_str1='"' replace_str1="&quot;"}{field_allow_text_type_regex}{/replace}", str{field_source_name}))
            {
                this.errorProvider.SetError(this.label_{field_source_name}_again, "{text translate="auto"}再次输入 [{field_caption translate="auto"}] 的内容有误：{field_allow_text_type_desc}{/text}");
                bValue = false;
            }
            {/field_allow_text_type_check}

            return bValue;
        }
        {/control_style_check}
        {/field_input_again_check}
        {/fields_loop}

        /// <summary>
        /// 检测输入数据的正确性
        /// </summary>
        /// <returns></returns>
        private bool CheckInputData()
        { 
            return {fields_loop separator=" && "}CheckInputData_{field_source_name}(){field_input_again_check value="true" match="true"}{control_style_check value="文本框|密码框" match="true"} && CheckInputData_again_{field_source_name}(){/control_style_check}{/field_input_again_check}{/fields_loop};
        }
        #endregion 检测输入数据

        /// <summary>
        /// 保存数据
        /// </summary>
        private void SaveData()
        {
            bool bSaveSta = false;
            string strMsg = "";
            if (CheckInputData())
            {
    {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"}
                        item["{field_source_name}"] = this.{control_name}.SelectedValue;
                        {/control_style_check}
                        
                        {control_style_check value="上载文件|上载图片" match="true"}
                        //选择文件后才进行上载
                        if (this.{control_name}.Text.Length > 0 && this.{control_name}.Text.IndexOf(":\\") > 0)
                        {
                            //使用原文件名上载
                            //item["{field_source_name}"] = strSavePath + this.{control_name}.Text;
                            //使用系统生成的新文件名
                            item["{field_source_name}"] = strSavePath + MathExtend.NumToStrJZ("datetime", 36) + System.IO.Path.GetExtension(this.{control_name}.Text);
                            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}.Text);
                                    System.IO.File.Delete(fileSys.GetAbsPath(str{field_source_name}_old));
                                }
                            }
                            {control_style_check value="上载文件" match="true"}
                            //上载文件到服务器
                            fileSys.UploadFile(this.{control_name}.Text, false, item["{field_source_name}"].ToString(), strAllowExt, iMaxSize, true);
                            {/control_style_check}
                            {control_style_check value="上载图片" match="true"}
                            //上载图片到服务器，并添加水印
                            fileSys.UploadFile(this.{control_name}.Text, 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 (System.IO.File.Exists(this.{control_name}.Text))
                        {
                            System.IO.FileStream fileStream_{field_source_name} = new System.IO.FileStream(this.{control_name}.Text, System.IO.FileMode.Open);
                            byte[] byteFile_{field_source_name} = new byte[Convert.ToInt32(fileStream_{field_source_name}.Length)];
                            fileStream_{field_source_name}.Read(byteFile_{field_source_name}, 0, Convert.ToInt32(fileStream_{field_source_name}.Length));
                            {control_style_check value="上载到库|图片到库" match="true"}
                            //上载文件到数据库中
                            if (byteFile_{field_source_name}.Length > 0)
                                item["{field_source_name}"] = byteFile_{field_source_name};
						    {/control_style_check}
						    {control_style_check value="图片到库" match="true"}
						    //上载图片到数据库中，并添加水印
                            if (byteFile_{field_source_name}.Length > 0)
                            {
                                FypSystem.Common.ImageExtend image = new ImageExtend();
                                item["{field_source_name}"] = image.AddWaterMark(strWaterMarkPath, 9, 0.5f, byteFile_{field_source_name}, this.{control_name}.Text);
                            }
                            {/control_style_check}
                        }
                        {/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 (this.{control_name}.Text.Length > 0 && this.{control_name}.Text.IndexOf(":\\") > 0)
                        {
                            string str{field_source_name}_new = "";
                            //使用原文件名上载
                            //str{field_source_name}_new = strSavePath + this.{control_name}.Text;
                            //使用系统生成的新文件名
                            str{field_source_name}_new = strSavePath + MathExtend.NumToStrJZ("datetime", 36) + System.IO.Path.GetExtension(this.{control_name}.Text);
                            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}.Text);
                                    System.IO.File.Delete(fileSys.GetAbsPath(str{field_source_name}_old));
                                }
                            }
                            {control_style_check value="上载文件" match="true"}
                            //上载文件到服务器
                            fileSys.UploadFile(this.{control_name}.Text, false, str{field_source_name}_new, strAllowExt, iMaxSize, true);
                            {/control_style_check}
                            {control_style_check value="上载图片" match="true"}
                            //上载图片到服务器，并添加水印
                            fileSys.UploadFile(this.{control_name}.Text, false, str{field_source_name}_new, strAllowExt, iMaxSize, true, true, strWaterMarkPath, 9);
                            sqlParams[{i from="{fields_count type='3'}"}].Value = str{field_source_name}_new;
                            {/control_style_check}
                        }
                        {/control_style_check}

                        {control_style_check value="上载到库|图片到库" match="true"}
                        if (System.IO.File.Exists(this.{control_name}.Text))
                        {
                            System.IO.FileStream fileStream_{field_source_name} = new System.IO.FileStream(this.{control_name}.Text, System.IO.FileMode.Open);
                            byte[] byteFile_{field_source_name} = new byte[Convert.ToInt32(fileStream_{field_source_name}.Length)];
                            fileStream_{field_source_name}.Read(byteFile_{field_source_name}, 0, Convert.ToInt32(fileStream_{field_source_name}.Length));
                            {control_style_check value="上载到库|图片到库" match="true"}
                            //上载文件到数据库中
                            if (byteFile_{field_source_name}.Length > 0)
                                sqlParams[{i from="{fields_count type='3'}"}].Value = byteFile_{field_source_name};
						    {/control_style_check}
						    {control_style_check value="图片到库" match="true"}
						    //上载图片到数据库中，并添加水印
                            if (byteFile_{field_source_name}.Length > 0)
                            {
                                FypSystem.Common.ImageExtend image = new ImageExtend();
                                sqlParams[{i from="{fields_count type='3'}"}].Value = image.AddWaterMark(strWaterMarkPath, 9, 0.5f, byteFile_{field_source_name}, this.{control_name}.Text);
                            }
                            {/control_style_check}
                        }
                        {/control_style_check}
                        {/fields_loop}

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

                        strMsg = "保存数据成功";
                        bSaveSta = true;
                    }
                    catch (System.Exception err)
                    {
                        strMsg = "保存数据时出错：" + err.Message;
                    }
                }
            }
            else
            {
                strMsg = "输入信息不正确";
            }

            if (strMsg.Length > 0)
                MessageBox.Show(strMsg, "出错提示：");

            if (bSaveSta)
            {
                (({file_search_name type="2"})this.Owner).FillGrid();
                this.Close();
            }
        }

    {fields_loop}
        {remark note="说明："}为级联菜单的非最后一级菜单时的生成代码{/remark}
        {field_seltable_level_check value="0|null" match="false"}
        {field_seltable_level_check value="0|null" match="false" next="1"}
        private void {control_name}_SelectedIndexChanged(object sender, EventArgs e)
        {
            //填充下拉框
            if (this.{control_name}.SelectedValue.ToString().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"}", "--请选择--", "");
                }
            }
        }
        {/field_seltable_level_check}
        {/field_seltable_level_check}

        {control_style_check value="上载到库|上载文件|图片到库|上载图片" match="true"}
        private void btn_SelectFile_{field_source_name}_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog.ShowDialog(this) == DialogResult.OK)
                this.{control_name}.Text = this.openFileDialog.FileName;
        }
        {/control_style_check}

    {/fields_loop}
    }
}