//======================================== //get Rules public Dictionary <string, object> GetRules(int userId, DataConfig config) { DataTable dt = GetDataFromConfiguration(userId, config); Dictionary <string, object> result = new Dictionary <string, object>(); foreach (DataRow dr in dt.Rows) { result.Add(dr["RuleName"].ToString(), dr["Value"]); } return(result); }
//======================================== //count public int CountDataFromConfiguration(int userId, DataConfig config) { string statement; if (config.type == DataConfig.FunctionType) { statement = string.Format(@"exec [dbo].[USP_System_Data_Function_Get] @UserId ={0}, @FunctionName = '{1}', @Parameter = N'{2}', @TextFilter = N'{3}', @Action = '{4}', @StartRow = {5}, @EndRow = {6}, @GlobalOrder = '{7}', @GlobalOrderDirection = {8}" , userId, config.dataobject, config.functionparameters, config.condition, "count", config.startrow, config.endrow, config.sort, 1//dconfig.OrderDirection ); } else { statement = string.Format(@"exec [dbo].[USP_System_Data_List_Get] @UserId ={0}, @TableName = '{1}', @Colums = '{2}', @Condition = N'{3}', @OrderColums = '{4}', @TextFilter = N'{5}', @Action = '{6}', @StartRow = {7}, @EndRow = {8}, @GlobalOrder = '{9}', @GlobalOrderDirection = {10}" , userId, config.dataobject, config.columns, config.condition, config.sort, "",// gridConfig.FilterByValue, "count", config.startrow, config.endrow, "" /*config.OrderBy*/, 1//dconfig.OrderDirection ); } int count = 0; using (var db = dbFactory.OpenDbConnection()) { count = db.Scalar <int>(statement); } return(count); }
//======================================== #region Get List //======================================== //get Json public IList <Dictionary <string, object> > GetDataFromConfigurationJsonable(int userId, DataConfig gridConfig) { List <Dictionary <string, object> > rows = new List <Dictionary <string, object> >(); DataTable dt = GetDataFromConfiguration(userId, gridConfig); Dictionary <string, object> row; foreach (DataRow dr in dt.Rows) { row = new Dictionary <string, object>(); foreach (DataColumn col in dt.Columns) { if (dr[col] == DBNull.Value) { row.Add(col.ColumnName, ""); } else { if (col.DataType == typeof(DateTime)) { row.Add(col.ColumnName, Convert.ToDateTime(dr[col]).ToString("dd-MM-yyyy hh:mm:ss")); } else { row.Add(col.ColumnName, dr[col]); } } } rows.Add(row); } return(rows); }
//======================================== //sum public Dictionary <string, object> SumDataFromConfiguration(int userId, DataConfig config) { config.action = "sum"; //gridConfig.FilterBy return(GetDataFromConfigurationJsonable(userId, config).First()); }