private static void BuildVariables(DataTable variables, PxMainTable table) { var vari = from c in variables.AsEnumerable() where c.Field <string>("Name") != null select new PxVariable { Variable = c.Field <string>("Name"), PresText = c.Field <string>("PressText"), PresTextEnglish = c.Field <string>("EnglishName"), Footnote = "N", VariableType = GetVariableType(c.Field <string>("Name")) }; foreach (var item in vari) { var variable = VariableFacade.GetVarible(item.Variable); if (variable != null) { if (String.Compare(variable.Variable, item.Variable, true) == 0) { if (String.Compare(variable.PresText, item.PresText, true) == 0) { item.IsNew = false; } else { item.Variable = item.Variable + Guid.NewGuid().ToString(); } } } table.Variables.Add(item); } }
public override bool Validate(ref string message) { // Check mandantory fields if (String.IsNullOrWhiteSpace(Valueset) || String.IsNullOrWhiteSpace(PresText) || String.IsNullOrWhiteSpace(Elimination) || String.IsNullOrWhiteSpace(ValuePool) || String.IsNullOrWhiteSpace(ValuePres)) { message = "Please enter a valid option for all input fields"; return(false); } //Check for duplicate values Dictionary <string, string> codes = new Dictionary <string, string>(); List <Model.PxValue> poolValues = VariableFacade.GetValuesByValuePool(ValuePool); PxValue existingValue; foreach (var v in _values) { string code = v.ValueCode.ToUpper(); if (codes.ContainsKey(code)) { message = "Duplicate code: " + v.ValueCode; return(false); } codes.Add(code, v.ValueCode); if (!v.Validate(ref message)) { return(false); } existingValue = GetValue(poolValues, v.ValueCode); if (existingValue == null) { v.IsNew = true; } else { if (String.Compare(existingValue.ValueText, v.ValueText, true) == 0 && String.Compare(existingValue.ValueTextEnglish, v.ValueTextEnglish, true) == 0) { v.IsNew = false; } else { message = String.Format("The value you are adding {0}, {1} is already in the valuepool {2}, \n Either remove your value and add it from valuepool or define a new valuepool or a new code in this valuepool" , v.ValueCode, v.ValueText, ValuePool); return(false); } } } return(true); }
/// <summary> Resolve the object into a variable by various means and /// using the current context. /// </summary> /// <returns> variable, or <code>null</code> /// </returns> internal virtual Variable resolveToVariable(Object o) { Variable v = null; // if o is a variable already, then we're done! if (o is Variable) return (Variable) o; // Resolve the name to something { // not an id so try as name String name = o.ToString(); long id = nameAsId(name); /* * if #N was used just pick up the variable, otherwise * we need to use the current context to resolve * the name to a member */ if (id != Value.UNKNOWN_ID) { // TODO what here? } else { // try to resolve as a member of current context (will set context if null) id = determineContext(name); v = locateForNamed((int) id, name, true); if (v != null) v = new VariableFacade(v, id); else if (v == null && m_createIfMissing && name[0] != '$') { v = new VariableFacade(id, name); } } } return v; }