internal static News[] GetNewsByAuthor(string author, LoadType loadType) { List <IMyDbParameter> prams = new List <IMyDbParameter>(); prams.Add(DbParameterProxy.Create("Author", SqlDbType.NVarChar, "%" + author + "%")); News[] objs = PersisterService.LoadObjects <News>("[Author] like @Author order by ReadingQuantity desc", prams.ToArray(), loadType); return(objs); }
internal static News[] GetNewsByType(NewsType type, LoadType loadType) { List <IMyDbParameter> prams = new List <IMyDbParameter>(); prams.Add(DbParameterProxy.Create("Type", SqlDbType.Int, (int)type)); News[] objs = PersisterService.LoadObjects <News>("[Type]=@Type", prams.ToArray(), loadType); return(objs); }
private T LoadObjectDataBaseDirect <T>(string alias, string tableName, string id, bool isNolock) where T : SRO, new() { Type type = typeof(T); IDbOperate dbOperate = DbProxy.Create(alias, type); IDataReader dataReader = null; try { string sql = string.Format(isNolock ? SELECTSINGLEOBJECTWITHNOLOCK : SELECTSINGLEOBJECT, tableName); IMyDbParameter[] prams = { DbParameterProxy.Create("@Id", SqlDbType.NVarChar, 32, id) }; dataReader = dbOperate.GetDataReader(sql, prams); if (!dataReader.Read()) { return(default(T)); } T obj = LoadObject <T>(dataReader); obj.CurrentAlias = alias; obj.CurrentTableName = tableName; return(obj); } catch (Exception ex) { LogProxy.Error(ex, true); throw; } finally { if (dataReader != null) { dataReader.Close(); } } }
private static QueryOutDTO QueryConstructor(Type type, string tableName, string orderBy, string columnList, QueryInDTO inDto, out DataView dataView) { QueryOutDTO outDto = new QueryOutDTO(); dataView = null; try { Dictionary <string, object> returnValue; IMyDbParameter[] prams = { DbParameterProxy.Create("@TableName", SqlDbType.NVarChar, 50, tableName), DbParameterProxy.Create("@OrderBy", SqlDbType.NVarChar, 500, orderBy), DbParameterProxy.Create("@ColumnList", SqlDbType.NVarChar, 500, columnList), DbParameterProxy.Create("@PageSize", SqlDbType.Int, inDto.PageSize), DbParameterProxy.Create("@PageIndex", SqlDbType.Int, inDto.PageIndex), DbParameterProxy.Create("@Condition", SqlDbType.NVarChar, 4000, inDto.Condition), DbParameterProxy.Create("@PageCount", SqlDbType.Int, ParameterDirection.Output), DbParameterProxy.Create("@RecordCount", SqlDbType.Int, ParameterDirection.Output) }; DataSet dataSet; IDbOperate dbOperate = DbProxy.Create(null, type); dbOperate.RunProcedure(PROPAGING, prams, out dataSet, out returnValue); dataView = dataSet.Tables[0].DefaultView; outDto.IsSucceed = true; outDto.PageCount = (int)returnValue["@PageCount"]; outDto.RecordCount = (int)returnValue["@RecordCount"]; } catch (Exception ex) { LogProxy.Error(ex, false); outDto.ErrorMsg = ex.Message; } return(outDto); }
private static IMyDbParameter ParameterBuilder(IMyPropertyInfo property, object pValue) { #region 构造 IMyDbParameter 开始 Type pType = property.PropertyType; if (pType == INTTYPE) { return(DbParameterProxy.Create(property.Name, SqlDbType.Int, pValue)); } else if (pType == BOOLTYPE) { return(DbParameterProxy.Create(property.Name, SqlDbType.Bit, pValue)); } else if (pType == STRINGTYPE) { if (property.StringDataType.Type == StringType.NVarchar) { if (property.StringDataType.IsMaxLength) { return(DbParameterProxy.Create(property.Name, SqlDbType.NVarChar, pValue)); } else { string val = pValue as string; if (!string.IsNullOrEmpty(val) && val.Length > property.StringDataType.Length) { LogProxy.Error(string.Format(LENGTHGAUGE, property.Name, val), true); } return(DbParameterProxy.Create(property.Name, SqlDbType.NVarChar, property.StringDataType.Length, pValue)); } } else { return(DbParameterProxy.Create(property.Name, SqlDbType.NText, pValue)); } } else if (pType == DATETIMETYPE) { if ((DateTime)pValue == DateTime.MinValue) { return(DbParameterProxy.Create(property.Name, SqlDbType.DateTime, DBNull.Value)); } else { return(DbParameterProxy.Create(property.Name, SqlDbType.DateTime, pValue)); } } else if (pType == DECIMALTYPE) { return(DbParameterProxy.Create(property.Name, SqlDbType.Decimal, pValue)); } else if (pType.IsEnum) { return(DbParameterProxy.Create(property.Name, SqlDbType.Int, (int)pValue)); } else if (pType == LONGTYPE) { return(DbParameterProxy.Create(property.Name, SqlDbType.BigInt, pValue)); } else if (pType == BYTESTYPE) { return(DbParameterProxy.Create(property.Name, SqlDbType.Image, pValue)); } else { LogProxy.ErrorFormat(true, DATATYPEERROR, pType.ToString()); return(null); } #endregion 构造 IMyDbParameter 结束 }
public static SRO LoadObject(Type type, string alias, string tableName, string id, LoadType loadType, bool isNolock) { if (string.IsNullOrEmpty(id)) { LogProxy.Error(IDISNULL, true); return(null); } if (loadType != LoadType.DataBaseDirect) { SRO obj = LoadCacheObject(type, id) as SRO; if (loadType == LoadType.OnlyCache) { return(obj); } if (obj != null) { return(obj); } } IDbOperate dbOperate = DbProxy.Create(alias, type); IDataReader dataReader = null; try { string sql = string.Format(isNolock ? SELECTSINGLEOBJECTWITHNOLOCK : SELECTSINGLEOBJECT, tableName); IMyDbParameter[] prams = { DbParameterProxy.Create("@Id", SqlDbType.NVarChar, 32, id) }; dataReader = dbOperate.GetDataReader(sql, prams); if (!dataReader.Read()) { return(null); } SRO obj = LoadObject(type, dataReader); if (obj == null) { return(null); } obj.CurrentAlias = alias; obj.CurrentTableName = tableName; return(obj); } catch (Exception ex) { LogProxy.Error(ex, true); throw; } finally { if (dataReader != null) { dataReader.Close(); } } }