public static string GetSQLFromXml(XmlElement expressionElement) { if (!MyUtils.IsEmpty(expressionElement)) { eLangType language = eLangType.literal; string expression = expressionElement.InnerText; string languageString = expressionElement.GetAttribute("lang"); if (!MyUtils.IsEmpty(languageString)) { try { language = (eLangType)Enum.Parse(typeof(eLangType), languageString); } catch { // Do nothing } } switch (language) { case eLangType.sql: return(expression); } } return(null); }
public static object Eval(XmlElement expressionElement, DataRow drParams, Type type) { object result = null; if (!MyUtils.IsEmpty(expressionElement)) { eLangType language = eLangType.literal; string expression = expressionElement.InnerText; string languageString = expressionElement.GetAttribute("lang"); if (!MyUtils.IsEmpty(languageString)) { try { language = (eLangType)Enum.Parse(typeof(eLangType), languageString); } catch { // Do nothing } } switch (language) { case eLangType.literal: result = expression; break; case eLangType.column: string columnName = expression; if (drParams != null && drParams.Table.Columns.Contains(columnName)) { result = drParams[columnName]; } else { result = null; } break; case eLangType.sql: if (!MyUtils.IsEmpty(expression)) { DataTable dt = GetBySQL(expression, drParams); if (type == typeof(DataTable)) { result = dt; } else if (type == typeof(DataRow)) { if (MyWebUtils.GetNumberOfRows(dt) > 0) { result = dt.Rows[0]; } } else { if (MyWebUtils.GetNumberOfRows(dt) > 0 && MyWebUtils.GetNumberOfColumns(dt) > 0) { result = dt.Rows[0][0]; } } } break; case eLangType.xml: result = expressionElement; break; } } if (MyUtils.IsEmpty(result)) { if (type == typeof(bool)) { result = false; } } return(result); }