コード例 #1
0
        public TerminalManagementViewModel(
            Warehouse defaultWarehouse,
            Employee driver,
            ITdiTab parentTab,
            IEmployeeRepository employeeRepository,
            IWarehouseRepository warehouseRepository,
            IRouteListRepository routeListRepository,
            ICommonServices commonServices,
            IUnitOfWork uow,
            ITerminalNomenclatureProvider terminalNomenclatureProvider)
        {
            UoW             = uow ?? throw new ArgumentNullException(nameof(uow));
            _driver         = driver ?? throw new ArgumentNullException(nameof(driver));
            _parentTab      = parentTab ?? throw new ArgumentNullException(nameof(parentTab));
            _commonServices = commonServices ?? throw new ArgumentNullException(nameof(commonServices));
            _terminalNomenclatureProvider =
                terminalNomenclatureProvider ?? throw new ArgumentNullException(nameof(terminalNomenclatureProvider));
            _employeeRepository  = employeeRepository ?? throw new ArgumentNullException(nameof(employeeRepository));
            _warehouseRepository = warehouseRepository ?? throw new ArgumentNullException(nameof(warehouseRepository));
            _routeListRepository = routeListRepository ?? throw new ArgumentNullException(nameof(routeListRepository));
            _defaultWarehouse    = defaultWarehouse;

            _author = _employeeRepository.GetEmployeeForCurrentUser(UoW);
            UpdateEntityAndRelatedProperties(
                _driver.Id > 0
                                ? _routeListRepository.GetLastTerminalDocumentForEmployee(UoW, _driver)
                                : null, false);
            _canManageTerminal = _commonServices.CurrentPermissionService.ValidatePresetPermission("role_сashier");
        }
コード例 #2
0
        private void ConfigureDlg()
        {
            btnCancel.Clicked                   += OnCancelClicked;
            printTimeButton.Clicked             += OnPrintTimeButtonClicked;
            ybuttonAddAdditionalLoad.Clicked    += OnButtonAddAdditionalLoadClicked;
            ybuttonRemoveAdditionalLoad.Clicked += OnButtonRemoveAdditionalLoadClicked;

            datepickerDate.Binding.AddBinding(Entity, e => e.Date, w => w.Date).InitializeFromSource();
            _previousSelectedDate             = Entity.Date;
            datepickerDate.DateChangedByUser += OnDatepickerDateDateChangedByUser;

            entityviewmodelentryCar.SetEntityAutocompleteSelectorFactory(new CarJournalFactory(MainClass.MainWin.NavigationManager).CreateCarAutocompleteSelectorFactory());
            entityviewmodelentryCar.Binding.AddBinding(Entity, e => e.Car, w => w.Subject).InitializeFromSource();
            entityviewmodelentryCar.CompletionPopupSetWidth(false);
            entityviewmodelentryCar.ChangedByUser += (sender, e) =>
            {
                if (Entity.Car == null || Entity.Date == default)
                {
                    evmeForwarder.IsEditable           = true;
                    ybuttonAddAdditionalLoad.Sensitive = false;
                    return;
                }

                ybuttonAddAdditionalLoad.Sensitive = true;
                var isCompanyCar = Entity.GetCarVersion.IsCompanyCar;

                Entity.Driver = Entity.Car.Driver != null && Entity.Car.Driver.Status != EmployeeStatus.IsFired
                                        ? Entity.Car.Driver
                                        : null;
                evmeDriver.Sensitive = Entity.Driver == null || isCompanyCar;

                if (!isCompanyCar || Entity.Car.CarModel.CarTypeOfUse == CarTypeOfUse.Largus && Entity.CanAddForwarder)
                {
                    Entity.Forwarder         = Entity.Forwarder;
                    evmeForwarder.IsEditable = true;
                }
                else
                {
                    Entity.Forwarder         = null;
                    evmeForwarder.IsEditable = false;
                }
            };

            var driverFilter = new EmployeeFilterViewModel();

            driverFilter.SetAndRefilterAtOnce(
                x => x.Status           = EmployeeStatus.IsWorking,
                x => x.RestrictCategory = EmployeeCategory.driver,
                x => x.CanChangeStatus  = false);
            var driverFactory = new EmployeeJournalFactory(driverFilter);

            evmeDriver.Changed += (sender, args) => lblDriverComment.Text = Entity.Driver?.Comment;
            evmeDriver.SetEntityAutocompleteSelectorFactory(driverFactory.CreateEmployeeAutocompleteSelectorFactory());
            evmeDriver.Binding.AddBinding(Entity, e => e.Driver, w => w.Subject).InitializeFromSource();

            hboxDriverComment.Binding
            .AddFuncBinding(Entity, e => e.Driver != null && !string.IsNullOrWhiteSpace(e.Driver.Comment), w => w.Visible)
            .InitializeFromSource();

            var forwarderFilter = new EmployeeFilterViewModel();

            forwarderFilter.SetAndRefilterAtOnce(
                x => x.Status           = EmployeeStatus.IsWorking,
                x => x.RestrictCategory = EmployeeCategory.forwarder,
                x => x.CanChangeStatus  = false);
            var forwarderFactory = new EmployeeJournalFactory(forwarderFilter);

            evmeForwarder.SetEntityAutocompleteSelectorFactory(forwarderFactory.CreateEmployeeAutocompleteSelectorFactory());
            evmeForwarder.Binding.AddBinding(Entity, e => e.Forwarder, w => w.Subject).InitializeFromSource();
            evmeForwarder.Changed += (sender, args) =>
            {
                createroutelistitemsview1.OnForwarderChanged();
                lblForwarderComment.Text = Entity.Forwarder?.Comment;
            };

            hboxForwarderComment.Binding
            .AddFuncBinding(Entity, e => e.Forwarder != null && !string.IsNullOrWhiteSpace(e.Forwarder.Comment), w => w.Visible)
            .InitializeFromSource();
            lblForwarderComment.Text = Entity.Forwarder?.Comment;

            var employeeFactory = new EmployeeJournalFactory();

            evmeLogistician.SetEntityAutocompleteSelectorFactory(employeeFactory.CreateEmployeeAutocompleteSelectorFactory());
            evmeLogistician.Sensitive = false;
            evmeLogistician.Binding.AddBinding(Entity, e => e.Logistician, w => w.Subject).InitializeFromSource();

            speccomboShift.ItemsList = _deliveryShiftRepository.ActiveShifts(UoW);
            speccomboShift.Binding.AddBinding(Entity, e => e.Shift, w => w.SelectedItem).InitializeFromSource();

            labelStatus.Binding.AddFuncBinding(Entity, e => e.Status.GetEnumTitle(), w => w.LabelProp).InitializeFromSource();

            evmeDriver.Sensitive = false;
            enumPrint.Sensitive  = Entity.Status != RouteListStatus.New;

            if (Entity.Id > 0)
            {
                //Нужно только для быстрой загрузки данных диалога. Проверено на МЛ из 200 заказов. Разница в скорости в несколько раз.
                var orders = UoW.Session.QueryOver <RouteListItem>()
                             .Where(x => x.RouteList == Entity)
                             .Fetch(x => x.Order).Eager
                             .Fetch(x => x.Order.OrderItems).Eager
                             .List();
            }

            _isLogistican = ServicesConfig.CommonServices.CurrentPermissionService.ValidatePresetPermission("logistican");
            createroutelistitemsview1.RouteListUoW = UoWGeneric;
            createroutelistitemsview1.SetPermissionParameters(permissionResult, _isLogistican);

            var additionalLoadingItemsViewModel =
                new AdditionalLoadingItemsViewModel(UoW, this, new NomenclatureJournalFactory(), ServicesConfig.InteractiveService);

            additionalLoadingItemsViewModel.BindWithSource(Entity, e => e.AdditionalLoadingDocument);
            additionalLoadingItemsViewModel.CanEdit  = Entity.Status == RouteListStatus.New;
            _additionalLoadingItemsView              = new AdditionalLoadingItemsView(additionalLoadingItemsViewModel);
            _additionalLoadingItemsView.WidthRequest = 300;
            _additionalLoadingItemsView.ShowAll();
            hboxAdditionalLoading.PackStart(_additionalLoadingItemsView, false, false, 0);

            buttonAccept.Visible = ybuttonAddAdditionalLoad.Visible = ybuttonRemoveAdditionalLoad.Visible =
                NotLoadedRouteListStatuses.Contains(Entity.Status);

            if (Entity.Status == RouteListStatus.InLoading || Entity.Status == RouteListStatus.Confirmed)
            {
                var icon = new Image
                {
                    Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-edit", IconSize.Menu)
                };
                buttonAccept.Image = icon;
                buttonAccept.Label = "Редактировать";
            }

            ggToStringWidget.UoW   = UoW;
            ggToStringWidget.Label = "Район города:";
            ggToStringWidget.Binding.AddBinding(Entity, x => x.ObservableGeographicGroups, x => x.Items).InitializeFromSource();

            enumPrint.ItemsEnum = typeof(RouteListPrintableDocuments);
            enumPrint.SetVisibility(RouteListPrintableDocuments.TimeList, false);
            enumPrint.SetVisibility(RouteListPrintableDocuments.OrderOfAddresses, false);
            bool IsLoadDocumentPrintable = ServicesConfig.CommonServices.CurrentPermissionService
                                           .ValidatePresetPermission("can_print_car_load_document");

            enumPrint.SetVisibility(RouteListPrintableDocuments.LoadDocument, IsLoadDocumentPrintable &&
                                    !(Entity.Status == RouteListStatus.Confirmed));
            enumPrint.EnumItemClicked += (sender, e) => PrintSelectedDocument((RouteListPrintableDocuments)e.ItemEnum);

            //Телефон
            phoneLogistican.MangoManager = phoneDriver.MangoManager = phoneForwarder.MangoManager = MainClass.MainWin.MangoManager;
            phoneLogistican.Binding.AddBinding(Entity, e => e.Logistician, w => w.Employee).InitializeFromSource();
            phoneDriver.Binding.AddBinding(Entity, e => e.Driver, w => w.Employee).InitializeFromSource();
            phoneForwarder.Binding.AddBinding(Entity, e => e.Forwarder, w => w.Employee).InitializeFromSource();

            var hasAccessToDriverTerminal = _isLogistican ||
                                            ServicesConfig.CommonServices.CurrentPermissionService.ValidatePresetPermission("role_сashier");
            var baseDoc = _routeListRepository.GetLastTerminalDocumentForEmployee(UoW, Entity.Driver);

            labelTerminalCondition.Visible = hasAccessToDriverTerminal &&
                                             baseDoc is DriverAttachedTerminalGiveoutDocument &&
                                             baseDoc.CreationDate.Date <= Entity?.Date;
            if (labelTerminalCondition.Visible)
            {
                labelTerminalCondition.LabelProp += $"{Entity.DriverTerminalCondition?.GetEnumTitle() ?? "неизвестно"}";
            }

            _canСreateRoutelistInPastPeriod = ServicesConfig.CommonServices.CurrentPermissionService.ValidatePresetPermission("can_create_routelist_in_past_period");

            _oldDriver = Entity.Driver;
            UpdateDlg(_isLogistican);

            Entity.PropertyChanged += OnRouteListPropertyChanged;
        }