Example #1
0
 public PluginVariable(string pName, EpiInfo.Plugin.DataType pDataType, EpiInfo.Plugin.VariableScope pVariableScope, string pExpression, string pNamespace = null)
 {
     this.name          = pName;
     this.dataType      = pDataType;
     this.variableScope = pVariableScope;
     this.expression    = pExpression;
     this._Namespace    = pNamespace;
 }
 public PluginVariable(string name, EpiInfo.Plugin.DataType dataType, EpiInfo.Plugin.VariableScope variableScope, string expression, string variableNamespace = null, string prompt = null)
 {
     _name              = name;
     _dataType          = dataType;
     _variableScope     = variableScope;
     _expression        = expression;
     _variableNamespace = variableNamespace;
     _prompt            = prompt;
 }
        /// <summary>
        /// performs execution of retrieving the value of a variable or expression
        /// </summary>
        /// <returns>object</returns>
        public override object Execute()
        {
            object result = null;

            if (this.Id != null)
            {
                EpiInfo.Plugin.IVariable var;
                EpiInfo.Plugin.DataType  dataType = EpiInfo.Plugin.DataType.Unknown;
                string dataValue = string.Empty;

                var = Context.CurrentScope.Resolve(this.Id, this.Namespace);

                if (var != null && !(var.VariableScope == EpiInfo.Plugin.VariableScope.DataSource))
                {
                    dataType  = var.DataType;
                    dataValue = var.Expression;
                }
                else
                {
                    if (this.Context.EnterCheckCodeInterface != null)
                    {
                        EpiInfo.Plugin.DataType dt = EpiInfo.Plugin.DataType.Unknown;

                        if (this.Index0 == -1)
                        {
                            this.Context.EnterCheckCodeInterface.TryGetFieldInfo(this.Id, out dt, out dataValue);
                            dataType = (EpiInfo.Plugin.DataType)dt;
                        }
                        else
                        {
                            if (this.Index1 is Rule_Value)
                            {
                                this.Index1 = ((Rule_Value)this.Index1).Execute();
                            }

                            EpiInfo.Plugin.IVariable iv = this.Context.EnterCheckCodeInterface.GetGridValue(this.Id, this.Index0, this.Index1);
                            dataValue = iv.Expression;
                            dataType  = iv.DataType;
                        }
                    }
                }
                result = ConvertEpiDataTypeToSystemObject(dataType, dataValue);
            }
            else
            {
                if (value is EnterRule)
                {
                    result = ((EnterRule)value).Execute();
                }
                else
                {
                    result = value;
                }
            }
            return(result);
        }
Example #4
0
        /// <summary>
        /// performs execution of retrieving the value of a variable or expression
        /// </summary>
        /// <returns>object</returns>
        public override object Execute()
        {
            object result = null;

            if (this.Id != null)
            {
                EpiInfo.Plugin.IVariable var;
                EpiInfo.Plugin.DataType  dataType = EpiInfo.Plugin.DataType.Unknown;
                string dataValue = string.Empty;

                var = this.Context.CurrentScope.resolve(this.Id, this.Namespace);

                if (var != null)
                {
                    dataType  = var.DataType;
                    dataValue = var.Expression;
                }
                else
                {
                    if (this.Context.EnterCheckCodeInterface != null)
                    {
                        EpiInfo.Plugin.DataType dt = EpiInfo.Plugin.DataType.Unknown;

                        this.Context.EnterCheckCodeInterface.TryGetFieldInfo(this.Id, out dt, out dataValue);
                        dataType = (EpiInfo.Plugin.DataType)dt;
                    }
                }
                result = ConvertEpiDataTypeToSystemObject(dataType, dataValue);
            }
            else
            {
                if (value is EnterRule)
                {
                    result = ((EnterRule)value).Execute();
                }
                else
                {
                    //result = ParseDataStrings(((String)value));
                    result = ParseDataStrings(value);
                }
            }
            return(result);
        }
Example #5
0
        string Watermark(EpiInfo.Plugin.DataType dataType)
        {
            System.Globalization.DateTimeFormatInfo formatInfo = System.Globalization.DateTimeFormatInfo.CurrentInfo;
            string watermark = string.Empty;

            if (dataType == EpiInfo.Plugin.DataType.Date)
            {
                watermark = string.Format("{0}", formatInfo.ShortDatePattern.ToUpperInvariant());
            }
            else if (dataType == EpiInfo.Plugin.DataType.Time)
            {
                watermark = string.Format("{0}", formatInfo.LongTimePattern.ToUpperInvariant());
            }
            else
            {
                watermark = string.Format("{0} {1}", formatInfo.ShortDatePattern.ToUpperInvariant(), formatInfo.LongTimePattern.ToUpperInvariant());
            }

            return(watermark);
        }
Example #6
0
        protected bool DialogThenAssign(object obj, EpiInfo.Plugin.DataType dataType = EpiInfo.Plugin.DataType.Unknown)
        {
            MaskOpt  = MaskOpt == null ? string.Empty : MaskOpt;
            MaskOpt  = MaskOpt == "None" ? string.Empty : MaskOpt;
            Modifier = Modifier == null ? string.Empty : Modifier;

            if (this.Context.EnterCheckCodeInterface.Dialog(Prompt, TitleText, MaskOpt, Modifier, ref obj, dataType))
            {
                if (obj is StringBuilder)
                {
                    Assign.AssignValue(this.Context, Identifier, obj.ToString());
                }
                else
                {
                    Assign.AssignValue(this.Context, Identifier, obj);
                }

                return(true);
            }

            return(false);
        }
Example #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="text">Text (aka Prompt) is shown on the form above the controls.</param>
        /// <param name="caption">Caption (aka Title) is shown on the title bar.</param>
        /// <param name="mask">Mask is used with masked controls.</param>
        /// <param name="input">Input is used to get the type of the object that will be displayed for user input.</param>
        public InputDialog(string text, string caption, string mask, object input, EpiInfo.Plugin.DataType dataType = EpiInfo.Plugin.DataType.Unknown)
        {
            Input = input;
            _dataType = dataType;
            bool IsExpand = false;
            InitializeComponent();

            if (caption.Length > 75)
            {
                caption = caption.Substring(0, 75) + "...";
            }

            this.gbxMainGroup.Text = caption;
            this.lblPrompt.Text = text;

            if (_dataType == EpiInfo.Plugin.DataType.Unknown)
            {
                if (input is System.String)
                {
                    _dataType = EpiInfo.Plugin.DataType.Text;
                }
                else if (input is System.Double)
                {
                    _dataType = EpiInfo.Plugin.DataType.Number;
                }
                else if (input is DateTime)
                {
                    _dataType = EpiInfo.Plugin.DataType.DateTime;
                }
                else if (input is Boolean)
                {
                    _dataType = EpiInfo.Plugin.DataType.Boolean;
                }
            }

            Control control = null;

            if (_dataType == EpiInfo.Plugin.DataType.Text)
            {
                Int32 maxLength;
                if (string.IsNullOrEmpty(mask))
                {
                    control = this.txtTextInput;
                }
                else if (Int32.TryParse(mask, out maxLength))
                {
                    this.txtTextInput.MaxLength = maxLength;
                    control = this.txtTextInput;
                }
                else
                {
                    this.txtMaskedTextInput.Mask = mask;
                    control = this.txtMaskedTextInput;
                }
            }
            else if (_dataType == EpiInfo.Plugin.DataType.Number)
            {
                if (string.IsNullOrEmpty(mask))
                {
                    this.txtTextInput.TextChanged += new EventHandler(textBoxInput_TextChanged);
                    control = this.txtTextInput;
                }
                else
                {
                    this.txtMaskedTextInput.Mask = mask;
                    control = this.txtMaskedTextInput;
                }
            }
            else if (_dataType == EpiInfo.Plugin.DataType.Date || _dataType == EpiInfo.Plugin.DataType.Time || _dataType == EpiInfo.Plugin.DataType.DateTime)
            {
                txtTextInput.TextChanged += new EventHandler(textBoxInput_TextChanged);
                if (_dataType == EpiInfo.Plugin.DataType.Date || _dataType == EpiInfo.Plugin.DataType.DateTime)
                {
                    txtTextInput.MouseDown += new MouseEventHandler(txtTextInput_MouseDown);
                    IsExpand = true;
                }
                control = txtTextInput;
                control.Text = Watermark(_dataType);

            }
            else if (_dataType == EpiInfo.Plugin.DataType.Boolean)
            {
                control = this.btnYes;
            }
            else if (input is List<string>)
            {
                this.lbxInput.Items.AddRange(((List<string>)input).ToArray());
                control = this.lbxInput;
            }

            control.Parent = gbxMainGroup;
            control.Visible = true;
            int controlGap = 14;
            Point starting = new Point(20, gbxMainGroup.Location.Y + 12);
            control.Select();

            lblPrompt.Location = new Point(starting.X, starting.Y);
            control.Location = new Point(starting.X, starting.Y + lblPrompt.Height + controlGap - 4);

            if (!IsExpand)
                gbxMainGroup.Size = new Size(gbxMainGroup.Size.Width, control.Location.Y + control.Size.Height + controlGap);
            else
                gbxMainGroup.Size = new Size(gbxMainGroup.Size.Width, control.Location.Y + control.Size.Height + controlGap + 160);
            btnOK.Location = new Point(btnOK.Location.X, gbxMainGroup.Location.Y + gbxMainGroup.Size.Height + controlGap);
            btnCancel.Location = new Point(btnCancel.Location.X, gbxMainGroup.Location.Y + gbxMainGroup.Size.Height + controlGap);
            this.Size = new Size(this.Size.Width, btnOK.Location.Y + btnOK.Size.Height + 48);

            if (_dataType == EpiInfo.Plugin.DataType.Boolean)
            {
                InitYesNoButtons();
            }

            this.TopMost = true;
        }
Example #8
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="text">Text (aka Prompt) is shown on the form above the controls.</param>
        /// <param name="caption">Caption (aka Title) is shown on the title bar.</param>
        /// <param name="mask">Mask is used with masked controls.</param>
        /// <param name="input">Input is used to get the type of the object that will be displayed for user input.</param>
        public InputGuidDialog(string text, string caption, string mask, object input, EpiInfo.Plugin.DataType dataType = EpiInfo.Plugin.DataType.Unknown)
        {
            Input     = input;
            _dataType = dataType;

            InitializeComponent();

            if (caption.Length > 75)
            {
                caption = caption.Substring(0, 75) + "...";
            }

            this.gbxMainGroup.Text = caption;
            this.lblPrompt.Text    = text;

            if (_dataType == EpiInfo.Plugin.DataType.Unknown)
            {
                if (input is System.String)
                {
                    _dataType = EpiInfo.Plugin.DataType.Text;
                }
                else if (input is System.Double)
                {
                    _dataType = EpiInfo.Plugin.DataType.Number;
                }
                else if (input is DateTime)
                {
                    _dataType = EpiInfo.Plugin.DataType.DateTime;
                }
                else if (input is Boolean)
                {
                    _dataType = EpiInfo.Plugin.DataType.Boolean;
                }
            }

            Control control = null;

            if (_dataType == EpiInfo.Plugin.DataType.Text)
            {
                Int32 maxLength;
                if (string.IsNullOrEmpty(mask))
                {
                    control = this.txtTextInput;
                }
                else if (Int32.TryParse(mask, out maxLength))
                {
                    this.txtTextInput.MaxLength = maxLength;
                    control = this.txtTextInput;
                }
                else
                {
                    this.txtMaskedTextInput.Mask = mask;
                    control = this.txtMaskedTextInput;
                }
            }
            else if (_dataType == EpiInfo.Plugin.DataType.Number)
            {
                if (string.IsNullOrEmpty(mask))
                {
                    this.txtTextInput.TextChanged += new EventHandler(textBoxInput_TextChanged);
                    control = this.txtTextInput;
                }
                else
                {
                    this.txtMaskedTextInput.Mask = mask;
                    control = this.txtMaskedTextInput;
                }
            }
            else if (_dataType == EpiInfo.Plugin.DataType.Date || _dataType == EpiInfo.Plugin.DataType.Time || _dataType == EpiInfo.Plugin.DataType.DateTime)
            {
                this.txtTextInput.TextChanged += new EventHandler(textBoxInput_TextChanged);
                control      = this.txtTextInput;
                control.Text = Watermark(_dataType);
            }
            else if (_dataType == EpiInfo.Plugin.DataType.Boolean)
            {
                control = this.btnYes;
            }
            else if (input is List <string> )
            {
                this.lbxInput.Items.AddRange(((List <string>)input).ToArray());
                control = this.lbxInput;
            }

            control.Parent  = gbxMainGroup;
            control.Visible = true;
            int   controlGap = 14;
            Point starting   = new Point(20, gbxMainGroup.Location.Y + 12);

            control.Select();

            lblPrompt.Location = new Point(starting.X, starting.Y);
            control.Location   = new Point(starting.X, starting.Y + lblPrompt.Height + controlGap - 4);

            gbxMainGroup.Size  = new Size(gbxMainGroup.Size.Width, control.Location.Y + control.Size.Height + controlGap);
            btnOK.Location     = new Point(btnOK.Location.X, gbxMainGroup.Location.Y + gbxMainGroup.Size.Height + controlGap);
            btnCancel.Location = new Point(btnCancel.Location.X, gbxMainGroup.Location.Y + gbxMainGroup.Size.Height + controlGap);
            this.Size          = new Size(this.Size.Width, btnOK.Location.Y + btnOK.Size.Height + 48);

            if (_dataType == EpiInfo.Plugin.DataType.Boolean)
            {
                InitYesNoButtons();
            }
        }
Example #9
0
 public BuiltInTypeSymbol(EpiInfo.Plugin.DataType pType) : base(pType.ToString(), pType)
 {
 }
Example #10
0
 public VariableSymbol(string pName, EpiInfo.Plugin.DataType pType) : base(pName, pType)
 {
 }
Example #11
0
 public cSymbol(EpiInfo.Plugin.IVariable pVariable)
 {
     this.Name = pVariable.Name;
     this.Type = pVariable.DataType;
 }
Example #12
0
 public cSymbol(string pName, EpiInfo.Plugin.DataType pType)
 {
     this.Name = pName;
     this.Type = pType;
 }
Example #13
0
        private object ConvertEpiDataTypeToSystemObject(EpiInfo.Plugin.DataType dataType, string dataValue)
        {
            object result = null;

            if (dataValue != null)
            {
                switch (dataType)
                {
                case EpiInfo.Plugin.DataType.Boolean:
                case EpiInfo.Plugin.DataType.YesNo:
                    result = new Boolean();
                    if (dataValue == "(+)" || dataValue.ToLower() == "true" || dataValue == "1" || dataValue.ToLower() == "yes")
                    {
                        result = true;
                    }
                    else if (dataValue == "(-)" || dataValue.ToLower() == "false" || dataValue == "0" || dataValue.ToLower() == "no")
                    {
                        result = false;
                    }
                    else
                    {
                        result = null;
                    }
                    break;

                case EpiInfo.Plugin.DataType.Number:
                    double num;
                    if (double.TryParse(dataValue, out num))
                    {
                        result = num;
                    }
                    else
                    {
                        result = null;
                    }
                    break;

                case EpiInfo.Plugin.DataType.Date:
                case EpiInfo.Plugin.DataType.DateTime:
                case EpiInfo.Plugin.DataType.Time:
                    DateTime dateTime;
                    if (DateTime.TryParse(dataValue, out dateTime))
                    {
                        result = dateTime;
                    }
                    else
                    {
                        result = null;
                    }
                    break;

                case EpiInfo.Plugin.DataType.PhoneNumber:
                case EpiInfo.Plugin.DataType.GUID:
                case EpiInfo.Plugin.DataType.Text:
                    if (dataValue != null)
                    {
                        result = dataValue.Trim().Trim('\"');
                    }
                    else
                    {
                        result = null;
                    }
                    break;

                case EpiInfo.Plugin.DataType.Unknown:
                default:
                    double   double_compare;
                    DateTime DateTime_compare;
                    bool     bool_compare;

                    if (double.TryParse(dataValue, out double_compare))
                    {
                        result = double_compare;
                    }
                    else
                    if (DateTime.TryParse(dataValue, out DateTime_compare))
                    {
                        result = DateTime_compare;
                    }
                    else
                    if (bool.TryParse(dataValue, out bool_compare))
                    {
                        result = bool_compare;
                    }
                    else
                    {
                        result = dataValue;
                    }
                    break;
                }
            }
            return(result);
        }
Example #14
0
        //object ReturnResult = null;

        public Rule_Value(Rule_Context pContext, Token pToken) : base(pContext)
        {
            /* ::= Identifier	| <Literal> | Boolean | '(' <Expr List> ')' */

            if (pToken is NonterminalToken)
            {
                NonterminalToken T = (NonterminalToken)pToken;
                if (T.Tokens.Length == 1)
                {
                    switch (T.Symbol.ToString())
                    {
                    case "<Qualified ID>":
                    case "Identifier":
                        this.Id = this.GetCommandElement(T.Tokens, 0);
                        break;

                    case "<FunctionCall>":
                        //this.value = new Rule_FunctionCall(pContext, (NonterminalToken)T.Tokens[0]);
                        this.value = EnterRule.BuildStatments(pContext, T.Tokens[0]);
                        break;

                    case "<Literal_Date>":
                        this.VariableDataType = EpiInfo.Plugin.DataType.Date;
                        this.value            = this.GetCommandElement(T.Tokens, 0);
                        break;

                    case "<Literal_Time>":
                        this.VariableDataType = EpiInfo.Plugin.DataType.Time;
                        this.value            = this.GetCommandElement(T.Tokens, 0);
                        break;

                    case "<Literal>":
                    case "<Literal_String>":
                        this.VariableDataType = EpiInfo.Plugin.DataType.Text;
                        this.value            = this.GetCommandElement(T.Tokens, 0);
                        break;

                    case "<Number>":
                    case "<Real_Number>":
                    case "<Decimal_Number>":
                    case "<Hex_Number>":
                        this.VariableDataType = EpiInfo.Plugin.DataType.Number;
                        this.value            = this.GetCommandElement(T.Tokens, 0);
                        break;

                    case "<Subroutine_Statement>":

                        break;

                    default:
                        this.value = this.GetCommandElement(T.Tokens, 0);
                        switch (this.value.ToString())
                        {
                        case "(+)":
                            this.VariableDataType = EpiInfo.Plugin.DataType.Boolean;
                            this.value            = true;
                            break;

                        case "(-)":
                            this.VariableDataType = EpiInfo.Plugin.DataType.Boolean;
                            this.value            = false;
                            break;

                        case "(.)":
                            this.VariableDataType = EpiInfo.Plugin.DataType.Boolean;
                            this.value            = null;
                            break;
                        }
                        break;
                    }
                }
                else
                {
                    //this.value = new Rule_ExprList(pContext, (NonterminalToken)T.Tokens[1]);
                    if (T.Tokens.Length == 0)
                    {
                        this.value = EnterRule.BuildStatments(pContext, T);
                    }
                    else if (T.Symbol.ToString() == "<Fully_Qualified_Id>" || T.Symbol.ToString() == "<Qualified ID>")
                    {
                        string[] temp = this.ExtractTokens(T.Tokens).Split(' ');
                        this.Namespace = temp[0];
                        this.Id        = temp[2];
                    }
                    else
                    {
                        if (this.GetCommandElement(T.Tokens, 0) == "(")
                        {
                            UseParenthesis = true;
                        }

                        //this.value = new Rule_ExprList(pContext, (NonterminalToken)T.Tokens[1]);
                        this.value = EnterRule.BuildStatments(pContext, T.Tokens[1]);
                    }
                }
            }
            else
            {
                TerminalToken TT = (TerminalToken)pToken;
                switch (TT.Symbol.ToString())
                {
                case "Boolean":
                    this.VariableDataType = EpiInfo.Plugin.DataType.Boolean;
                    this.value            = TT.Text;
                    break;

                case "RealLiteral":
                case "DecLiteral":
                case "HexLiteral":
                    this.VariableDataType = EpiInfo.Plugin.DataType.Number;
                    this.value            = TT.Text;
                    break;

                case "Date":
                    this.VariableDataType = EpiInfo.Plugin.DataType.Date;
                    this.value            = TT.Text;
                    break;

                case "Time":
                    this.VariableDataType = EpiInfo.Plugin.DataType.Time;
                    this.value            = TT.Text;
                    break;

                case "Identifier":
                    this.Id = TT.Text;
                    this.VariableDataType = EpiInfo.Plugin.DataType.Time;
                    break;

                case "String":
                    this.VariableDataType = EpiInfo.Plugin.DataType.Text;
                    this.value            = TT.Text;
                    break;

                default:
                    this.VariableDataType = EpiInfo.Plugin.DataType.Unknown;
                    this.value            = TT.Text;
                    break;
                }
            }

            if (this.Id == null && this.value == null)
            {
            }
        }