www.pudn.com > WorkflowDesigner.rar > ParamInfoDlg.cs, change:2007-11-21,size:6254b


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
 
namespace WorkflowDesigner 
{ 
    public partial class ParamInfoDlg : Form 
    { 
 
        private bool _isNewAppOperation; 
 
        private WfParam _param; 
 
        public WfParam Param 
        { 
            get { return _param; } 
            set { _param = value; } 
        } 
 
 
        public ParamInfoDlg(WfParam param) 
        { 
            _isNewAppOperation = false; 
            this._param = param; 
            InitializeComponent(); 
            if (_param == null) 
            { 
                _isNewAppOperation = true; 
            } 
            else 
            { 
                //赋值 
 
 
 
 
 
            } 
        } 
 
        private void buttonCancel_Click(object sender, EventArgs e) 
        { 
            this.Close(); 
        } 
 
        private void ParamInfoDlg_Load(object sender, EventArgs e) 
        { 
             
            BindType(); 
            BindBoolValue(); 
            if (!_isNewAppOperation) 
            { 
                //赋值 
                this.textBoxName.Text = this._param.Name; 
                this.comboBoxType.SelectedValue = this._param.ParamType; 
                //SetValueByType(); 
                if (this._param.ParamType == "2") 
                { 
                    this.comboBoxValue.SelectedValue = this._param.Value; 
                } 
                else 
                { 
                    this.textBoxValue.Text = this._param.Value; 
                } 
                this.textBoxRemark.Text = this._param.Remark; 
            } 
        } 
 
        private void BindType() 
        { 
            //构建DataTable 
            DataTable dt = new DataTable(); 
            dt.Columns.Add("ID", typeof(int)); 
            dt.Columns.Add("Name", typeof(String)); 
 
            DataRow dr = dt.NewRow(); 
            dr["ID"] = "0"; 
            dr["Name"] = "整型"; 
            dt.Rows.Add(dr); 
 
            dr = dt.NewRow(); 
            dr["ID"] = "1"; 
            dr["Name"] = "字符串"; 
            dt.Rows.Add(dr); 
 
            dr = dt.NewRow(); 
            dr["ID"] = "2"; 
            dr["Name"] = "布尔"; 
            dt.Rows.Add(dr); 
 
 
            this.comboBoxType.DataSource = dt; 
            this.comboBoxType.DisplayMember = "Name"; 
            this.comboBoxType.ValueMember = "ID"; 
        } 
 
        private void BindBoolValue() 
        { 
            //构建DataTable 
            DataTable dt = new DataTable(); 
            dt.Columns.Add("ID", typeof(String)); 
            dt.Columns.Add("Name", typeof(String)); 
 
            DataRow dr = dt.NewRow(); 
            dr["ID"] = "False"; 
            dr["Name"] = "否"; 
            dt.Rows.Add(dr); 
 
            dr = dt.NewRow(); 
            dr["ID"] = "True"; 
            dr["Name"] = "是"; 
            dt.Rows.Add(dr); 
 
             
 
            this.comboBoxValue.DataSource = dt; 
            this.comboBoxValue.DisplayMember = "Name"; 
            this.comboBoxValue.ValueMember = "ID"; 
        } 
        private void SetValueByType() 
        { 
            String TypeId = this.comboBoxType.SelectedValue.ToString(); 
            if (TypeId == "2") 
            { 
                this.textBoxValue.Width = 0; 
                this.textBoxValue.Visible = false; 
                this.comboBoxValue.Visible = true; 
            } 
            else 
            { 
                this.textBoxValue.Width = 124; 
                this.textBoxValue.Visible = true; 
                this.comboBoxValue.Visible = false; 
            } 
        } 
        private void comboBoxType_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            SetValueByType(); 
        } 
 
        private void buttonOk_Click(object sender, EventArgs e) 
        { 
            if (this.IsVaild()) 
            { 
                this.Save(); 
            } 
        } 
 
 
        private bool IsVaild() 
        { 
            //名称为必填 
            if (this.textBoxName.Text.Trim() == "") 
            { 
                MessageBox.Show("请填写参数名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                this.textBoxName.Focus(); 
                return false; 
            } 
            //判断数值型 
            if (this.comboBoxType.SelectedValue.ToString() == "0") 
            { 
                if (this.textBoxValue.Text != "") 
                { 
                    if (!CommFunction.IsInteger(this.textBoxValue.Text)) 
                    { 
                        MessageBox.Show("请填写整型数值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                        this.textBoxValue.Focus(); 
                        return false; 
                    } 
                } 
            } 
             
            return true; 
        } 
 
        private void Save() 
        { 
            try 
            { 
                //保存信息 
                String ParamName = this.textBoxName.Text.Trim(); 
                String type = this.comboBoxType.SelectedValue.ToString(); 
 
                String Value = ""; 
                if (type == "2") 
                { 
                    Value = this.comboBoxValue.SelectedValue.ToString(); 
                } 
                else 
                { 
                    Value = this.textBoxValue.Text; 
                } 
                String Remark = this.textBoxRemark.Text; 
                if (this._isNewAppOperation) 
                { 
                    Program.WorkflowControl.NewParam(ParamName, type, Value, Remark); 
                } 
                else 
                { 
                    Program.WorkflowControl.UpdateParam(this._param, ParamName, type, Value, Remark); 
                } 
 
                MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                this.Close(); 
            } 
            catch (Exception err) 
            { 
                MessageBox.Show(err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); 
            } 
 
        } 
 
 
    } 
}