private void ReCreateMenuParam() { var sql = @" SELECT FileName=b.Name,a.ClassName FROM dbo.sysBusinessView a WITH(NOLOCK) LEFT JOIN dbo.sysFile b WITH(NOLOCK) ON a.FileId=b.Iden WHERE a.Iden=:Iden"; var viewId = this.ViewModel.MainEntitySet.CurrentEntity.BusinessViewId; var esView = new EntitySet<QueryEntity>(); esView.Query(sql,viewId); if (esView.IsEmpty()) return; var entity = esView.First(); var fileName = entity.GetFieldValue<string>("FileName"); if (fileName.IsEmpty()) return; var typeName = entity.GetFieldValue<string>("ClassName"); if (typeName.IsEmpty()) return; var dllFile = Path.Combine(Application.StartupPath, fileName); if (!File.Exists(dllFile)) return; AppDomain ad = AppDomain.CreateDomain("sysMenuView Test DLL Marked ViewParameterAttribute"); try { LoadAssemblyProxyObject obj = (LoadAssemblyProxyObject)ad.CreateInstanceFromAndUnwrap(LoadAssemblyProxyObject.AssemblyFileName, LoadAssemblyProxyObject.ProxyObjectTypeName); if (!Path.GetExtension(fileName).Equals(".dll", StringComparison.InvariantCultureIgnoreCase) && !Path.GetExtension(fileName).Equals(".exe", StringComparison.InvariantCultureIgnoreCase)) return; obj.LoadAssembly(dllFile); var types = obj.GetType(typeName); if (types == null) return; var list = types.GetAllPropertyMarked<ViewParameterAttribute>(); if (list.IsEmpty()) return; var deleteList = this.ViewModel.MenuParamEntitySet.Where(p => !p.Name.In(list.Select(x => x.Name))); foreach (var item in deleteList) { item.Delete(); } foreach (var item in list) { var attr = item.GetCustomAttribute<ViewParameterAttribute>(); var param = this.ViewModel.MenuParamEntitySet.FirstOrDefault(p => p.Name == item.Name); if (param == null) { param = this.ViewModel.MenuParamEntitySet.AddNew(); param.Iden = IdenGenerator.NewIden(param.IdenGroup); param.MenuId = this.ViewModel.MainEntitySet.CurrentEntity.Iden; param.Value = string.Empty; } param.Name = item.Name; param.ControlType = (int)attr.ControlType; param.Description = attr.Desctiption; param.Category = attr.Category; } this.grvParams.RefreshData(); this.grvParams.BestFitColumns(); } finally { AppDomain.Unload(ad); } }
protected override void OnInitViewParam() { base.OnInitViewParam(); var es = new EntitySet<QueryEntity>(); if (DataPortal.TableIsExists(es.ConnectionName, "[dbo].[sysMenuParam]")) { es.Query("SELECT Name,[Value] FROM [dbo].[sysMenuParam] with(nolock) WHERE [MenuId]=:MenuId", this.UniqueId); if (!es.IsEmpty()) { foreach (var entity in es) { this.ViewParameters[entity.GetFieldValue<string>("Name")] = entity.GetFieldValue<string>("Value"); } } } }