ValidationResult percentUsage() { int i = 0; while (i < equation.Count) { IEquationToken token = equation[i]; if (token is VariableToken) { ChemicalStreamData data; try { DictionaryOfTableData.TryGetValue(token.Value, out data); if (new UnitsFormatter().ConvertFromIntToString(data.Units) == "%") { if (i + 4 < equation.Count) { if (!(equation[i + 1].Value == "/" && equation[i + 2].Value == "100" && equation[i + 3].Value == "*" && DictionaryOfTableData.ContainsKey(equation[i + 4].Value))) { return(new ValidationResult(equation, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Incorrect_Use_Of_Percent))); } } else { return(new ValidationResult(equation, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Incorrect_Use_Of_Percent))); } } } catch { //it is a number so dont do anything } } i++; } return(ValidationResult.Empty); }
bool CheckSameCompound() { int i = 0; string compound = null; while (i < equation.Count) { IEquationToken token = equation[i]; if (token is VariableToken) { ChemicalStreamData data; try { DictionaryOfTableData.TryGetValue(token.Value, out data); if (compound == null) { compound = new CompoundFormatter().ConvertFromIntToString(data.Compound); } else if (compound != new CompoundFormatter().ConvertFromIntToString(data.Compound)) { return(false); } if (new UnitsFormatter().ConvertFromIntToString(data.Units) == "%") { //This is so we skip over the percent mainly the Overal so we dont have to deal with it i += 4; } } catch { //just to be safe but this should never catch anything } } i++; } return(true); }