/// <summary> /// 清除该数据集对应的所有缓存 /// </summary> public void ClearCache() { Rpt_DataSet_DataCacheBLL.ClearDataSetCache(_m.ID); }
public int SaveForever(Dictionary <string, object> ParamValues) { return(Rpt_DataSet_DataCacheBLL.SaveForever(_m.DataSet, ParamValues)); }
/// <summary> /// 获取数据源 /// </summary> /// <param name="ParamValue"></param> /// <param name="CacheTime"></param> /// <returns></returns> public DataTable GetData(Dictionary <string, object> ParamValue, bool LoadFromCache, out DateTime CacheTime) { DataTable dt = null; CacheTime = DateTime.Now; if (LoadFromCache) { dt = Rpt_DataSet_DataCacheBLL.LoadDataSetCache(_m.ID, ParamValue, out CacheTime); } if (dt == null || dt.Rows.Count == 0) { SqlParameter[] param = MakeParams(ParamValue); Rpt_DataSource source = new Rpt_DataSourceBLL(_m.DataSource).Model; string conn = ""; if (source.ConnectionString != "") { conn = MCSFramework.Common.DataEncrypter.DecryptData(source.ConnectionString); } switch (_m.CommandType) { case 1: dt = _dal.GetDataFromSQL(conn, _m.CommandText, param); break; case 2: dt = _dal.GetDataFromStoreProcedure(conn, _m.CommandText, param); break; case 3: Dictionary <string, Rpt_DataSetFields> dicTreeColumnList; dt = _dal.GetDataFromSQL(conn, GenarateSelectSQL(out dicTreeColumnList), param); #region 处理树形字段,显示指定层级的内容 for (int i = 0; i < dt.Columns.Count; i++) { DataColumn column = dt.Columns[i]; if (!dicTreeColumnList.ContainsKey(column.ColumnName)) { continue; } DataColumn newcolumn = dt.Columns.Add("_" + column.ColumnName, Type.GetType("System.String")); Rpt_DataSetFields field = dicTreeColumnList[column.ColumnName]; Dictionary <int, string> cachevalue = new Dictionary <int, string>(); foreach (DataRow row in dt.Rows) { int value = 0; if (int.TryParse(row[column].ToString(), out value)) { if (cachevalue.ContainsKey(value)) { row[newcolumn] = cachevalue[value]; } else { if (field.TreeLevel == 100) { //显示全路径 row[newcolumn] = TreeTableBLL.GetFullPathName(new UD_ModelFieldsBLL(field.FieldID, true).Model.RelationTableName, value); } else { //显示父级 if (field.DisplayMode == 1) { row[newcolumn] = TreeTableBLL.GetSuperIDByLevel(new UD_ModelFieldsBLL(field.FieldID, true).Model.RelationTableName, value, field.TreeLevel).ToString(); } else { row[newcolumn] = TreeTableBLL.GetSuperNameByLevel(new UD_ModelFieldsBLL(field.FieldID, true).Model.RelationTableName, value, field.TreeLevel); } } cachevalue.Add(value, row[newcolumn].ToString()); } } } int order = column.Ordinal; dt.Columns.Remove(column); newcolumn.SetOrdinal(order); newcolumn.ColumnName = newcolumn.ColumnName.Substring(1); } #endregion break; default: break; } if (_m.CommandType == 1 || _m.CommandType == 2) { #region 加入计算列字段 IList <Rpt_DataSetFields> computefields = this.GetFields().Where(p => p.IsComputeField == "Y").ToList(); foreach (Rpt_DataSetFields field in computefields) { Type ColumnType; switch (field.DataType) { case 1: //整型(int) ColumnType = Type.GetType("System.Int32"); break; case 2: //小数(decimal) ColumnType = Type.GetType("System.Decimal"); break; case 3: //字符串(varchar) case 6: //字符串(nvarchar) ColumnType = Type.GetType("System.String"); break; case 4: //日期(datetime) ColumnType = Type.GetType("System.DateTime"); break; case 5: //GUID(uniqueidentifier) ColumnType = Type.GetType("System.Guid"); break; default: ColumnType = Type.GetType("System.Decimal"); break; } try { dt.Columns.Add(field.FieldName, ColumnType, field.Expression); } catch { } } #endregion } if (dt != null && dt.Rows.Count < 200000) //只对20万行以下的数据表进行缓存 { try { Rpt_DataSet_DataCacheBLL.SaveDataSetCache(_m.ID, ParamValue, dt); CacheTime = DateTime.Now; } catch { System.GC.Collect(); } } } return(dt); }