Exemple #1
0
        private void Configure()
        {
            table1.Sensitive = false;

            buttonSave.Clicked   += (sender, e) => Save();
            buttonCancel.Clicked += (sender, e) => ViewModel.Close(false, QS.Navigation.CloseSource.Cancel);

            entityVMEntryCar.SetEntityAutocompleteSelectorFactory(
                new DefaultEntityAutocompleteSelectorFactory <Car, CarJournalViewModel, CarJournalFilterViewModel>(ServicesConfig.CommonServices));
            entityVMEntryCar.Binding.AddBinding(ViewModel.Entity, e => e.Car, w => w.Subject).InitializeFromSource();
            entityVMEntryCar.CompletionPopupSetWidth(false);

            entityVMEntryDriver.SetEntityAutocompleteSelectorFactory(ViewModel.DriverSelectorFactory);
            entityVMEntryDriver.Binding.AddBinding(ViewModel.Entity, e => e.Driver, w => w.Subject).InitializeFromSource();

            entityVMEntryForwarder.SetEntityAutocompleteSelectorFactory(ViewModel.ForwarderSelectorFactory);
            entityVMEntryForwarder.Binding.AddBinding(ViewModel.Entity, e => e.Forwarder, w => w.Subject).InitializeFromSource();

            entityVMEntryLogistician.SetEntityAutocompleteSelectorFactory(ViewModel.LogisticanSelectorFactory);
            entityVMEntryLogistician.Binding.AddBinding(ViewModel.Entity, rl => rl.Logistician, w => w.Subject).InitializeFromSource();

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

            datePickerDate.Binding.AddBinding(ViewModel.Entity, e => e.Date, w => w.Date).InitializeFromSource();

            ytextviewLogisticianComment.Binding.AddBinding(ViewModel.Entity, e => e.LogisticiansComment, w => w.Buffer.Text).InitializeFromSource();

            ConfigureTreeViewAddresses();

            //Заполняем телефоны
            FillPhones();

            //Заполняем информацию о бутылях
            UpdateBottlesSummaryInfo();

            ViewModel.UpdateTreeAddresses += UpdateTreeAddresses;
        }
        public void ConfigureDlg()
        {
            Entity.ObservableAddresses.ElementAdded   += ObservableAddresses_ElementAdded;
            Entity.ObservableAddresses.ElementRemoved += ObservableAddresses_ElementRemoved;
            Entity.ObservableAddresses.ElementChanged += ObservableAddresses_ElementChanged;;

            referenceCar.SubjectType = typeof(Car);
            referenceCar.ItemsQuery  = CarRepository.ActiveCarsQuery();
            referenceCar.Binding.AddBinding(Entity, rl => rl.Car, widget => widget.Subject).InitializeFromSource();
            referenceCar.Sensitive = logisticanEditing;

            var filterDriver = new EmployeeFilter(UoW);

            filterDriver.SetAndRefilterAtOnce(x => x.RestrictCategory = EmployeeCategory.driver);
            referenceDriver.RepresentationModel = new EmployeesVM(filterDriver);
            referenceDriver.Binding.AddBinding(Entity, rl => rl.Driver, widget => widget.Subject).InitializeFromSource();
            referenceDriver.Sensitive = logisticanEditing;
            var filterForwarder = new EmployeeFilter(UoW);

            filterForwarder.SetAndRefilterAtOnce(x => x.RestrictCategory = EmployeeCategory.forwarder);
            referenceForwarder.RepresentationModel = new EmployeesVM(filterForwarder);
            referenceForwarder.Binding.AddBinding(Entity, rl => rl.Forwarder, widget => widget.Subject).InitializeFromSource();
            referenceForwarder.Sensitive = logisticanEditing;
            referenceForwarder.Changed  += ReferenceForwarder_Changed;

            var filterLogistican = new EmployeeFilter(UoW);

            filterLogistican.SetAndRefilterAtOnce(x => x.ShowFired = false);
            referenceLogistican.RepresentationModel = new EmployeesVM(filterLogistican);
            referenceLogistican.Binding.AddBinding(Entity, rl => rl.Logistican, widget => widget.Subject).InitializeFromSource();
            referenceLogistican.Sensitive = logisticanEditing;

            speccomboShift.ItemsList = DeliveryShiftRepository.ActiveShifts(UoW);
            speccomboShift.Binding.AddBinding(Entity, rl => rl.Shift, widget => widget.SelectedItem).InitializeFromSource();
            speccomboShift.Sensitive = logisticanEditing;

            yspinActualDistance.Binding.AddBinding(Entity, rl => rl.ActualDistance, widget => widget.ValueAsDecimal).InitializeFromSource();
            yspinActualDistance.Sensitive = logisticanEditing;

            datePickerDate.Binding.AddBinding(Entity, rl => rl.Date, widget => widget.Date).InitializeFromSource();
            datePickerDate.Sensitive = logisticanEditing;

            ylabelLastTimeCall.Binding.AddFuncBinding(Entity, e => GetLastCallTime(e.LastCallTime), w => w.LabelProp).InitializeFromSource();

            buttonMadeCall.Sensitive = allEditing;

            buttonRetriveEnRoute.Sensitive = Entity.Status == RouteListStatus.OnClosing && isUserLogist;

            //Заполняем иконки
            var ass = Assembly.GetAssembly(typeof(MainClass));

            statusIcons.Add(RouteListItemStatus.EnRoute, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.car.png"));
            statusIcons.Add(RouteListItemStatus.Completed, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.face-smile-grin.png"));
            statusIcons.Add(RouteListItemStatus.Overdue, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.face-angry.png"));
            statusIcons.Add(RouteListItemStatus.Canceled, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.face-crying.png"));
            statusIcons.Add(RouteListItemStatus.Transfered, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.face-uncertain.png"));

            ytreeviewAddresses.ColumnsConfig = ColumnsConfigFactory.Create <RouteListKeepingItemNode>()
                                               .AddColumn("№ п/п").AddNumericRenderer(x => x.RouteListItem.IndexInRoute + 1)
                                               .AddColumn("Заказ")
                                               .AddTextRenderer(node => node.RouteListItem.Order.Id.ToString())
                                               .AddColumn("Адрес")
                                               .AddTextRenderer(node => node.RouteListItem.Order.DeliveryPoint == null ? "Требуется точка доставки" : node.RouteListItem.Order.DeliveryPoint.ShortAddress)
                                               .AddColumn("Время")
                                               .AddTextRenderer(node => node.RouteListItem.Order.DeliverySchedule == null ? "" : node.RouteListItem.Order.DeliverySchedule.Name)
                                               .AddColumn("Статус")
                                               .AddPixbufRenderer(x => statusIcons[x.Status])
                                               .AddEnumRenderer(node => node.Status, excludeItems: new Enum [] { RouteListItemStatus.Transfered })
                                               .AddSetter((c, n) => c.Editable = allEditing && n.Status != RouteListItemStatus.Transfered)
                                               .AddColumn("Отгрузка")
                                               .AddNumericRenderer(node => node.RouteListItem.Order.OrderItems
                                                                   .Where(b => b.Nomenclature.Category == NomenclatureCategory.water && b.Nomenclature.TareVolume == TareVolume.Vol19L)
                                                                   .Sum(b => b.Count))
                                               .AddColumn("Возврат тары")
                                               .AddNumericRenderer(node => node.RouteListItem.Order.BottlesReturn)
                                               .AddColumn("Сдали по факту")
                                               .AddNumericRenderer(node => node.RouteListItem.DriverBottlesReturned)
                                               .AddColumn("Статус изменен")
                                               .AddTextRenderer(node => node.LastUpdate)
                                               .AddColumn("Комментарий")
                                               .AddTextRenderer(node => node.Comment)
                                               .Editable(allEditing)
                                               .AddColumn("Переносы")
                                               .AddTextRenderer(node => node.Transferred)
                                               .RowCells()
                                               .AddSetter <CellRenderer> ((cell, node) => cell.CellBackgroundGdk = node.RowColor)
                                               .Finish();
            ytreeviewAddresses.Selection.Mode     = SelectionMode.Multiple;
            ytreeviewAddresses.Selection.Changed += OnSelectionChanged;
            ytreeviewAddresses.Sensitive          = allEditing;
            ytreeviewAddresses.RowActivated      += YtreeviewAddresses_RowActivated;

            //Заполняем телефоны
            string phones = null;

            if (Entity.Driver != null && Entity.Driver.Phones.Count > 0)
            {
                phones = String.Format("<b>Водитель {0}:</b>\n{1}",
                                       Entity.Driver.FullName,
                                       String.Join("\n", Entity.Driver.Phones));
            }
            if (Entity.Forwarder != null && Entity.Forwarder.Phones.Count > 0)
            {
                if (!string.IsNullOrWhiteSpace(phones))
                {
                    phones += "\n";
                }
                phones += String.Format("<b>Экспедитор {0}:</b>\n{1}",
                                        Entity.Forwarder.FullName,
                                        String.Join("\n", Entity.Forwarder.Phones));
            }

            if (string.IsNullOrWhiteSpace(phones))
            {
                phones = "Нет телефонов";
            }
            labelPhonesInfo.Markup = phones;

            //Заполняем информацию о бутылях
            UpdateBottlesSummaryInfo();


            UpdateNodes();
        }
        public void ConfigureDlg()
        {
            Entity.ObservableAddresses.ElementAdded   += ObservableAddresses_ElementAdded;
            Entity.ObservableAddresses.ElementRemoved += ObservableAddresses_ElementRemoved;
            Entity.ObservableAddresses.ElementChanged += ObservableAddresses_ElementChanged;;

            entityviewmodelentryCar.SetEntityAutocompleteSelectorFactory(
                new DefaultEntityAutocompleteSelectorFactory <Car, CarJournalViewModel, CarJournalFilterViewModel>(ServicesConfig.CommonServices));
            entityviewmodelentryCar.Binding.AddBinding(Entity, e => e.Car, w => w.Subject).InitializeFromSource();
            entityviewmodelentryCar.CompletionPopupSetWidth(false);
            entityviewmodelentryCar.Sensitive = logisticanEditing;

            var filterDriver = new EmployeeFilterViewModel();

            filterDriver.SetAndRefilterAtOnce(
                x => x.RestrictCategory = EmployeeCategory.driver,
                x => x.Status           = EmployeeStatus.IsWorking
                );
            referenceDriver.RepresentationModel = new EmployeesVM(filterDriver);
            referenceDriver.Binding.AddBinding(Entity, rl => rl.Driver, widget => widget.Subject).InitializeFromSource();
            referenceDriver.Sensitive = logisticanEditing;
            var filterForwarder = new EmployeeFilterViewModel();

            filterForwarder.SetAndRefilterAtOnce(
                x => x.RestrictCategory = EmployeeCategory.forwarder,
                x => x.Status           = EmployeeStatus.IsWorking
                );
            referenceForwarder.RepresentationModel = new EmployeesVM(filterForwarder);
            referenceForwarder.Binding.AddBinding(Entity, rl => rl.Forwarder, widget => widget.Subject).InitializeFromSource();
            referenceForwarder.Sensitive = logisticanEditing;
            referenceForwarder.Changed  += ReferenceForwarder_Changed;

            referenceLogistican.RepresentationModel = new EmployeesVM();
            referenceLogistican.Binding.AddBinding(Entity, rl => rl.Logistician, widget => widget.Subject).InitializeFromSource();
            referenceLogistican.Sensitive = logisticanEditing;

            speccomboShift.ItemsList = DeliveryShiftRepository.ActiveShifts(UoW);
            speccomboShift.Binding.AddBinding(Entity, rl => rl.Shift, widget => widget.SelectedItem).InitializeFromSource();
            speccomboShift.Sensitive = logisticanEditing;

            datePickerDate.Binding.AddBinding(Entity, rl => rl.Date, widget => widget.Date).InitializeFromSource();
            datePickerDate.Sensitive = logisticanEditing;

            ylabelLastTimeCall.Binding.AddFuncBinding(Entity, e => GetLastCallTime(e.LastCallTime), w => w.LabelProp).InitializeFromSource();
            yspinActualDistance.Sensitive = allEditing;

            buttonMadeCall.Sensitive = allEditing;

            buttonRetriveEnRoute.Sensitive = Entity.Status == RouteListStatus.OnClosing && isUserLogist &&
                                             ServicesConfig.CommonServices.CurrentPermissionService.ValidatePresetPermission("can_retrieve_routelist_en_route");

            buttonNewFine.Sensitive = allEditing;

            buttonRefresh.Sensitive = allEditing;

            //Заполняем иконки
            var ass = Assembly.GetAssembly(typeof(MainClass));

            statusIcons.Add(RouteListItemStatus.EnRoute, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.car.png"));
            statusIcons.Add(RouteListItemStatus.Completed, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.face-smile-grin.png"));
            statusIcons.Add(RouteListItemStatus.Overdue, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.face-angry.png"));
            statusIcons.Add(RouteListItemStatus.Canceled, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.face-crying.png"));
            statusIcons.Add(RouteListItemStatus.Transfered, new Gdk.Pixbuf(ass, "Vodovoz.icons.status.face-uncertain.png"));

            ytreeviewAddresses.ColumnsConfig = ColumnsConfigFactory.Create <RouteListKeepingItemNode>()
                                               .AddColumn("№ п/п").AddNumericRenderer(x => x.RouteListItem.IndexInRoute + 1)
                                               .AddColumn("Заказ")
                                               .AddTextRenderer(node => node.RouteListItem.Order.Id.ToString())
                                               .AddColumn("Адрес")
                                               .AddTextRenderer(node => node.RouteListItem.Order.DeliveryPoint == null ? "Требуется точка доставки" : node.RouteListItem.Order.DeliveryPoint.ShortAddress)
                                               .AddColumn("Время")
                                               .AddTextRenderer(node => node.RouteListItem.Order.DeliverySchedule == null ? "" : node.RouteListItem.Order.DeliverySchedule.Name)
                                               .AddColumn("Статус")
                                               .AddPixbufRenderer(x => statusIcons[x.Status])
                                               .AddEnumRenderer(node => node.Status, excludeItems: new Enum[] { RouteListItemStatus.Transfered })
                                               .AddSetter((c, n) => c.Editable = allEditing && n.Status != RouteListItemStatus.Transfered)
                                               .AddColumn("Отгрузка")
                                               .AddNumericRenderer(node => node.RouteListItem.Order.OrderItems
                                                                   .Where(b => b.Nomenclature.Category == NomenclatureCategory.water && b.Nomenclature.TareVolume == TareVolume.Vol19L)
                                                                   .Sum(b => b.Count))
                                               .AddColumn("Возврат тары")
                                               .AddNumericRenderer(node => node.RouteListItem.Order.BottlesReturn)
                                               .AddColumn("Сдали по факту")
                                               .AddNumericRenderer(node => node.RouteListItem.DriverBottlesReturned)
                                               .AddColumn("Статус изменен")
                                               .AddTextRenderer(node => node.LastUpdate)
                                               .AddColumn("Комментарий")
                                               .AddTextRenderer(node => node.Comment)
                                               .Editable(allEditing)
                                               .AddColumn("Переносы")
                                               .AddTextRenderer(node => node.Transferred)
                                               .RowCells()
                                               .AddSetter <CellRenderer>((cell, node) => cell.CellBackgroundGdk = node.RowColor)
                                               .Finish();
            ytreeviewAddresses.Selection.Mode     = SelectionMode.Multiple;
            ytreeviewAddresses.Selection.Changed += OnSelectionChanged;
            ytreeviewAddresses.Sensitive          = allEditing;
            ytreeviewAddresses.RowActivated      += YtreeviewAddresses_RowActivated;

            //Point!
            //Заполняем телефоны

            if (Entity.Driver != null && Entity.Driver.Phones.Count > 0)
            {
                uint rows = Convert.ToUInt32(Entity.Driver.Phones.Count + 1);
                PhonesTable1.Resize(rows, 2);
                Label label = new Label();
                label.LabelProp = $"{Entity.Driver.FullName}";
                PhonesTable1.Attach(label, 0, 2, 0, 1);

                for (uint i = 1; i < rows; i++)
                {
                    Label l = new Label();
                    l.LabelProp = "+7 " + Entity.Driver.Phones[Convert.ToInt32(i - 1)].Number;
                    PhonesTable1.Attach(l, 0, 1, i, i + 1);

                    HandsetView h = new HandsetView(Entity.Driver.Phones[Convert.ToInt32(i - 1)].DigitsNumber);
                    PhonesTable1.Attach(h, 1, 2, i, i + 1);
                }
            }
            if (Entity.Forwarder != null && Entity.Forwarder.Phones.Count > 0)
            {
                uint rows = Convert.ToUInt32(Entity.Forwarder.Phones.Count + 1);
                PhonesTable2.Resize(rows, 2);
                Label label = new Label();
                label.LabelProp = $"{Entity.Forwarder.FullName}";
                PhonesTable2.Attach(label, 0, 2, 0, 1);

                for (uint i = 1; i < rows; i++)
                {
                    Label l = new Label();
                    l.LabelProp = "+7 " + Entity.Forwarder.Phones[Convert.ToInt32(i - 1)].Number;
                    PhonesTable2.Attach(l, 0, 1, i, i + 1);

                    HandsetView h = new HandsetView(Entity.Forwarder.Phones[Convert.ToInt32(i - 1)].DigitsNumber);
                    PhonesTable2.Attach(h, 1, 2, i, i + 1);
                }
            }

            //Телефон
            PhonesTable1.ShowAll();
            PhonesTable2.ShowAll();

            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();

            //Заполняем информацию о бутылях
            UpdateBottlesSummaryInfo();

            UpdateNodes();
        }
Exemple #4
0
        public void ConfigureDlg()
        {
            HasChanges = true;
            if (!editing)
            {
                MessageDialogHelper.RunWarningDialog("Не достаточно прав. Обратитесь к руководителю.");
                HasChanges        = false;
                vbxMain.Sensitive = false;
            }

            buttonAcceptFine.Clicked += ButtonAcceptFineOnClicked;

            entityviewmodelentryCar.SetEntityAutocompleteSelectorFactory(
                new DefaultEntityAutocompleteSelectorFactory <Car, CarJournalViewModel, CarJournalFilterViewModel>(ServicesConfig.CommonServices));
            entityviewmodelentryCar.Binding.AddBinding(Entity, e => e.Car, w => w.Subject).InitializeFromSource();
            entityviewmodelentryCar.CompletionPopupSetWidth(false);

            referenceDriver.Binding.AddBinding(Entity, rl => rl.Driver, widget => widget.Subject).InitializeFromSource();

            referenceForwarder.Binding.AddBinding(Entity, rl => rl.Forwarder, widget => widget.Subject).InitializeFromSource();

            referenceLogistican.RepresentationModel = new EmployeesVM();
            referenceLogistican.Binding.AddBinding(Entity, rl => rl.Logistician, widget => widget.Subject).InitializeFromSource();

            speccomboShift.ItemsList = DeliveryShiftRepository.ActiveShifts(UoWGeneric);
            speccomboShift.Binding.AddBinding(Entity, rl => rl.Shift, widget => widget.SelectedItem).InitializeFromSource();

            datePickerDate.Binding.AddBinding(Entity, rl => rl.Date, widget => widget.Date).InitializeFromSource();

            yspinConfirmedDistance.Binding.AddBinding(Entity, rl => rl.ConfirmedDistance, widget => widget.ValueAsDecimal).InitializeFromSource();

            yentryRecalculatedDistance.Binding.AddBinding(Entity, rl => rl.RecalculatedDistance, widget => widget.Text, new DecimalToStringConverter()).InitializeFromSource();

            ytreeviewAddresses.ColumnsConfig = ColumnsConfigFactory.Create <RouteListKeepingItemNode>()
                                               .AddColumn("Заказ")
                                               .AddTextRenderer(node => node.RouteListItem.Order.Id.ToString())
                                               .AddColumn("Адрес")
                                               .AddTextRenderer(node => String.Format("{0} д.{1}", node.RouteListItem.Order.DeliveryPoint.Street, node.RouteListItem.Order.DeliveryPoint.Building))
                                               .AddColumn("Время")
                                               .AddTextRenderer(node => node.RouteListItem.Order.DeliverySchedule == null ? "" : node.RouteListItem.Order.DeliverySchedule.Name)
                                               .AddColumn("Статус")
                                               .AddEnumRenderer(node => node.Status).Editing(false)
                                               .AddColumn("Последнее редактирование")
                                               .AddTextRenderer(node => node.LastUpdate)
                                               .RowCells()
                                               .AddSetter <CellRenderer>((cell, node) => cell.CellBackgroundGdk = node.RowColor)
                                               .Finish();

            items = new List <RouteListKeepingItemNode>();
            foreach (var item in Entity.Addresses)
            {
                items.Add(new RouteListKeepingItemNode {
                    RouteListItem = item
                });
            }

            items.Sort((x, y) => {
                if (x.RouteListItem.StatusLastUpdate.HasValue && y.RouteListItem.StatusLastUpdate.HasValue)
                {
                    if (x.RouteListItem.StatusLastUpdate > y.RouteListItem.StatusLastUpdate)
                    {
                        return(1);
                    }
                    if (x.RouteListItem.StatusLastUpdate < y.RouteListItem.StatusLastUpdate)
                    {
                        return(-1);
                    }
                }
                return(0);
            });

            ytreeviewAddresses.ItemsDataSource = items;
            ytextviewMileageComment.Binding.AddBinding(Entity, x => x.MileageComment, w => w.Buffer.Text).InitializeFromSource();

            if (Entity.Status == RouteListStatus.Closed)
            {
                vboxRouteList.Sensitive = table2.Sensitive = false;
            }
            else
            {
                RecountMileage();
            }

            //Телефон
            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();
        }
        public void ConfigureDlg()
        {
            referenceCar.SubjectType = typeof(Car);
            referenceCar.ItemsQuery  = CarRepository.ActiveCarsQuery();
            referenceCar.Binding.AddBinding(Entity, rl => rl.Car, widget => widget.Subject).InitializeFromSource();
            referenceCar.Sensitive = false;

            referenceDriver.Binding.AddBinding(Entity, rl => rl.Driver, widget => widget.Subject).InitializeFromSource();
            referenceDriver.Sensitive = false;

            referenceForwarder.Binding.AddBinding(Entity, rl => rl.Forwarder, widget => widget.Subject).InitializeFromSource();
            referenceForwarder.Sensitive = false;

            var filterLogistican = new EmployeeFilter(UoW);

            filterLogistican.ShowFired = false;
            referenceLogistican.RepresentationModel = new EmployeesVM(filterLogistican);
            referenceLogistican.Binding.AddBinding(Entity, rl => rl.Logistican, widget => widget.Subject).InitializeFromSource();
            referenceLogistican.Sensitive = editing;

            speccomboShift.ItemsList = DeliveryShiftRepository.ActiveShifts(UoWGeneric);
            speccomboShift.Binding.AddBinding(Entity, rl => rl.Shift, widget => widget.SelectedItem).InitializeFromSource();
            speccomboShift.Sensitive = editing;

            yspinActualDistance.Binding.AddBinding(Entity, rl => rl.ActualDistance, widget => widget.ValueAsDecimal).InitializeFromSource();
            yspinActualDistance.Sensitive = false;

            datePickerDate.Binding.AddBinding(Entity, rl => rl.Date, widget => widget.Date).InitializeFromSource();
            datePickerDate.Sensitive = editing;

            yspinConfirmedDistance.Binding.AddBinding(Entity, rl => rl.ConfirmedDistance, widget => widget.ValueAsDecimal).InitializeFromSource();
            yspinConfirmedDistance.Sensitive = editing && Entity.Status != RouteListStatus.Closed;
            buttonConfirm.Sensitive          = editing && Entity.Status != RouteListStatus.Closed;

            ytreeviewAddresses.ColumnsConfig = ColumnsConfigFactory.Create <RouteListKeepingItemNode>()
                                               .AddColumn("Заказ")
                                               .AddTextRenderer(node => node.RouteListItem.Order.Id.ToString())
                                               .AddColumn("Адрес")
                                               .AddTextRenderer(node => String.Format("{0} д.{1}", node.RouteListItem.Order.DeliveryPoint.Street, node.RouteListItem.Order.DeliveryPoint.Building))
                                               .AddColumn("Время")
                                               .AddTextRenderer(node => node.RouteListItem.Order.DeliverySchedule == null ? "" : node.RouteListItem.Order.DeliverySchedule.Name)
                                               .AddColumn("Статус")
                                               .AddEnumRenderer(node => node.Status).Editing(false)
                                               .AddColumn("Последнее редактирование")
                                               .AddTextRenderer(node => node.LastUpdate)
                                               .RowCells()
                                               .AddSetter <CellRenderer>((cell, node) => cell.CellBackgroundGdk = node.RowColor)
                                               .Finish();

            items = new List <RouteListKeepingItemNode>();
            foreach (var item in Entity.Addresses)
            {
                items.Add(new RouteListKeepingItemNode {
                    RouteListItem = item
                });
            }

            items.Sort((x, y) => {
                if (x.RouteListItem.StatusLastUpdate.HasValue && y.RouteListItem.StatusLastUpdate.HasValue)
                {
                    if (x.RouteListItem.StatusLastUpdate > y.RouteListItem.StatusLastUpdate)
                    {
                        return(1);
                    }
                    if (x.RouteListItem.StatusLastUpdate < y.RouteListItem.StatusLastUpdate)
                    {
                        return(-1);
                    }
                }
                return(0);
            });

            ytreeviewAddresses.ItemsDataSource = items;
            entryMileageComment.Binding.AddBinding(Entity, x => x.MileageComment, w => w.Text).InitializeFromSource();



            if (Entity.Status == RouteListStatus.MileageCheck)
            {
                buttonCloseRouteList.Sensitive = editing;
            }
            else if (editingAdmin)
            {
                buttonCloseRouteList.Sensitive = true;
            }
            else
            {
                buttonCloseRouteList.Sensitive = false;
            }
        }
        private void ConfigureDlg()
        {
            Entity.ObservableFuelDocuments.ElementAdded   += ObservableFuelDocuments_ElementAdded;
            Entity.ObservableFuelDocuments.ElementRemoved += ObservableFuelDocuments_ElementRemoved;
            referenceCar.SubjectType = typeof(Car);
            referenceCar.ItemsQuery  = CarRepository.ActiveCarsQuery();
            referenceCar.Binding.AddBinding(Entity, rl => rl.Car, widget => widget.Subject).InitializeFromSource();
            referenceCar.Sensitive = editing;

            var filterDriver = new EmployeeFilter(UoW);

            filterDriver.SetAndRefilterAtOnce(
                x => x.RestrictCategory = EmployeeCategory.driver,
                x => x.ShowFired        = false
                );
            referenceDriver.RepresentationModel = new EmployeesVM(filterDriver);
            referenceDriver.Binding.AddBinding(Entity, rl => rl.Driver, widget => widget.Subject).InitializeFromSource();
            referenceDriver.Sensitive = editing;

            previousForwarder = Entity.Forwarder;
            var filterForwarder = new EmployeeFilter(UoW);

            filterForwarder.SetAndRefilterAtOnce(
                x => x.RestrictCategory = EmployeeCategory.forwarder,
                x => x.ShowFired        = false
                );
            referenceForwarder.RepresentationModel = new EmployeesVM(filterForwarder);
            referenceForwarder.Binding.AddBinding(Entity, rl => rl.Forwarder, widget => widget.Subject).InitializeFromSource();
            referenceForwarder.Sensitive = editing;
            referenceForwarder.Changed  += ReferenceForwarder_Changed;

            var filterLogistican = new EmployeeFilter(UoW);

            filterLogistican.SetAndRefilterAtOnce(x => x.ShowFired = false);
            referenceLogistican.RepresentationModel = new EmployeesVM(filterLogistican);
            referenceLogistican.Binding.AddBinding(Entity, rl => rl.Logistican, widget => widget.Subject).InitializeFromSource();
            referenceLogistican.Sensitive = editing;

            speccomboShift.ItemsList = DeliveryShiftRepository.ActiveShifts(UoW);
            speccomboShift.Binding.AddBinding(Entity, rl => rl.Shift, widget => widget.SelectedItem).InitializeFromSource();
            speccomboShift.Sensitive = editing;

            yspinActualDistance.Binding.AddBinding(Entity, rl => rl.ActualDistance, widget => widget.ValueAsDecimal).InitializeFromSource();
            yspinActualDistance.Sensitive = editing;

            datePickerDate.Binding.AddBinding(Entity, rl => rl.Date, widget => widget.Date).InitializeFromSource();
            datePickerDate.Sensitive = editing;

            ycheckConfirmDifferences.Binding.AddBinding(Entity, e => e.DifferencesConfirmed, w => w.Active).InitializeFromSource();
            ycheckConfirmDifferences.Sensitive = editing && Entity.Status == RouteListStatus.OnClosing;

            decimal unclosedAdvanceMoney = AccountableDebtsRepository.EmloyeeDebt(UoW, Entity.Driver);

            ylabelUnclosedAdvancesMoney.LabelProp =
                String.Format(unclosedAdvanceMoney > 0m ? "<span foreground='red'><b>Долг: {0}</b></span>" : "", unclosedAdvanceMoney);

            ytextClosingComment.Binding.AddBinding(Entity, e => e.ClosingComment, w => w.Buffer.Text).InitializeFromSource();
            ytextClosingComment.Sensitive = editing;
            labelOrderEarly.Text          = "Сдано ранее:" + GetCashOrder().ToString();
            spinCashOrder.Value           = 0;
            advanceSpinbutton.Value       = 0;
            advanceSpinbutton.Visible     = false;

            ycheckNormalWage.Binding.AddSource(Entity)
            .AddFuncBinding(x => x.Driver.WageCalcType == WageCalculationType.normal && x.Car.IsCompanyHavings, w => w.Visible)
            .AddBinding(x => x.NormalWage, w => w.Active)
            .InitializeFromSource();
            ycheckNormalWage.Sensitive = editing && QSMain.User.Permissions["change_driver_wage"];

            PerformanceHelper.AddTimePoint("Создан диалог");

            //Предварительная загрузка объектов для ускорения.

            /*			Vodovoz.Domain.Orders.Order orderAlias = null;
             *                      var clients = UoW.Session.QueryOver<RouteListItem>()
             *                              .Where(rli => rli.RouteList.Id == Entity.Id)
             *                              .JoinAlias(rli => rli.Order, () => orderAlias)
             *                              .Fetch(rli => rli.Order.Client).Eager
             *                              .List();
             *                              //.Select(Projections. a => orderAlias.Client).Future();
             *                              //.List<Counterparty>();
             */
            PerformanceHelper.AddTimePoint("Предварительная загрузка");

            routeListAddressesView.UoW       = UoW;
            routeListAddressesView.RouteList = Entity;
            foreach (RouteListItem item in routeListAddressesView.Items)
            {
                item.Order.ObservableOrderItems.ElementChanged += ObservableOrderItems_ElementChanged;
                item.Order.ObservableOrderItems.ElementAdded   += ObservableOrderItems_ElementAdded;
                item.Order.ObservableOrderItems.ElementRemoved += ObservableOrderItems_ElementRemoved;

                item.Order.ObservableOrderEquipments.ElementChanged += ObservableOrderItems_ElementChanged;
                item.Order.ObservableOrderEquipments.ElementAdded   += ObservableOrderItems_ElementAdded;
                item.Order.ObservableOrderEquipments.ElementRemoved += ObservableOrderItems_ElementRemoved;

                item.Order.ObservableOrderDepositItems.ElementChanged += ObservableOrderItems_ElementChanged;
                item.Order.ObservableOrderDepositItems.ElementAdded   += ObservableOrderItems_ElementAdded;
                item.Order.ObservableOrderDepositItems.ElementRemoved += ObservableOrderItems_ElementRemoved;
            }
            routeListAddressesView.Items.ElementChanged   += OnRouteListItemChanged;
            routeListAddressesView.OnClosingItemActivated += OnRouteListItemActivated;
            routeListAddressesView.IsEditing        = editing;
            routeListAddressesView.ColumsVisibility = !ycheckHideCells.Active;
            ycheckHideCells.Sensitive = editing;
            PerformanceHelper.AddTimePoint("заполнили список адресов");
            ReloadReturnedToWarehouse();
            var returnableOrderItems = routeListAddressesView.Items
                                       .Where(address => address.IsDelivered())
                                       .SelectMany(address => address.Order.OrderItems)
                                       .Where(orderItem => !orderItem.Nomenclature.IsSerial)
                                       .Where(orderItem => Nomenclature.GetCategoriesForShipment().Any(nom => nom == orderItem.Nomenclature.Category));

            foreach (var item in returnableOrderItems)
            {
                if (allReturnsToWarehouse.All(r => r.NomenclatureId != item.Nomenclature.Id))
                {
                    allReturnsToWarehouse.Add(new RouteListRepository.ReturnsNode {
                        Name           = item.Nomenclature.Name,
                        Trackable      = item.Nomenclature.IsSerial,
                        NomenclatureId = item.Nomenclature.Id,
                        Amount         = 0
                    });
                }
            }
            PerformanceHelper.AddTimePoint("Получили возврат на склад");
            //FIXME Убрать из этого места первоначальное заполнение. Сейчас оно вызывается при переводе статуса на сдачу. После того как не нормально не переведенных в закрытие маршрутников, тут заполение можно убрать.
            if (!Entity.ClosingFilled)
            {
                Entity.FirstFillClosing();
            }

            PerformanceHelper.AddTimePoint("Закончено первоначальное заполнение");

            hbox6.Remove(vboxHidenPanel);
            rightsidepanel1.Panel   = vboxHidenPanel;
            rightsidepanel1.IsHided = true;

            expander1.Expanded = false;

            routelistdiscrepancyview.FindDiscrepancies(Entity.Addresses, allReturnsToWarehouse);
            routelistdiscrepancyview.FineChanged += Routelistdiscrepancyview_FineChanged;
            routelistdiscrepancyview.Sensitive    = editing;
            PerformanceHelper.AddTimePoint("Заполнили расхождения");

            buttonAddFuelDocument.Sensitive             = Entity.Car?.FuelType?.Cost != null && Entity.Driver != null && editing;
            buttonDeleteFuelDocument.Sensitive          = Entity.Car?.FuelType?.Cost != null && Entity.Driver != null && editing;
            ytreeviewFuelDocuments.ItemsDataSource      = Entity.ObservableFuelDocuments;
            ytreeviewFuelDocuments.Reorderable          = true;
            Entity.ObservableFuelDocuments.ListChanged += ObservableFuelDocuments_ListChanged;
            UpdateFuelDocumentsColumns();

            enummenuRLActions.ItemsEnum        = typeof(RouteListActions);
            enummenuRLActions.EnumItemClicked += EnummenuRLActions_EnumItemClicked;
            enummenuRLActions.Sensitive        = editing;

            CheckWage();

            LoadDataFromFine();
            OnItemsUpdated();
            PerformanceHelper.AddTimePoint("Загрузка штрафов");
            GetFuelInfo();
            UpdateFuelInfo();
            PerformanceHelper.AddTimePoint("Загрузка бензина");

            PerformanceHelper.Main.PrintAllPoints(logger);

            //Подписки на обновления
            OrmMain.GetObjectDescription <CarUnloadDocument>().ObjectUpdatedGeneric += OnCalUnloadUpdated;

            enumPrint.ItemsEnum        = typeof(RouteListPrintDocuments);
            enumPrint.EnumItemClicked += (sender, e) => PrintSelectedDocument((RouteListPrintDocuments)e.ItemEnum);

            ylabelRecalculatedMileage.Binding.AddFuncBinding(Entity, e => e.RecalculatedDistance.HasValue ? $" {e.RecalculatedDistance} км" : "", w => w.LabelProp).InitializeFromSource();
            checkSendToMileageCheck.Binding.AddBinding(Entity, x => x.MileageCheck, w => w.Active).InitializeFromSource();
            Entity.PropertyChanged += Entity_PropertyChanged;
            //FIXME костыли, необходимо избавится от этого кода когда решим проблему с сессиями и flush nhibernate
            HasChanges          = true;
            UoW.CanCheckIfDirty = false;
        }
        private void ConfigureDlg()
        {
            datepickerDate.Binding.AddBinding(Entity, e => e.Date, w => w.Date).InitializeFromSource();

            referenceCar.SubjectType = typeof(Car);
            referenceCar.ItemsQuery  = CarRepository.ActiveCarsQuery();
            referenceCar.Binding.AddBinding(Entity, e => e.Car, w => w.Subject).InitializeFromSource();
            referenceCar.ChangedByUser += (sender, e) => {
                if (Entity.Car != null)
                {
                    Entity.Driver             = (Entity.Car.Driver != null && !Entity.Car.Driver.IsFired) ? Entity.Car.Driver : null;
                    referenceDriver.Sensitive = Entity.Driver == null || Entity.Car.IsCompanyHavings;
                    //Водители на Авто компании катаются без экспедитора
                    Entity.Forwarder = Entity.Car.IsCompanyHavings ? null : Entity.Forwarder;
                    referenceForwarder.IsEditable = !Entity.Car.IsCompanyHavings;
                }
            };

            var filterDriver = new EmployeeFilter(UoW, false);

            filterDriver.SetAndRefilterAtOnce(x => x.RestrictCategory = EmployeeCategory.driver);
            referenceDriver.RepresentationModel = new EmployeesVM(filterDriver);
            referenceDriver.Binding.AddBinding(Entity, e => e.Driver, w => w.Subject).InitializeFromSource();

            var filter = new EmployeeFilter(UoW, false);

            filter.SetAndRefilterAtOnce(x => x.RestrictCategory = EmployeeCategory.forwarder);
            referenceForwarder.RepresentationModel = new ViewModel.EmployeesVM(filter);
            referenceForwarder.Binding.AddBinding(Entity, e => e.Forwarder, w => w.Subject).InitializeFromSource();
            referenceForwarder.Changed += (sender, args) =>
            {
                createroutelistitemsview1.OnForwarderChanged();
            };

            referenceLogistican.Sensitive = false;
            var filterLogistican = new EmployeeFilter(UoW);

            referenceLogistican.RepresentationModel = new EmployeesVM(filterLogistican);
            referenceLogistican.Binding.AddBinding(Entity, e => e.Logistican, 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();

            referenceDriver.Sensitive = false;
            enumPrint.Sensitive       = UoWGeneric.Root.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();
            }

            createroutelistitemsview1.RouteListUoW = UoWGeneric;

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

            IsEditable = UoWGeneric.Root.Status == RouteListStatus.New && QSMain.User.Permissions ["logistican"];

            //FIXME костыли, необходимо избавится от этого кода когда решим проблему с сессиями и flush nhibernate
            HasChanges          = true;
            UoW.CanCheckIfDirty = false;

            enumPrint.ItemsEnum = typeof(RouteListPrintableDocuments);
            enumPrint.SetVisibility(RouteListPrintableDocuments.LoadSofiyskaya, false);
            enumPrint.EnumItemClicked += (sender, e) => PrintSelectedDocument((RouteListPrintableDocuments)e.ItemEnum);
            CheckCarLoadDocuments();
        }