Esempio n. 1
0
        /// <summary>
        /// peforms the Define rule uses the MemoryRegion and this.Context.DataSet to hold variable definitions
        /// </summary>
        /// <returns>object</returns>
        public override object Execute()
        {
            PluginVariable result = new PluginVariable();

            try
            {
                result.Name = this.Identifier;
                string dataTypeName             = VariableTypeIndicator.Trim().ToUpper();
                EpiInfo.Plugin.DataType type    = GetDataType(dataTypeName);
                string variableScope            = Variable_Scope.Trim().ToUpper();
                EpiInfo.Plugin.VariableScope vt = EpiInfo.Plugin.VariableScope.Standard;

                if (!string.IsNullOrEmpty(variableScope))
                {
                    vt = this.GetVariableScopeIdByName(variableScope);
                }

                result.VariableScope = vt;
                result.DataType      = type;
                result.ControlType   = "hidden";
                this.Context.CurrentScope.define(result);

                return(result);
            }
            catch (Exception ex)
            {
                //Epi.Diagnostics.Debugger.Break();
                //Epi.Diagnostics.Debugger.LogException(ex);
                throw ex;
            }
        }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
        ///// <summary>
        ///// peforms the Define rule uses the MemoryRegion and this.Context.DataSet to hold variable definitions
        ///// </summary>
        ///// <returns>object</returns>
        //public override object Execute_Old()
        //{
        //    try
        //    {
        //        EpiInfo.Plugin.IVariable var = null;

        //        var = this.Context.CurrentScope.resolve(Identifier);
        //        if (var != null)
        //        {
        //            if (var.VariableScope != VariableScope.Permanent && var.VariableScope != VariableScope.Global)
        //                {
        //                    this.Context.EnterCheckCodeInterface.Dialog("Duplicate variable: " + Identifier, "Define");
        //                    return null;
        //                }
        //        }


        //        string dataTypeName = VariableTypeIndicator.Trim().ToUpper();
        //        EpiInfo.Plugin.DataType type = GetDataType(dataTypeName);
        //        string variableScope = Variable_Scope.Trim().ToUpper();
        //        EpiInfo.Plugin.VariableScope vt = EpiInfo.Plugin.VariableScope.Standard;

        //       //if(variableScope.Equals("PERMANENT", StringComparison.OrdinalIgnoreCase))
        //       //{
        //       //    vt = EpiInfo.Plugin.VariableScope.Permanent;
        //       //}
        //       //else if(variableScope.Equals("GLOBAL", StringComparison.OrdinalIgnoreCase))
        //       //{
        //       //     vt = EpiInfo.Plugin.VariableScope.Global;
        //       //}
        //       //else
        //       //{
        //       //     vt = EpiInfo.Plugin.VariableScope.Standard;
        //       //}


        //        if (!string.IsNullOrEmpty(variableScope))
        //        {
        //            vt = this.GetVariableScopeIdByName(variableScope);
        //        }

        //        //var = new PluginVariable(Identifier, type, vt, null);
        //        var = null;
        //        string promptString = Define_Prompt.Trim().Replace("\"", string.Empty);
        //        if (!string.IsNullOrEmpty(promptString))
        //        {
        //            promptString = promptString.Replace("(", string.Empty).Replace(")", string.Empty);
        //            promptString.Replace("\"", string.Empty);
        //        }
        //        //var.PromptText = promptString;
        //        //this.Context.MemoryRegion.DefineVariable(var);
        //        EpiInfo.Plugin.IVariable temp = (EpiInfo.Plugin.IVariable)var;
        //        this.Context.CurrentScope.define(temp);

        //        return var;
        //    }
        //    catch (Exception ex)
        //    {
        //        //Epi.Diagnostics.Debugger.Break();
        //        //Epi.Diagnostics.Debugger.LogException(ex);
        //        throw ex;
        //    }
        //}


        public override void ToJavaScript(StringBuilder pJavaScriptBuilder)
        {
            string defineFormat       = "cce_Context.define(\"{0}\", \"{1}\", \"{2}\", \"{3}\");";
            string defineNumberFormat = "cce_Context.define(\"{0}\", \"{1}\", \"{2}\", new Number({3}));";

            PluginVariable var = (PluginVariable)this.Context.CurrentScope.resolve(this.Identifier);

            if (var == null)
            {
                //foreach (PluginVariable var in this.Context.CurrentScope.FindVariables( VariableScope.DataSource | VariableScope.Global | VariableScope.Permanent))
                var = new PluginVariable();

                var.Name = this.Identifier;
                string dataTypeName             = VariableTypeIndicator.Trim().ToUpper();
                EpiInfo.Plugin.DataType type    = GetDataType(dataTypeName);
                string variableScope            = Variable_Scope.Trim().ToUpper();
                EpiInfo.Plugin.VariableScope vt = EpiInfo.Plugin.VariableScope.Standard;

                if (!string.IsNullOrEmpty(variableScope))
                {
                    vt = this.GetVariableScopeIdByName(variableScope);
                }

                var.VariableScope = vt;
                var.DataType      = type;
            }
            switch (var.ControlType)
            {
            case "checkbox":
            case "yesno":
                pJavaScriptBuilder.AppendLine(string.Format(defineFormat, var.Name, var.ControlType, "datasource", var.Expression));
                break;

            case "numeric":
                pJavaScriptBuilder.AppendLine(string.Format(defineNumberFormat, var.Name, var.ControlType, "datasource", var.Expression));
                break;

            case "commentlegal":
            case  "codes":
            case "legalvalues":
            case "datepicker":
            case "multiline":
            case "textbox":
            default:
                pJavaScriptBuilder.AppendLine(string.Format(defineFormat, var.Name, var.ControlType, "datasource", var.Expression));
                break;
            }
        }
        /// <summary>
        /// peforms the Define rule uses the MemoryRegion and this.Context.DataSet to hold variable definitions
        /// </summary>
        /// <returns>object</returns>
        public override object Execute()
        {
            try
            {
                EpiInfo.Plugin.IVariable var = null;

                var = Context.CurrentScope.Resolve(Identifier);
                if (var != null)
                {
                    if (var.VariableScope != VariableScope.Permanent && var.VariableScope != VariableScope.Global)
                    {
                        this.Context.EnterCheckCodeInterface.Dialog("Duplicate variable: " + Identifier, "Define");
                        return(null);
                    }


                    if (var.VariableScope == VariableScope.Permanent)
                    {
                        return(var);
                    }
                }


                string dataTypeName             = VariableTypeIndicator.Trim().ToUpperInvariant();
                EpiInfo.Plugin.DataType type    = GetDataType(dataTypeName);
                string variableScope            = Variable_Scope.Trim().ToUpperInvariant();
                EpiInfo.Plugin.VariableScope vt = EpiInfo.Plugin.VariableScope.Standard;

                //if(variableScope.Equals("PERMANENT", StringComparison.OrdinalIgnoreCase))
                //{
                //    vt = EpiInfo.Plugin.VariableScope.Permanent;
                //}
                //else if(variableScope.Equals("GLOBAL", StringComparison.OrdinalIgnoreCase))
                //{
                //     vt = EpiInfo.Plugin.VariableScope.Global;
                //}
                //else
                //{
                //     vt = EpiInfo.Plugin.VariableScope.Standard;
                //}


                if (!string.IsNullOrEmpty(variableScope))
                {
                    vt = this.GetVariableScopeIdByName(variableScope);
                }


                string promptString = Define_Prompt.Trim().Replace("\"", string.Empty);
                if (!string.IsNullOrEmpty(promptString))
                {
                    promptString = promptString.Replace("(", string.Empty).Replace(")", string.Empty);
                    promptString.Replace("\"", string.Empty);
                }

                var = new PluginVariable(Identifier, type, vt, null, promptString);
                //var.PromptText = promptString;
                //this.Context.MemoryRegion.DefineVariable(var);
                EpiInfo.Plugin.IVariable temp = (EpiInfo.Plugin.IVariable)var;
                this.Context.CurrentScope.Define(temp);

                return(var);
            }
            catch (Exception ex)
            {
                Epi.Diagnostics.Debugger.Break();
                Epi.Diagnostics.Debugger.LogException(ex);
                throw ex;
            }
        }