public static object EvalSQL(string SQL, DataRow drParams, int?appID = null) { if (!MyUtils.IsEmpty(SQL)) { DataTable dt = GetBySQL(SQL, drParams, appID); if (MyWebUtils.GetNumberOfRows(dt) > 0 && MyWebUtils.GetNumberOfColumns(dt) > 0) { return(dt.Rows[0][0]); } } return(null); }
public static bool IsTrueSQL(string SQL, DataRow drParams, int?appID = null) { if (!MyUtils.IsEmpty(SQL)) { DataTable dt = GetBySQL(SQL, drParams, appID); if (MyWebUtils.GetNumberOfRows(dt) > 0 && MyWebUtils.GetNumberOfColumns(dt) > 0) { return(Convert.ToBoolean(MyUtils.Coalesce(dt.Rows[0][0], false))); } return(false); } return(true); }
public DataTable SelectTable(object table, string view, object parameters, ref string script) { DataRow drParams = parameters as DataRow; DataTable dt = null; CiTable ciTable = table as CiTable; if (ciTable != null) { if (parameters != null && parameters.GetType() == typeof(bool)) { // Do nothing - but can't remember what this is for??? throw new System.Exception("Aha!"); } else if (ciTable.SelectMacro != null) { CiMacro ciMacro = ciTable.SearchMacro; if (ciMacro != null) { ciMacro.Run(drParams, true); dt = ciMacro.ResultTable; script = ciMacro.ResultScript; } } else if (ciTable.DataSource != null) { dt = ciTable.DataTable; } if (dt == null) { dt = new DataTable(); } AddExpressionColumns(ciTable, dt, drParams); if (MyWebUtils.GetNumberOfColumns(dt) > 0 && !dt.Columns.Contains("RowKey")) { dt.Columns.Add("RowKey").Expression = CreateRowKeyExpression(ciTable.RowKey); } } return(dt); }
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); }