/// <summary> /// 释放资源 /// </summary> protected override void Dispose(bool disposing) { if (disposing) { image = null; TranImage = null; TranLaterImage = null; } if (_tBrush != null) { _tBrush.Dispose(); _tBrush = null; } if (sTimer != null) { sTimer.Stop(); sTimer.Dispose(); } if (alpha != null) { alpha.Dispose(); alpha = null; } base.Dispose(disposing); }
/// <summary> /// 参数为true表示释放所有资源,只能由使用者调用 /// 参数为false表示释放非托管资源,只能由垃圾回收器自动调用 /// 如果子类有自己的非托管资源,可以重载这个函数,添加自己的非托管资源的释放 /// 但是要记住,重载此函数必须保证调用基类的版本,以保证基类的资源正常释放 /// </summary> protected virtual void Dispose(bool disposing) { // 如果资源未释放 // 这个判断主要用了防止对象被多次释放 if (!disposed) { // 标识此对象已释放 disposed = true; if (disposing) { // TODO: 释放托管资源(托管的对象)。 _image = null; Tag = null; Owner = null; } // TODO: 释放未托管资源(未托管的对象)并在以下内容中替代终结器。 // TODO: 将大型字段设置为 null。 // 未托管资源有: // ApplicationContext, Brush, Component, ComponentDesigner, Container, Context, Cursor, // FileStream, Font, Icon, Image, Matrix, Object, OdbcDataReader, OleDBDataReader, Pen, // Regex, Socket, StreamWriter, Timer, Tooltip, 文件句柄, GDI资源, 数据库连接等等资源。 if (_color != null) { _color.Dispose(); _color = null; } } }
public async Task <TProperties> GetAsync <TProperties>() where TProperties : PropertiesSet, new() { var properties = new TProperties(); var propertiesRecord = await LoadFromDatabaseAsync <TProperties>(); if (propertiesRecord != null) { properties = JsonConvert.DeserializeObject <TProperties>(propertiesRecord.Data); } return(properties); }
/// <summary> /// 验证排序与查询字段合法性 /// </summary> /// <param name="options"></param> /// <param name="queryable"></param> /// <returns></returns> private PageDataOptions ValidatePageOptions(PageDataOptions options, out IQueryable <Hiiops_Cart> queryable, List <SearchParameters> searchParametersList) { options = options ?? new PageDataOptions(); queryable = Instance.DbContext.Set <Hiiops_Cart>(); //判断列的数据类型数字,日期的需要判断值的格式是否正确 for (int i = 0; i < searchParametersList.Count; i++) { SearchParameters x = searchParametersList[i]; x.DisplayType = x.DisplayType.GetDBCondition(); if (string.IsNullOrEmpty(x.Value)) { // searchParametersList.Remove(x); continue; } PropertyInfo property = TProperties.Where(c => c.Name.ToUpper() == x.Name.ToUpper()).FirstOrDefault(); // property //移除查询的值与数据库类型不匹配的数据 // x.Value = string.Join(",", dbType.ValidationVal(x.Value.Split(',')).Where(q => q != "")); object[] values = property.ValidationValueForDbType(x.Value.Split(',')).Where(q => q.Item1).Select(s => s.Item3).ToArray(); // if (string.IsNullOrEmpty(x.Value)) if (values == null || values.Length == 0) { // searchParametersList.Remove(x); continue; } if (x.DisplayType == HtmlElementType.Contains) { x.Value = string.Join(",", values); } LinqExpressionType expressionType = x.DisplayType.GetLinqCondition(); queryable = LinqExpressionType.In == expressionType ? queryable.Where(x.Name.CreateExpression <Hiiops_Cart>(values, expressionType)) : queryable.Where(x.Name.CreateExpression <Hiiops_Cart>(x.Value, expressionType)); } // options.Wheres = searchParametersList.GetEntitySql(); return(options); }
/// <summary> /// 审核默认对应数据库字段为AuditId审核人ID ,AuditStatus审核状态,Auditor审核人,Auditdate审核时间,Auditreason审核原因 /// </summary> /// <param name="keys"></param> /// <param name="auditStatus"></param> /// <param name="auditReason"></param> /// <returns></returns> public virtual WebResponseContent Audit(object[] keys, int?auditStatus, string auditReason) { if (keys == null || keys.Length == 0) { return(Response.Error("未获取到参数!")); } if (auditStatus != 1 && auditStatus != 2) { return(Response.Error("请提求正确的审核结果!")); } //获取主键 PropertyInfo property = TProperties.GetKeyProperty(); if (property == null) { return(Response.Error("没有配置好主键!")); } UserInfo userInfo = UserContext.Current.UserInfo; //表如果有审核相关字段,设置默认审核 PropertyInfo[] updateFileds = TProperties.Where(x => auditFields.Contains(x.Name.ToLower())).ToArray(); List <T> auditList = new List <T>(); foreach (var value in keys) { object convertVal = value.ToString().ChangeType(property.PropertyType); if (convertVal == null) { continue; } T entity = Activator.CreateInstance <T>(); property.SetValue(entity, convertVal); foreach (var item in updateFileds) { switch (item.Name.ToLower()) { case "auditid": item.SetValue(entity, userInfo.User_Id); break; case "auditstatus": item.SetValue(entity, auditStatus); break; case "auditor": item.SetValue(entity, userInfo.UserTrueName); break; case "auditdate": item.SetValue(entity, DateTime.Now); break; case "auditreason": item.SetValue(entity, auditReason); break; } } auditList.Add(entity); } if (base.AuditOnExecuting != null) { Response = AuditOnExecuting(auditList); if (!Response.Status) { return(Response); } } repository.UpdateRange(auditList, updateFileds.Select(x => x.Name).ToArray(), true); if (base.AuditOnExecuted != null) { Response = AuditOnExecuted(auditList); if (!Response.Status) { return(Response); } } return(Response.OK(ResponseType.AuditSuccess)); }