⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 relatefielddefinition.cs

📁 EpiInfo 开源的导航系统远程序,不知道在哪里下的了,分享一下,有兴趣的
💻 CS
字号:
#region Namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Epi.Fields;
using Epi;
using VariableCollection = Epi.Collections.NamedObjectCollection<Epi.IVariable>;

#endregion
namespace Epi.Windows.MakeView.Dialogs.FieldDefinitionDialogs
{
    /// <summary>
    /// Field definition dialog for relate fields
    /// </summary>
    public partial class RelateFieldDefinition : CommandButtonFieldDefinition
    {
        private RelatedViewField field;

		#region Constructors
        /// <summary>
        /// Default Constsructor, for exclusive use by the designer.
        /// </summary>
        public RelateFieldDefinition()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Constructor for the Relate Field Definition
        /// </summary>
        /// <param name="frm">The main form</param>
		public RelateFieldDefinition(MainForm frm) : base(frm)
		{
			InitializeComponent();
		}

        /// <summary>
        /// Constructor for the Relate Field Definition
        /// </summary>
        /// <param name="frm">The main form</param>
        /// <param name="page">The page</param>
		public RelateFieldDefinition(MainForm frm, Page page) : base(frm)
		{
			InitializeComponent();
			this.mode = FormMode.Create;
			this.page = page;
		}

		/// <summary>
		/// Constructor for the class
		/// </summary>
        /// <param name="frm">The parent form</param>
		/// <param name="field">The fied to be edited</param>
		public RelateFieldDefinition(MainForm frm, RelatedViewField field) : base(frm)
		{
			InitializeComponent();
			this.mode = FormMode.Edit;
			this.field = field;
			this.page = field.Page;
			LoadFormData();
		}
		#endregion Constructors

        #region Private Methods
        private void LoadFormData()
        {
            txtPrompt.Text = field.PromptText;
            txtPrompt.Font = field.PromptFont; 
            txtFieldName.Text = field.Name;
            txtFieldName.Font = field.ControlFont;

            //fill combo with all variables
            IMemoryRegion memoryRegion = this.MainForm.Module.GetMemoryRegion();
            VariableCollection vars = memoryRegion.GetVariablesInScope();
            foreach (IVariable v in vars)
            {
                cbxVariables.Items.Add(v.Name);
                cbxVariables.SelectedIndex = -1;
            }
            cbxVariables.Sorted = true;


            //fill combo with view name except current view //zack 8/6/08
            DataTable cbxDs = new DataTable();
            cbxDs.Columns.Add("RelatedViewId", typeof(int));
            cbxDs.Columns.Add("ViewName", typeof(string));

            foreach (Epi.View v in field.GetView().Project.Views)
            {
                if (v.Name != field.GetView().Name)
                {
                    cbxRelatedView.Items.Add(v.Name);  
                    object [] row = new object [2];
                    row[0]=v.Id ;
                    row[1]=v.Name ;
                    cbxDs.Rows.Add(row);
                }
            }
            cbxRelatedView.DataSource = cbxDs;
            cbxRelatedView.ValueMember = "RelatedViewId";
            cbxRelatedView.DisplayMember = "ViewName"; 

            //TODO:  Get ChildView from XML metadata - EJ
            if (field.ChildView != null)
            {
                cbxRelatedView.Text = field.ChildView.Name; 
            }

            if (field.Condition.Length > 0)
            {
                rdbAccessibleWithConditions.Checked = true;
                txtCondition.Text  = field.Condition;
            }
            else
            {
                rdbAccessibleAlways.Checked = true;
                txtCondition.Text = string.Empty;
            }
            controlFont = field.ControlFont;
            chkReturnToParent.Checked = field.ShouldReturnToParent;
            //8/7/08 Zack; here missing: chkNutstat.Checked = field.RelateToNutstat, field class does not have this property now. However, it is not required because 'relate to NutStat' feature in Epi3.4.3 has been removed
            //ToDo,  will remove the nutstat checkbox later 
        }

        /// <summary>
        /// Common event handler for build expression buttons
        /// </summary>
        /// <param name="sender">Object that fired the event.</param>
        /// <param name="e">.NET supplied event args.</param>
        private void ClickHandler(object sender, System.EventArgs e)
        {
            ToolStripButton btn = (ToolStripButton)sender;
            txtCondition.Text += StringLiterals.SPACE;
            if ((string)btn.Tag == null)
            {
                txtCondition.Text += btn.Text;
            }
            else
            {
                txtCondition.Text += (string)btn.Tag;
            }
            txtCondition.Text += StringLiterals.SPACE;
        }

        #endregion //Private Methods

        #region Public Methods


        protected override bool ValidateDialogInput()
        {
            ErrorMessages.Clear();
            if (!string.IsNullOrEmpty(txtCondition.Text))
            {
                try
                {
                    Compiler compiler = new Compiler();
                    compiler.Compile(txtCondition.Text.Trim());
                }
                catch (Exception ex)
                {
                    ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                if (rdbAccessibleWithConditions.Checked == true)
                {
                    ErrorMessages.Add(SharedStrings.WARNING_ADD_RELATE_CONDITION); 
                }
            }
            return (ErrorMessages.Count == 0);
        }

        /// <summary>
        /// Sets the field's properties based on GUI values
        /// </summary>
        protected override void SetFieldProperties()
        {
            field.Name = txtFieldName.Text;
            field.PromptText = txtPrompt.Text;
            if (controlFont != null)
            {
                field.ControlFont = controlFont;
            }
            field.RelatedViewID  = int.Parse(cbxRelatedView.SelectedValue.ToString ());   
            if (rdbAccessibleAlways.Checked == true)
            {
                field.Condition = string.Empty;
            }
            else
            {
                field.Condition = txtCondition.Text;
            }

            field.ShouldReturnToParent = chkReturnToParent.Checked;  
        }

        /// <summary>
        /// Gets the field defined by this field definition dialog
        /// </summary>
        public override RenderableField Field
        {
            get
            {
                return field;
            }
        }
        #endregion	//Public Methods

        #region Event Handlers
        private void rdbAccessibleWithConditions_CheckedChanged(object sender, EventArgs e)
        {
            lblCondition.Enabled = rdbAccessibleWithConditions.Checked;
            txtCondition.Enabled = rdbAccessibleWithConditions.Checked;
            lblAvailableVariables.Enabled = rdbAccessibleWithConditions.Checked;
            cbxVariables.Enabled = rdbAccessibleWithConditions.Checked;
            grpOperators.Enabled = rdbAccessibleWithConditions.Checked;
        }

        private void cbxVariables_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(cbxVariables.Text))
            {
                txtCondition.Text += cbxVariables.Text;
            }
        }
        
        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -