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; }
public void Define(EpiInfo.Plugin.IVariable symbol) { if ( (symbol.VariableScope == EpiInfo.Plugin.VariableScope.Permanent | symbol.VariableScope == EpiInfo.Plugin.VariableScope.Global) && !_name.Equals("global", StringComparison.OrdinalIgnoreCase) || !string.IsNullOrEmpty(symbol.Namespace) && (!string.IsNullOrEmpty(_name) && !_name.Equals(symbol.Namespace, StringComparison.OrdinalIgnoreCase)) ) { if (_parent != null) { _parent.Define(symbol); } } else if (!string.IsNullOrEmpty(symbol.Namespace) && !_name.Equals(symbol.Namespace)) { if (_parent != null) { _parent.Define(symbol); } } else { if (_symbolList.ContainsKey(symbol.Name)) { _symbolList[symbol.Name] = symbol; } else { _symbolList.Add(symbol.Name, symbol); if (symbol.VariableScope == EpiInfo.Plugin.VariableScope.Permanent) { PermanentVariable permanentVariable = new PermanentVariable(symbol.Name, (Epi.DataType)symbol.DataType); permanentVariable.Expression = symbol.Expression; Epi.MemoryRegion.UpdatePermanentVariable(permanentVariable); } } } }
public void DefineVariable(EpiInfo.Plugin.IVariable variable) { this.currentScope.Define(variable); }
public static void UpdatePermanentVariable(EpiInfo.Plugin.IVariable variable) { Configuration config = Configuration.GetNewInstance(); DataRow[] result = config.PermanentVariables.Select("Name='" + variable.Name + "'"); if (result.Length < 1) { config.PermanentVariables.AddPermanentVariableRow( variable.Name, variable.Expression ?? "", (int)variable.DataType, config.ParentRowPermanentVariables); } else if (result.Length == 1) { ((DataSets.Config.PermanentVariableRow)result[0]).DataValue = variable.Expression ?? ""; ((DataSets.Config.PermanentVariableRow)result[0]).DataType = (int)variable.DataType; } else { throw new ConfigurationException(ConfigurationException.ConfigurationIssue.ContentsInvalid, "Duplicate permanent variable rows encountered."); } Configuration.Save(config); }
public IAnalysisStatistic GetStatistic(string pName, EpiInfo.Plugin.IAnalysisStatisticContext pHost) { IAnalysisStatistic result = null; string StatisticsAssembly = CommandToAssemblyMap[pName]; System.Reflection.Assembly a = StatisticModuleList[StatisticsAssembly]; foreach (Type type in a.GetTypes()) { if (type.IsPublic && type.IsClass && type.Name.Equals(pName, StringComparison.OrdinalIgnoreCase)) { result = (EpiInfo.Plugin.IAnalysisStatistic)Activator.CreateInstance(type, new object[] { pHost }); break; } } return result; }
public bool TryGetVariable(string p, out EpiInfo.Plugin.IVariable var) { bool result = false; var = null; Epi.IVariable V = null; result = this.mContext.MemoryRegion.TryGetVariable(p, out V); var = (EpiInfo.Plugin.IVariable) V; return result; }
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; }
/// <summary> /// Try Get Field Info /// </summary> /// <param name="name">Name</param> /// <param name="dataType">Type</param> /// <param name="value">Value</param> /// <returns>boolean</returns> public bool TryGetFieldInfo(string name, out EpiInfo.Plugin.DataType dataType, out string value) { bool fieldExists = false; IVariable dataField; dataType = EpiInfo.Plugin.DataType.Unknown; value = string.Empty; if (this.view == null) { this.view = this.EnterCheckCodeEngine.CurrentView.View; } // check if field is on current page and get data from the page control // if not on current page then pull from view.Fields if (this.currentPage != null && this.currentPage.Fields.Contains(name)) { List<System.Windows.Forms.Control> Controls = ControlFactory.Instance.GetAssociatedControls(this.currentPage.Fields[name]); dataField = (IVariable)this.view.Fields[name]; dataType = (EpiInfo.Plugin.DataType)dataField.DataType; if (Controls.Count > 1) { if (Controls[1] is CheckBox) { value = ((CheckBox)Controls[1]).Checked.ToString(); } else if (Controls[1] is Epi.Windows.Enter.Controls.LegalValuesComboBox) { Epi.Windows.Enter.Controls.LegalValuesComboBox legalValue = (Epi.Windows.Enter.Controls.LegalValuesComboBox)Controls[1]; // codes do NOT use the SelectedValue //if (legalValue.SelectedValue == null) //{ // value = Controls[1].Text; //} //else //{ // if (legalValue.SelectedIndex > -1) // { // if (legalValue.Items[legalValue.SelectedIndex] is System.Data.DataRowView) // { // value = ((System.Data.DataRowView)legalValue.SelectedValue).Row[0].ToString(); // } // else // { // value = legalValue.SelectedValue.ToString(); // } // } // else // { // value = legalValue.SelectedValue.ToString(); // } //} if (dataField is DDLFieldOfCommentLegal) { /*if (!string.IsNullOrEmpty(legalValue.SelectedText) && legalValue.SelectedText.Trim().Length > 0) { value = legalValue.SelectedText.Split('-')[0].Trim(); } else {*/ if (!string.IsNullOrEmpty(Controls[1].Text) && Controls[1].Text.Trim().Length > 0) { value = Controls[1].Text.Split('-')[0].Trim(); } //} } else if (dataField is YesNoField) { if (legalValue.SelectedIndex == 1) value = "0"; else if (legalValue.SelectedIndex == 0) value = "1"; else value = ""; } else { value = Controls[1].Text; } } else { value = Controls[1].Text; } } else { if (Controls[0] is CheckBox) { value = ((CheckBox)Controls[0]).Checked.ToString(); } else if (Controls[0] is GroupBox) { string checkedRadioButtonName = string.Empty; foreach (Control control in ((GroupBox)Controls[0]).Controls) { if (((RadioButton)control).Checked) { checkedRadioButtonName = control.Text; break; } } int index = 0; foreach (string option in ((OptionField)dataField).Options) { if (checkedRadioButtonName == option) { value = index.ToString(); break; } index++; } } else if (Controls[0] is Epi.Windows.Enter.Controls.LegalValuesComboBox) { // codes do NOT use the SelectedValue if (((Epi.Windows.Enter.Controls.LegalValuesComboBox)Controls[0]).SelectedValue == null) { value = Controls[0].Text; } else { if (((Epi.Windows.Enter.Controls.LegalValuesComboBox)Controls[0]).SelectedValue is System.Data.DataRowView) { value = ((System.Data.DataRowView)((Epi.Windows.Enter.Controls.LegalValuesComboBox)Controls[0]).SelectedValue).Row[0].ToString(); } else { value = ((Epi.Windows.Enter.Controls.LegalValuesComboBox)Controls[0]).SelectedValue.ToString(); } } if (dataField is DDLFieldOfCommentLegal) { value = value.Split('-')[0].Trim(); } } else { value = Controls[0].Text; } } } else if (this.view.Fields.Contains(name)) { try { dataField = (IVariable)this.view.Fields[name]; dataType = (EpiInfo.Plugin.DataType) dataField.DataType; if (dataField is InputFieldWithSeparatePrompt) { if (dataField is DDLFieldOfCommentLegal) { value = ((Epi.Fields.InputFieldWithSeparatePrompt)(dataField)).CurrentRecordValueObject.ToString(); } else { value = ((Epi.Fields.InputFieldWithSeparatePrompt)(dataField)).CurrentRecordValueString; } } else if (dataField is InputFieldWithoutSeparatePrompt) { value = ((Epi.Fields.InputFieldWithoutSeparatePrompt)(dataField)).CurrentRecordValueString; } else if (dataField is PredefinedDataField) { value = ((Epi.Fields.PredefinedDataField)(dataField)).CurrentRecordValueString; } fieldExists = true; } catch { fieldExists = false; } } else if (this.view.IsRelatedView) { bool isparentexists = false; View parentview = null; try { isparentexists = GetParentfieldvalue(name, view, out parentview); if (isparentexists) { dataField = (IVariable)this.EnterCheckCodeEngine.CurrentView.View.Project.Views[parentview.Name].Fields[name]; dataType = (EpiInfo.Plugin.DataType)dataField.DataType; if (dataField is InputFieldWithSeparatePrompt) { if (dataField is DDLFieldOfCommentLegal) { value = ((Epi.Fields.InputFieldWithSeparatePrompt)(dataField)).CurrentRecordValueObject.ToString(); } else { value = ((Epi.Fields.InputFieldWithSeparatePrompt)(dataField)).CurrentRecordValueString; } } else if (dataField is InputFieldWithoutSeparatePrompt) { value = ((Epi.Fields.InputFieldWithoutSeparatePrompt)(dataField)).CurrentRecordValueString; } else if (dataField is PredefinedDataField) { value = ((Epi.Fields.PredefinedDataField)(dataField)).CurrentRecordValueString; } fieldExists = true; } } catch { fieldExists = false; } } return fieldExists; }
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.ToUpper()); } else if (dataType == EpiInfo.Plugin.DataType.Time) { watermark = string.Format("{0}", formatInfo.LongTimePattern.ToUpper()); } else { watermark = string.Format("{0} {1}", formatInfo.ShortDatePattern.ToUpper(), formatInfo.LongTimePattern.ToUpper()); } return watermark; }
public cSymbol(EpiInfo.Plugin.IVariable pVariable) { this.Name = pVariable.Name; this.Type = pVariable.DataType; }
public cSymbol(string pName, EpiInfo.Plugin.DataType pType) { this.Name = pName; this.Type = pType; }
public BuiltInTypeSymbol(EpiInfo.Plugin.DataType pType) : base(pType.ToString(), pType) { }
public List<EpiInfo.Plugin.IVariable> FindVariables(EpiInfo.Plugin.VariableScope pScopeCombination, string pNamespace = null) { List<EpiInfo.Plugin.IVariable> result = new List<EpiInfo.Plugin.IVariable>(); if (!string.IsNullOrEmpty(pNamespace) && (!string.IsNullOrEmpty(_name) && !_name.Equals(pNamespace, StringComparison.OrdinalIgnoreCase))) { if (_parent != null) { result.AddRange(_parent.FindVariables(pScopeCombination, pNamespace)); } } else { foreach (KeyValuePair<string, EpiInfo.Plugin.IVariable> kvp in _symbolList) { if ((kvp.Value.VariableScope & pScopeCombination) > 0) { result.Add(kvp.Value); } } if (_parent != null) { result.AddRange(_parent.FindVariables(pScopeCombination, pNamespace)); } } return result; }
public SymbolTable(string pName, EpiInfo.Plugin.IScope parent) { _name = pName; _parent = parent; _symbolList = new Dictionary<string, EpiInfo.Plugin.IVariable>(StringComparer.OrdinalIgnoreCase); }
public void RemoveVariablesInScope(EpiInfo.Plugin.VariableScope scopeCombination, string variableNamespace = null) { if (!string.IsNullOrEmpty(variableNamespace) && (!string.IsNullOrEmpty(_name) && !_name.Equals(variableNamespace, StringComparison.OrdinalIgnoreCase))) { if (_parent != null) { _parent.RemoveVariablesInScope(scopeCombination); } } else { List<string> kvplist = new List<string>(); for (int i = 0; i < _symbolList.Count; i++) { KeyValuePair<string, EpiInfo.Plugin.IVariable> kvp = _symbolList.ElementAt(i); if ((kvp.Value.VariableScope & scopeCombination) > 0) { kvplist.Add(kvp.Key); } } foreach (string kvpkey in kvplist) { Undefine(kvpkey, variableNamespace); } if (_parent != null) { _parent.RemoveVariablesInScope(scopeCombination, variableNamespace); } } }
public bool TryGetVariable(string p, out EpiInfo.Plugin.IVariable var) { bool result = false; var = null; var = this.currentScope.Resolve(p); if (var != null) { result = true; } return result; }
/// <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; }
public VariableSymbol(string pName, EpiInfo.Plugin.DataType pType) : base(pName, pType) { }
public VariableSymbol(EpiInfo.Plugin.IVariable pVariable) : base(pVariable.Name, pVariable.DataType) { }
public void DefineVariable(EpiInfo.Plugin.IVariable variable) { this.Context.MemoryRegion.DefineVariable((Epi.IVariable)variable); }
/// <summary> /// Displays a textbox input dialog /// </summary> /// <param name="text">Text</param> /// <param name="caption">Caption</param> /// <param name="mask">Mask</param> /// <param name="modifier">Modifier</param> /// <param name="input">Input</param> public bool Dialog(string text, string caption, string mask, string modifier, ref object input, EpiInfo.Plugin.DataType dataType) { bool ret = false; if (modifier.ToUpper().Equals("READ") || modifier.ToUpper().Equals("WRITE")) { string filePath; if (TryGetFileDialog((string)input, caption, modifier.ToUpper().Equals("READ"), out filePath)) { ret = true; if (input is StringBuilder) { ((StringBuilder)input).Append(filePath); } else { input = filePath; } } } else { Epi.Windows.Dialogs.InputDialog dialog = new Epi.Windows.Dialogs.InputDialog(text, caption, mask, input, dataType); DialogResult result = dialog.ShowDialog(); if (input is StringBuilder) { ((StringBuilder)input).Append(dialog.Input); } else if (dataType == EpiInfo.Plugin.DataType.Date) { DateTime dateTime; bool canParse = DateTime.TryParse(input.ToString(), out dateTime); if (((DateField)this.EnterCheckCodeEngine.CurrentView.CurrentField).IsInRange(dateTime) == false) { return false; } } else { input = dialog.Input; } ret = result == DialogResult.OK ? true : false; } return ret; }
private object ConvertEpiDataTypeToSystemObject(EpiInfo.Plugin.DataType dataType, string dataValue) { object result = null; if (dataValue != null) { DateTime dateTime; 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: if (DateTime.TryParse(dataValue, out dateTime)) { DateTime dt = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day); result = dt; } else { result = null; } break; case EpiInfo.Plugin.DataType.DateTime: case EpiInfo.Plugin.DataType.Time: 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('\"'); 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; }