public Variable(string src, int start, EquationElement root) { var varname = GetVarName(src, start, root); Name = varname; if (varname.Length > 0) m_sb.Append(varname); }
private bool AddUpdate(GeoArea geoArea, EquationYear equationYear, string userId, string[] elementValuesKeys) { var calculate = true; string values = ""; var elementIds = new List <int>(); foreach (string evs in elementValuesKeys) { string eeId = evs.Replace("ElementValue_", ""); EquationElement equationElement = db.EquationElements.Find(int.Parse(eeId)); if (equationElement == null) { throw new Exception("Equation Element Not Found"); } string strValue = Request[evs].Trim(); double _fValue = 0; double?fValue = null; if (string.IsNullOrEmpty(strValue) || double.TryParse(strValue, out _fValue)) { if (!string.IsNullOrEmpty(strValue)) { fValue = _fValue; } else { calculate = false; } values += string.Format("{0} : {1}\r\n", equationElement.Element.Name, strValue); var createdAt = DateTime.Now; var elementValue = new ElementValue() { EquationElementID = equationElement.ID, EquationYearID = equationYear.ID, GeoAreaID = geoArea.ID, Value = fValue, ApplicationUserID = userId, CreatedAt = createdAt, }; db.ElementValues.Add(elementValue); elementIds.Add(equationElement.ElementID); } else { throw new Exception("Value is in correct"); } } if (calculate) { var elementYearValues = db.ElementYearValues.Where(x => x.GeoAreaID == geoArea.ID && x.Year == equationYear.Year && elementIds.Contains(x.ElementID)).ToList(); foreach (var eyv in elementYearValues) { eyv.IsCommited = true; db.Entry(eyv).State = EntityState.Modified; } } return(calculate); }
private string GetElementValue(EquationElement ee, int geoAreaID, int year) { var value = ee.ElementValues.Where(x => x.GeoAreaID == geoAreaID && x.EquationYear.Year == year).FirstOrDefault(); if (value == null) { throw new Exception(string.Format("لا يوجد قيمة للمؤشر {0} في سنة {1}", ee.Element.Name, year)); } return(value.Value.ToString()); }
private static string GetVarName(string equation, int index, EquationElement root) { var varname = Term.ExtractName(equation, index).ToLower(); if (root != null && root.VarExist(varname)) return varname; var ch = equation[index]; if (ch >= 'a' && ch <= 'z') return new string(new[] {ch}); if (ch >= 'A' && ch <= 'Z') return new string(new[] {ch}); return string.Empty; }
static bool ShouldPopOperatorToQueue(EquationElement to, EquationElement so) { if (so is LeftBracketSymbol) { return(false); } if (so is OperatorBase) { if (so is EquationFunction) { return(true); } if (((OperatorBase)so).Precedence > ((OperatorBase)to).Precedence) { return(true); } if (((OperatorBase)so).Precedence == ((OperatorBase)to).Precedence && ((OperatorBase)so).Associativity == OperatorBase.OperatorAssociativity.Left) { return(true); } } return(false); }
public bool IsValid(string equation, int index, EquationElement root) => GetVarName(equation, index, root).Length > 0;