Exemplo n.º 1
0
        void ExternalEntityChangeEventMethod(DomainModel.NotifyChange.EntityChangeEvent[] changeEvents)
        {
            object foundUpdatedObject = changeEvents.FirstOrDefault(e => DomainHelper.EqualDomainObjects(e.Entity, EntityEntryViewModel.Entity));

            if (foundUpdatedObject != null && uow.Session.IsOpen && uow.Session.Contains(EntityEntryViewModel.Entity))
            {
                uow.Session.Refresh(EntityEntryViewModel.Entity);
            }
        }
Exemplo n.º 2
0
 public virtual void AddShift(DeliveryShift deliveryShift)
 {
     if (Shifts.Any(ds => DomainHelper.EqualDomainObjects(ds, deliveryShift)))
     {
         logger.Warn("Смена {0} уже добавлена. Пропускаем...", deliveryShift.Name);
         return;
     }
     ObservableShifts.Add(deliveryShift);
 }
Exemplo n.º 3
0
 public virtual void AddNomeclature(Nomenclature nomenclature)
 {
     if (Nomenclatures.Any(p => DomainHelper.EqualDomainObjects(p, nomenclature)))
     {
         logger.Warn("Номеклатура уже добавлена. Пропускаем...");
         return;
     }
     ObservableNomenclatures.Add(nomenclature);
 }
Exemplo n.º 4
0
        public virtual void UpdateContractTemplate(IUnitOfWork uow)
        {
            var newTemplate = Repository.Client.DocTemplateRepository.GetTemplate(uow, ContractType);

            if (!DomainHelper.EqualDomainObjects(newTemplate, ContractTemplate))
            {
                ContractTemplate    = newTemplate;
                ChangedTemplateFile = null;
            }
        }
Exemplo n.º 5
0
        public override bool Equals(object obj)
        {
            var tp = obj as TrackPoint;

            if (tp != null)
            {
                return(DomainHelper.EqualDomainObjects(tp.Track, this.Track) && tp.TimeStamp == this.TimeStamp);
            }
            return(false);
        }
Exemplo n.º 6
0
 public virtual void AddAnalog(ProtectionTools Analog)
 {
     if (Analogs.Any(p => DomainHelper.EqualDomainObjects(p, Analog)))
     {
         logger.Warn("Такой аналог уже добавлен. Пропускаем...");
         return;
     }
     if (DomainHelper.EqualDomainObjects(this, Analog))
     {
         logger.Warn("Нельзя добавлять в качестве аналога себя. Пропускаем...");
         return;
     }
     ObservableAnalog.Add(Analog);
 }
Exemplo n.º 7
0
        private void OnExternalObjectUpdated(object sender, OrmObjectUpdatedEventArgs e)
        {
            object foundUpdatedObject = e.UpdatedSubjects.FirstOrDefault(s => DomainHelper.EqualDomainObjects(s, Subject));

            if (foundUpdatedObject != null)
            {
                //var dlg = DialogHelper.FindParentUowDialog(this);
                //FIXME Возможно не нужно подписываться пока закомментируем
                //if (dlg != null && !dlg.Session.Contains (foundUpdatedObject))
                //	dlg.Session.Refresh (Subject);

                UpdateWidget();
                OnChanged();
            }
        }
Exemplo n.º 8
0
        void ExternalEntityChangeEventMethod(DomainModel.NotifyChange.EntityChangeEvent[] changeEvents)
        {
            object foundUpdatedObject = changeEvents.FirstOrDefault(e => DomainHelper.EqualDomainObjects(e.Entity, Subject));

            if (foundUpdatedObject != null)
            {
                if (UoW != null && UoW.Session.IsOpen && UoW.Session.Contains(Subject))
                {
                    UoW.Session.Refresh(Subject);
                }

                UpdateWidget();
                OnChanged();
            }
        }
Exemplo n.º 9
0
        public virtual void AddItem(SubdivisionIssueOperation operation, int count)
        {
            if (operation.Issued == 0)
            {
                throw new InvalidOperationException("Этот метод можно использовать только с операциями выдачи.");
            }

            if (Items.Any(p => DomainHelper.EqualDomainObjects(p.SubdivisionWriteoffOperation?.IssuedOperation, operation)))
            {
                logger.Warn("Номенклатура из этой выдачи уже добавлена. Пропускаем...");
                return;
            }

            ObservableItems.Add(new WriteoffItem(this, operation, count));
        }
Exemplo n.º 10
0
        void YentryreferenceRLTo_Changed(object sender, EventArgs e)
        {
            if (yentryreferenceRLTo.Subject == null)
            {
                ytreeviewRLTo.ItemsDataSource = null;
                return;
            }

            RouteList routeListTo   = yentryreferenceRLTo.Subject as RouteList;
            RouteList routeListFrom = yentryreferenceRLFrom.Subject as RouteList;

            if (DomainHelper.EqualDomainObjects(routeListFrom, routeListTo))
            {
                yentryreferenceRLTo.Subject = null;
                MessageDialogHelper.RunErrorDialog("Вы дурачёк?", "Вы не можете передавать адреса в тот же МЛ, из которого забираете.");
                return;
            }

            if (TabParent != null)
            {
                var tab = TabParent.FindTab(DialogHelper.GenerateDialogHashName <RouteList>(routeListTo.Id));
                if (!(tab is RouteListClosingDlg))
                {
                    if (tab != null)
                    {
                        MessageDialogHelper.RunErrorDialog("Маршрутный лист уже открыт в другой вкладке");
                        yentryreferenceRLTo.Subject = null;
                        return;
                    }
                }
            }

            CheckSensitivities();

            routeListTo.UoW = UoW;

            IList <RouteListItemNode> items = new List <RouteListItemNode>();

            foreach (var item in routeListTo.Addresses)
            {
                items.Add(new RouteListItemNode {
                    RouteListItem = item
                });
            }
            ytreeviewRLTo.ItemsDataSource = items;

            FillObservableDriverBalance(ObservableDriverBalanceTo, routeListTo);
        }
Exemplo n.º 11
0
        void ExternalEntityChangeEventMethod(DomainModel.NotifyChange.EntityChangeEvent[] changeEvents)
        {
            var foundUpdatedObject = changeEvents.FirstOrDefault(e => DomainHelper.EqualDomainObjects(e.Entity, EntityEntryViewModel.Entity));

            if (foundUpdatedObject != null && uow.Session.IsOpen && uow.Session.Contains(EntityEntryViewModel.Entity))
            {
                if (foundUpdatedObject.EventType == DomainModel.NotifyChange.TypeOfChangeEvent.Delete)
                {
                    EntityEntryViewModel.Entity = null;
                }
                else
                {
                    uow.Session.Refresh(EntityEntryViewModel.Entity);
                }
            }
        }
Exemplo n.º 12
0
        private void OnExternalObjectUpdated(object sender, OrmObjectUpdatedEventArgs e)
        {
            object foundUpdatedObject = e.UpdatedSubjects.FirstOrDefault(s => DomainHelper.EqualDomainObjects(s, Subject));

            if (foundUpdatedObject != null)
            {
                var dlg = DialogHelper.FindParentUowDialog(this);
                if (MyEntityDialogExist)
                {
                    MyEntityDialog.UoW.Session.Refresh(Subject);
                }

                UpdateWidget();
                OnChanged();
            }
        }
Exemplo n.º 13
0
        protected void OnButtonUpdatePricesClicked(object sender, EventArgs e)
        {
            var newPricesList = new Dictionary <Price, int>();
            int effectedRows  = 0;

            foreach (var item in Entity.ProjectRows)
            {
                PriceItem newPriceItem = Repository.PriceRepository.GetLastPriceItem(UoW, item.Fitting, item.SelectedPriceItem?.Price.Provider);
                if (newPriceItem == null)
                {
                    continue;
                }
                if (!DomainHelper.EqualDomainObjects(newPriceItem, item.SelectedPriceItem))
                {
                    effectedRows++;
                    item.SelectedPriceItem = newPriceItem;
                    item.FittingPrice      = newPriceItem.Cost;
                    item.PriceCurrency     = newPriceItem.Currency;
                    if (newPricesList.ContainsKey(newPriceItem.Price))
                    {
                        newPricesList[newPriceItem.Price]++;
                    }
                    else
                    {
                        newPricesList.Add(newPriceItem.Price, 1);
                    }
                }
            }

            if (effectedRows == 0)
            {
                MessageDialogWorks.RunInfoDialog("Новые цены не найдены!");
            }
            else
            {
                MessageDialogWorks.RunInfoDialog(String.Format("Были обновлены цены в {0}.\n" +
                                                               "Новые цены были получены из {1}:\n" +
                                                               "{2}",
                                                               RusNumber.FormatCase(effectedRows, "{0} строке", "{0} строках", "{0} строках"),
                                                               RusNumber.FormatCase(newPricesList.Count, "{0} прайса", "{0} прайсов", "{0} прайсов"),
                                                               String.Join("\n", newPricesList.Select(x =>
                                                                                                      String.Format("{0} ({1:d}) - {2}", x.Key.Provider.Name, x.Key.Date, x.Value)
                                                                                                      ))
                                                               ));
            }
        }
Exemplo n.º 14
0
        static bool EntityCompare(ref FieldChange change, object valueOld, object valueNew)
        {
            if (DomainHelper.EqualDomainObjects(valueOld, valueNew))
            {
                return(false);
            }

            change = new FieldChange();
            if (valueOld != null)
            {
                change.OldValue = HistoryMain.GetObjectTilte(valueOld);
                change.OldId    = DomainHelper.GetId(valueOld);
            }
            if (valueNew != null)
            {
                change.NewValue = HistoryMain.GetObjectTilte(valueNew);
                change.NewId    = DomainHelper.GetId(valueNew);
            }
            return(true);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Сравниваем все поля на равенство, ссылки на доменные объекты сравниваем по ID.
        /// </summary>
        /// <returns><c>true</c> если поля объектов одинаковы.</returns>
        /// <param name="object1">Object1.</param>
        /// <param name="object2">Object2.</param>
        public static bool CompareFields <T> (T object1, T object2) where T : class
        {
            Type             type   = object1.GetType();
            List <FieldInfo> fields = new List <FieldInfo> ();

            while (type != null)
            {
                fields.AddRange(type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
                type = type.BaseType;
            }
            foreach (FieldInfo f in fields)
            {
                object value = f.GetValue(object1);
                if (value is IDomainObject)
                {
                    if (!DomainHelper.EqualDomainObjects(value, f.GetValue(object2)))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (value == null)
                    {
                        if (f.GetValue(object2) != null)
                        {
                            return(false);
                        }
                    }
                    else if (!value.Equals(f.GetValue(object2)))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 16
0
        public void MakeChange(
            SettingsMatchEmployeesViewModel settings,
            EmployeeCard employee,
            SheetRowEmployee row,
            ImportedColumn <DataTypeEmployee> column,
            ChangeType rowChange,
            IUnitOfWork uow)
        {
            var value    = row.CellStringValue(column.Index);
            var dataType = column.DataType;

            if (String.IsNullOrWhiteSpace(value))
            {
                row.AddColumnChange(column, ChangeType.NotChanged);
                return;
            }

            switch (dataType)
            {
            case DataTypeEmployee.CardKey:
                row.ChangedColumns.Add(column, CompareString(employee.CardKey, value, rowChange));
                break;

            case DataTypeEmployee.PersonnelNumber:
                row.ChangedColumns.Add(column, CompareString(employee.PersonnelNumber,
                                                             (settings.ConvertPersonnelNumber ? EmployeeParse.ConvertPersonnelNumber(value) : value)?.Trim(), rowChange));
                break;

            case DataTypeEmployee.Phone:
                row.ChangedColumns.Add(column, ComparePhone(employee.PhoneNumber, value, rowChange));
                break;

            case DataTypeEmployee.LastName:
                row.ChangedColumns.Add(column, CompareString(employee.LastName, value, rowChange));
                break;

            case DataTypeEmployee.FirstName:
                row.ChangedColumns.Add(column, CompareString(employee.FirstName, value, rowChange));
                break;

            case DataTypeEmployee.Patronymic:
                row.ChangedColumns.Add(column, CompareString(employee.Patronymic, value, rowChange));
                break;

            case DataTypeEmployee.Sex:
                //Первая М английская, вторая русская.
                if (value.StartsWith("M", StringComparison.CurrentCultureIgnoreCase) ||
                    value.StartsWith("М", StringComparison.CurrentCultureIgnoreCase))
                {
                    row.AddColumnChange(column, employee.Sex == Sex.M ? ChangeType.NotChanged : rowChange);
                    break;
                }
                if (value.StartsWith("F", StringComparison.CurrentCultureIgnoreCase) ||
                    value.StartsWith("Ж", StringComparison.CurrentCultureIgnoreCase))
                {
                    row.AddColumnChange(column, employee.Sex == Sex.F ? ChangeType.NotChanged : rowChange);
                    break;
                }
                row.AddColumnChange(column, ChangeType.ParseError);
                break;

            case DataTypeEmployee.Fio:
                value.SplitFullName(out var lastName, out var firstName, out var patronymic);
                var lastDiff = !String.IsNullOrEmpty(lastName) &&
                               !String.Equals(employee.LastName, lastName, StringComparison.CurrentCultureIgnoreCase);
                var firstDiff = !String.IsNullOrEmpty(firstName) &&
                                !String.Equals(employee.FirstName, firstName, StringComparison.CurrentCultureIgnoreCase);
                var patronymicDiff = !String.IsNullOrEmpty(patronymic) &&
                                     !String.Equals(employee.Patronymic, patronymic, StringComparison.CurrentCultureIgnoreCase);
                string oldValue = (lastDiff || firstDiff || patronymicDiff) ? employee.FullName : null;
                row.AddColumnChange(column, (lastDiff || firstDiff || patronymicDiff) ? rowChange : ChangeType.NotChanged, oldValue);
                break;

            case DataTypeEmployee.HireDate:
                row.ChangedColumns.Add(column, CompareDate(employee.HireDate, row.CellDateTimeValue(column.Index), rowChange));
                break;

            case DataTypeEmployee.DismissDate:
                row.ChangedColumns.Add(column, CompareDate(employee.DismissDate, row.CellDateTimeValue(column.Index), rowChange));
                break;

            case DataTypeEmployee.BirthDate:
                row.ChangedColumns.Add(column, CompareDate(employee.BirthDate, row.CellDateTimeValue(column.Index), rowChange));
                break;

            case DataTypeEmployee.Subdivision:
                if (String.Equals(employee.Subdivision?.Name, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    row.AddColumnChange(column, ChangeType.NotChanged);
                    break;
                }

                var subdivision = UsedSubdivisions.FirstOrDefault(x =>
                                                                  String.Equals(x.Name, value, StringComparison.CurrentCultureIgnoreCase));
                if (subdivision == null)
                {
                    subdivision = new Subdivision {
                        Name = value
                    };
                    UsedSubdivisions.Add(subdivision);
                }
                row.AddColumnChange(column, subdivision.Id == 0 ? ChangeType.NewEntity : rowChange, employee.Subdivision?.Name);
                employee.Subdivision = subdivision;
                break;

            case DataTypeEmployee.Department:
                if (String.Equals(employee.Department?.Name, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    row.AddColumnChange(column, ChangeType.NotChanged);
                    break;
                }
                var department = UsedDepartment.FirstOrDefault(x =>
                                                               String.Equals(x.Name, value, StringComparison.CurrentCultureIgnoreCase) &&
                                                               (employee.Subdivision == null && x.Subdivision == null ||
                                                                DomainHelper.EqualDomainObjects(x.Subdivision, employee.Subdivision)));
                if (department == null)
                {
                    department = new Department {
                        Name        = value,
                        Subdivision = employee.Subdivision,
                        Comments    = "Создан при импорте сотрудников из Excel"
                    };
                    UsedDepartment.Add(department);
                }
                row.AddColumnChange(column, department.Id == 0 ? ChangeType.NewEntity : rowChange, employee.Department?.Name);
                employee.Department = department;
                break;

            case DataTypeEmployee.Post:
                if (String.Equals(employee.Post?.Name, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    row.AddColumnChange(column, ChangeType.NotChanged);
                    break;
                }
                var post = UsedPosts.FirstOrDefault(x =>
                                                    String.Equals(x.Name, value, StringComparison.CurrentCultureIgnoreCase) &&
                                                    (employee.Subdivision == null && x.Subdivision == null ||
                                                     DomainHelper.EqualDomainObjects(x.Subdivision, employee.Subdivision)));
                if (post == null)
                {
                    post = new Post {
                        Name        = value,
                        Subdivision = employee.Subdivision,
                        Comments    = "Создана при импорте сотрудников из Excel"
                    };
                    UsedPosts.Add(post);
                }
                row.AddColumnChange(column, post.Id == 0 ? ChangeType.NewEntity : rowChange, employee.Post?.Name);
                employee.Post = post;
                break;

            case DataTypeEmployee.Growth: {
                var height         = SizeParser.ParseSize(uow, row.CellStringValue(column.Index), sizeService, CategorySizeType.Height);
                var employeeHeight = employee.Sizes.FirstOrDefault(x => x.SizeType == height.SizeType)?.Size;
                row.ChangedColumns.Add(column, CompareSize(employeeHeight, height, rowChange, uow));
            }
            break;

            case DataTypeEmployee.WearSize: {
                var size         = SizeParser.ParseSize(uow, row.CellStringValue(column.Index), sizeService, CategorySizeType.Size);
                var employeeSize = employee.Sizes.FirstOrDefault(x => x.SizeType == size.SizeType)?.Size;
                row.ChangedColumns.Add(column, CompareSize(employeeSize, size, rowChange, uow));
            }
            break;

            case DataTypeEmployee.ShoesSize: {
                var size         = SizeParser.ParseSize(uow, row.CellStringValue(column.Index), sizeService, CategorySizeType.Size);
                var employeeSize = employee.Sizes.FirstOrDefault(x => x.SizeType == size.SizeType)?.Size;
                row.ChangedColumns.Add(column, CompareSize(employeeSize, size, rowChange, uow));
            }
            break;

            default:
                throw new NotSupportedException($"Тип данных {dataType} не поддерживается.");
            }
        }