void ConfigureDlg() { var editing = !UoW.IsNew && StoreDocumentHelper.CanEditDocument(WarehousePermissions.ShiftChangeEdit, Entity.Warehouse); var canCreate = UoW.IsNew && !StoreDocumentHelper.CheckCreateDocument(WarehousePermissions.ShiftChangeCreate, Entity.Warehouse); if (!canCreate && UoW.IsNew) { FailInitialize = true; return; } if (!editing && !UoW.IsNew) { MessageDialogWorks.RunWarningDialog("У вас нет прав на изменение этого документа."); } ydatepickerDocDate.Sensitive = yentryrefWarehouse.IsEditable = ytextviewCommnet.Editable = editing || canCreate; shiftchangewarehousedocumentitemsview1.Sensitive = editing || canCreate; ydatepickerDocDate.Binding.AddBinding(Entity, e => e.TimeStamp, w => w.Date).InitializeFromSource(); if (UoW.IsNew) { yentryrefWarehouse.ItemsQuery = StoreDocumentHelper.GetRestrictedWarehouseQuery(WarehousePermissions.ShiftChangeCreate); } if (!UoW.IsNew) { yentryrefWarehouse.ItemsQuery = StoreDocumentHelper.GetRestrictedWarehouseQuery(WarehousePermissions.ShiftChangeEdit); } yentryrefWarehouse.Binding.AddBinding(Entity, e => e.Warehouse, w => w.Subject).InitializeFromSource(); ytextviewCommnet.Binding.AddBinding(Entity, e => e.Comment, w => w.Buffer.Text).InitializeFromSource(); string errorMessage = "Не установлены единицы измерения у следующих номенклатур :" + Environment.NewLine; int wrongNomenclatures = 0; foreach (var item in UoWGeneric.Root.Items) { if (item.Nomenclature.Unit == null) { errorMessage += string.Format("Номер: {0}. Название: {1}{2}", item.Nomenclature.Id, item.Nomenclature.Name, Environment.NewLine); wrongNomenclatures++; } } if (wrongNomenclatures > 0) { MessageDialogWorks.RunErrorDialog(errorMessage); FailInitialize = true; return; } shiftchangewarehousedocumentitemsview1.DocumentUoW = UoWGeneric; }
void ConfigureDlg() { canEdit = !UoW.IsNew && StoreDocumentHelper.CanEditDocument(WarehousePermissions.ShiftChangeEdit, Entity.Warehouse); if (Entity.Id != 0 && Entity.TimeStamp < DateTime.Today) { var permissionValidator = new EntityExtendedPermissionValidator(PermissionExtensionSingletonStore.GetInstance(), _employeeRepository); canEdit &= permissionValidator.Validate( typeof(ShiftChangeWarehouseDocument), ServicesConfig.UserService.CurrentUserId, nameof(RetroactivelyClosePermission)); } canCreate = UoW.IsNew && !StoreDocumentHelper.CheckCreateDocument(WarehousePermissions.ShiftChangeCreate, Entity.Warehouse); if (!canCreate && UoW.IsNew) { FailInitialize = true; return; } if (!canEdit && !UoW.IsNew) { MessageDialogHelper.RunWarningDialog("У вас нет прав на изменение этого документа."); } ydatepickerDocDate.Sensitive = yentryrefWarehouse.IsEditable = ytextviewCommnet.Editable = canEdit || canCreate; ytreeviewNomenclatures.Sensitive = buttonFillItems.Sensitive = buttonAdd.Sensitive = canEdit || canCreate; ytreeviewNomenclatures.ItemsDataSource = Entity.ObservableItems; ytreeviewNomenclatures.YTreeModel?.EmitModelChanged(); ydatepickerDocDate.Binding.AddBinding(Entity, e => e.TimeStamp, w => w.Date).InitializeFromSource(); if (UoW.IsNew) { yentryrefWarehouse.ItemsQuery = StoreDocumentHelper.GetRestrictedWarehouseQuery(WarehousePermissions.ShiftChangeCreate); } if (!UoW.IsNew) { yentryrefWarehouse.ItemsQuery = StoreDocumentHelper.GetRestrictedWarehouseQuery(WarehousePermissions.ShiftChangeEdit); } yentryrefWarehouse.Binding.AddBinding(Entity, e => e.Warehouse, w => w.Subject).InitializeFromSource(); yentryrefWarehouse.Changed += OnWarehouseChanged; ytextviewCommnet.Binding.AddBinding(Entity, e => e.Comment, w => w.Buffer.Text).InitializeFromSource(); string errorMessage = "Не установлены единицы измерения у следующих номенклатур :" + Environment.NewLine; int wrongNomenclatures = 0; foreach (var item in Entity.Items) { if (item.Nomenclature.Unit == null) { errorMessage += string.Format("Номер: {0}. Название: {1}{2}", item.Nomenclature.Id, item.Nomenclature.Name, Environment.NewLine); wrongNomenclatures++; } } if (wrongNomenclatures > 0) { MessageDialogHelper.RunErrorDialog(errorMessage); FailInitialize = true; return; } filter = new SelectableParametersReportFilter(UoW); var nomenclatureParam = filter.CreateParameterSet( "Номенклатуры", "nomenclature", new ParametersFactory(UoW, (filters) => { SelectableEntityParameter <Nomenclature> resultAlias = null; var query = UoW.Session.QueryOver <Nomenclature>() .Where(x => !x.IsArchive); if (filters != null && filters.Any()) { foreach (var f in filters) { var filterCriterion = f(); if (filterCriterion != null) { query.Where(filterCriterion); } } } query.SelectList(list => list .Select(x => x.Id).WithAlias(() => resultAlias.EntityId) .Select(x => x.OfficialName).WithAlias(() => resultAlias.EntityTitle) ); query.TransformUsing(Transformers.AliasToBean <SelectableEntityParameter <Nomenclature> >()); return(query.List <SelectableParameter>()); }) ); var nomenclatureTypeParam = filter.CreateParameterSet( "Типы номенклатур", "nomenclature_type", new ParametersEnumFactory <NomenclatureCategory>() ); nomenclatureParam.AddFilterOnSourceSelectionChanged(nomenclatureTypeParam, () => { var selectedValues = nomenclatureTypeParam.GetSelectedValues(); if (!selectedValues.Any()) { return(null); } return(Restrictions.On <Nomenclature>(x => x.Category).IsIn(nomenclatureTypeParam.GetSelectedValues().ToArray())); } ); //Предзагрузка. Для избежания ленивой загрузки UoW.Session.QueryOver <ProductGroup>().Fetch(SelectMode.Fetch, x => x.Childs).List(); filter.CreateParameterSet( "Группы товаров", "product_group", new RecursiveParametersFactory <ProductGroup>(UoW, (filters) => { var query = UoW.Session.QueryOver <ProductGroup>(); if (filters != null && filters.Any()) { foreach (var f in filters) { query.Where(f()); } } return(query.List()); }, x => x.Name, x => x.Childs) ); var filterViewModel = new SelectableParameterReportFilterViewModel(filter); var filterWidget = new SelectableParameterReportFilterView(filterViewModel); vboxParameters.Add(filterWidget); filterWidget.Show(); ConfigureNomenclaturesView(); }