/// <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; } }
private void WriteValueJavascript(Rule_Value pValue, StringBuilder pJavaScriptBuilder) { if (!string.IsNullOrEmpty(pValue.Id)) { PluginVariable var = (PluginVariable)this.Context.CurrentScope.resolve(pValue.Id); if (var != null) { switch (var.DataType) { case EpiInfo.Plugin.DataType.Boolean: case EpiInfo.Plugin.DataType.Date: case EpiInfo.Plugin.DataType.DateTime: case EpiInfo.Plugin.DataType.Number: case EpiInfo.Plugin.DataType.Time: case EpiInfo.Plugin.DataType.Text: case EpiInfo.Plugin.DataType.GUID: pValue.ToJavaScript(pJavaScriptBuilder); break; default: pValue.ToJavaScript(pJavaScriptBuilder); break; } } } else { if (pValue.VariableDataType != EpiInfo.Plugin.DataType.Unknown) { switch (pValue.VariableDataType) { case EpiInfo.Plugin.DataType.Boolean: case EpiInfo.Plugin.DataType.Date: case EpiInfo.Plugin.DataType.DateTime: case EpiInfo.Plugin.DataType.Number: case EpiInfo.Plugin.DataType.Time: pValue.ToJavaScript(pJavaScriptBuilder); break; case EpiInfo.Plugin.DataType.Text: default: pValue.ToJavaScript(pJavaScriptBuilder); break; } } else if (pValue.value is string) { pValue.ToJavaScript(pJavaScriptBuilder); } else { pValue.ToJavaScript(pJavaScriptBuilder); } } }
///// <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; } }
public EpiInfo.Plugin.IVariable GetGridValue(string pName, int pIndex0, object pIndex1) { Dictionary<MetaFieldType, EpiInfo.Plugin.DataType> MapGridColumnTypeToDataType = new Dictionary<MetaFieldType, EpiInfo.Plugin.DataType>(); MapGridColumnTypeToDataType.Add(MetaFieldType.Text,EpiInfo.Plugin.DataType.Text); MapGridColumnTypeToDataType.Add(MetaFieldType.LabelTitle,EpiInfo.Plugin.DataType.Unknown); MapGridColumnTypeToDataType.Add(MetaFieldType.TextUppercase,EpiInfo.Plugin.DataType.Text); MapGridColumnTypeToDataType.Add(MetaFieldType.Multiline,EpiInfo.Plugin.DataType.Text); MapGridColumnTypeToDataType.Add(MetaFieldType.Number,EpiInfo.Plugin.DataType.Number); MapGridColumnTypeToDataType.Add(MetaFieldType.PhoneNumber,EpiInfo.Plugin.DataType.PhoneNumber); MapGridColumnTypeToDataType.Add(MetaFieldType.Date,EpiInfo.Plugin.DataType.Date); MapGridColumnTypeToDataType.Add(MetaFieldType.Time,EpiInfo.Plugin.DataType.Time); MapGridColumnTypeToDataType.Add(MetaFieldType.DateTime,EpiInfo.Plugin.DataType.DateTime); MapGridColumnTypeToDataType.Add(MetaFieldType.Checkbox,EpiInfo.Plugin.DataType.Boolean); MapGridColumnTypeToDataType.Add(MetaFieldType.YesNo,EpiInfo.Plugin.DataType.YesNo); MapGridColumnTypeToDataType.Add(MetaFieldType.Option,EpiInfo.Plugin.DataType.Text); MapGridColumnTypeToDataType.Add(MetaFieldType.CommandButton,EpiInfo.Plugin.DataType.Unknown); MapGridColumnTypeToDataType.Add(MetaFieldType.Image,EpiInfo.Plugin.DataType.Unknown); MapGridColumnTypeToDataType.Add(MetaFieldType.Mirror,EpiInfo.Plugin.DataType.Unknown); MapGridColumnTypeToDataType.Add(MetaFieldType.Grid,EpiInfo.Plugin.DataType.Unknown); MapGridColumnTypeToDataType.Add(MetaFieldType.LegalValues,EpiInfo.Plugin.DataType.Text); MapGridColumnTypeToDataType.Add(MetaFieldType.Codes,EpiInfo.Plugin.DataType.Text); MapGridColumnTypeToDataType.Add(MetaFieldType.CommentLegal,EpiInfo.Plugin.DataType.Text); MapGridColumnTypeToDataType.Add(MetaFieldType.Relate,EpiInfo.Plugin.DataType.Unknown); MapGridColumnTypeToDataType.Add(MetaFieldType.Group,EpiInfo.Plugin.DataType.Unknown); MapGridColumnTypeToDataType.Add(MetaFieldType.RecStatus,EpiInfo.Plugin.DataType.Number); MapGridColumnTypeToDataType.Add(MetaFieldType.UniqueKey,EpiInfo.Plugin.DataType.Number); MapGridColumnTypeToDataType.Add(MetaFieldType.ForeignKey,EpiInfo.Plugin.DataType.GUID); MapGridColumnTypeToDataType.Add(MetaFieldType.GUID,EpiInfo.Plugin.DataType.GUID); MapGridColumnTypeToDataType.Add(MetaFieldType.GlobalRecordId,EpiInfo.Plugin.DataType.GUID); MapGridColumnTypeToDataType.Add(MetaFieldType.List,EpiInfo.Plugin.DataType.Text); MapGridColumnTypeToDataType.Add(MetaFieldType.UniqueRowId, EpiInfo.Plugin.DataType.GUID); Epi.PluginVariable result = new PluginVariable(); result.Name = pName; result.DataType = EpiInfo.Plugin.DataType.Unknown; Epi.Fields.GridField gf = this.view.Fields[pName] as Epi.Fields.GridField; if (pIndex1 is string) { foreach (GridColumnBase gcb in gf.Columns) { if (gcb.Name.Equals(pIndex1.ToString(), StringComparison.OrdinalIgnoreCase)) { result.DataType = MapGridColumnTypeToDataType[gcb.GridColumnType]; break; } } } else { GridColumnBase gcb = gf.Columns[(int)pIndex1]; result.DataType = MapGridColumnTypeToDataType[gcb.GridColumnType]; } // if not on current page then pull from view.Fields if (this.currentPage.Fields.Contains(pName)) { List<System.Windows.Forms.Control> Controls = ControlFactory.Instance.GetAssociatedControls(this.currentPage.Fields[pName]); DataGridView dgv = null; if (Controls.Count > 1) { dgv = Controls[1] as DataGridView; } else { dgv = Controls[0] as DataGridView; } if (pIndex1 is string) { result.Expression = dgv.Rows[pIndex0].Cells[pIndex1.ToString()].Value.ToString(); } else { result.Expression = dgv.Rows[pIndex0].Cells[(int)pIndex1].Value.ToString(); } } else if (this.view.Fields.Contains(pName)) { if (gf.DataSource.Rows.Count > 0) { if (pIndex1 is string) { result.Expression = gf.DataSource.Rows[pIndex0][pIndex1.ToString()].ToString(); } else { result.Expression = gf.DataSource.Rows[pIndex0][(int)pIndex1].ToString(); } } } return result; }
public void OpenViewHandler(object sender, OpenViewEventArgs e) { Epi.View view = mCurrentProject.Views.GetViewById(e.ViewId); if (this.mCurrentView.Count == 0) { this.mCurrentView.Push(new RunTimeView(e.EnterCheckCodeInterface, view)); } else { if ( this.mCurrentProject.FilePath != view.GetProject().FilePath || view.ParentView == null || view.ParentView.Name != this.mCurrentView.Peek().View.Name ) { while (this.mCurrentView.Count > 0) { this.mCurrentView.Pop().CloseView(this, new RunCheckCodeEventArgs(EventActionEnum.CloseView, "")); } this.mCurrentView.Push(new RunTimeView(e.EnterCheckCodeInterface, view)); } else { RunTimeView runTimeView = this.mCurrentView.Peek(); int CurrentRecordId = runTimeView.View.CurrentRecordId; string CurrentGlobalRecordId = runTimeView.View.CurrentGlobalRecordId; EpiInfo.Plugin.IScope scope = runTimeView.EpiInterpreter.Context.GetNewScope(runTimeView.View.Name, runTimeView.EpiInterpreter.Context.Scope); foreach (Epi.Fields.Field field in runTimeView.View.Fields) { if (field is EpiInfo.Plugin.IVariable) { PluginVariable pluginVariable = new PluginVariable(); pluginVariable.VariableScope = EpiInfo.Plugin.VariableScope.Standard; pluginVariable.Name = field.Name; pluginVariable.DataType = ((EpiInfo.Plugin.IVariable)field).DataType; if (field is Epi.Fields.CheckBoxField || field is Epi.Fields.YesNoField) { if (((Epi.Fields.IDataField)field).CurrentRecordValueString == "1") { pluginVariable.Expression = "true"; } else if (((Epi.Fields.IDataField)field).CurrentRecordValueString == "0") { pluginVariable.Expression = "false"; } else { pluginVariable.Expression = null; } } else { pluginVariable.Expression = ((Epi.Fields.IDataField)field).CurrentRecordValueString; } scope.Define(pluginVariable); } } this.mCurrentView.Push(new RunTimeView(e.EnterCheckCodeInterface, view, CurrentRecordId, CurrentGlobalRecordId, scope)); } } this.mCurrentView.Peek().OpenViewHandler(sender, e); }
/// <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; } }
/// <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().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); } 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; } }