Ejemplo n.º 1
0
        public string GetPersonalNumber(SettingsMatchEmployeesViewModel settings, SheetRowEmployee row, int columnIndex)
        {
            var original = settings.ConvertPersonnelNumber ?
                           EmployeeParse.ConvertPersonnelNumber(row.CellStringValue(columnIndex)) : row.CellStringValue(columnIndex);

            return(original?.Trim());
        }
Ejemplo n.º 2
0
        public FIO GetFIO(SheetRowEmployee row, List <ImportedColumn <DataTypeEmployee> > columns)
        {
            var fio              = new FIO();
            var lastnameColumn   = columns.FirstOrDefault(x => x.DataType == DataTypeEmployee.LastName);
            var firstNameColumn  = columns.FirstOrDefault(x => x.DataType == DataTypeEmployee.FirstName);
            var patronymicColumn = columns.FirstOrDefault(x => x.DataType == DataTypeEmployee.Patronymic);
            var fioColumn        = columns.FirstOrDefault(x => x.DataType == DataTypeEmployee.Fio);

            if (fioColumn != null)
            {
                row.CellStringValue(fioColumn.Index)?.SplitFullName(out fio.LastName, out fio.FirstName, out fio.Patronymic);
            }
            if (lastnameColumn != null)
            {
                fio.LastName = row.CellStringValue(lastnameColumn.Index);
            }
            if (firstNameColumn != null)
            {
                fio.FirstName = row.CellStringValue(firstNameColumn.Index);
            }
            if (patronymicColumn != null)
            {
                fio.Patronymic = row.CellStringValue(patronymicColumn.Index);
            }
            return(fio);
        }
Ejemplo n.º 3
0
        private bool СompareFio(SheetRowEmployee x, EmployeeCard employee, List <ImportedColumn <DataTypeEmployee> > columns)
        {
            var fio = GetFIO(x, columns);

            return(String.Equals(fio.LastName, employee.LastName, StringComparison.CurrentCultureIgnoreCase) &&
                   String.Equals(fio.FirstName, employee.FirstName, StringComparison.CurrentCultureIgnoreCase) &&
                   (fio.Patronymic == null || String.Equals(fio.Patronymic, employee.Patronymic, StringComparison.CurrentCultureIgnoreCase)));
        }
Ejemplo n.º 4
0
        private void SetValue(
            SettingsMatchEmployeesViewModel settings,
            IUnitOfWork uow,
            EmployeeCard employee,
            SheetRowEmployee row,
            ImportedColumn <DataTypeEmployee> column)
        {
            var value    = row.CellStringValue(column.Index);
            var dataType = column.DataType;

            if (String.IsNullOrWhiteSpace(value))
            {
                return;
            }

            switch (dataType)
            {
            case DataTypeEmployee.CardKey:
                employee.CardKey = value;
                break;

            case DataTypeEmployee.PersonnelNumber:
                employee.PersonnelNumber = (settings.ConvertPersonnelNumber ?
                                            EmployeeParse.ConvertPersonnelNumber(value) : value)?.Trim();
                break;

            case DataTypeEmployee.Phone:
                employee.PhoneNumber = phoneFormatter.FormatString(value);
                break;

            case DataTypeEmployee.LastName:
                employee.LastName = value;
                break;

            case DataTypeEmployee.FirstName:
                employee.FirstName = value;
                if (employee.Sex == Sex.None)
                {
                    employee.Sex = personNames.GetSexByName(employee.FirstName);
                }
                break;

            case DataTypeEmployee.Patronymic:
                employee.Patronymic = value;
                break;

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

            case DataTypeEmployee.Fio:
                value.SplitFullName(out var lastName, out var firstName, out var patronymic);
                if (!String.IsNullOrEmpty(lastName) && !String.Equals(employee.LastName, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    employee.LastName = lastName;
                }
                if (!String.IsNullOrEmpty(firstName) && !String.Equals(employee.FirstName, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    employee.FirstName = firstName;
                }
                if (!String.IsNullOrEmpty(patronymic) && !String.Equals(employee.Patronymic, value, StringComparison.CurrentCultureIgnoreCase))
                {
                    employee.Patronymic = patronymic;
                }
                if (employee.Sex == Sex.None && !String.IsNullOrWhiteSpace(employee.FirstName))
                {
                    employee.Sex = personNames.GetSexByName(employee.FirstName);
                }
                break;

            case DataTypeEmployee.HireDate:
                var hireDate = row.CellDateTimeValue(column.Index);
                if (hireDate != null)
                {
                    employee.HireDate = hireDate;
                }
                break;

            case DataTypeEmployee.DismissDate:
                var dismissDate = row.CellDateTimeValue(column.Index);
                if (dismissDate != null)
                {
                    employee.DismissDate = dismissDate;
                }
                break;

            case DataTypeEmployee.BirthDate:
                var birthDate = row.CellDateTimeValue(column.Index);
                if (birthDate != null)
                {
                    employee.BirthDate = birthDate;
                }
                break;

            case DataTypeEmployee.Subdivision:
            case DataTypeEmployee.Department:
            case DataTypeEmployee.Post:
                //Устанавливаем в MakeChange;
                break;

            case DataTypeEmployee.Growth:
                var height = SizeParser.ParseSize(uow, value, sizeService, CategorySizeType.Height);
                if (height is null)
                {
                    break;
                }
                var employeeHeight = employee.Sizes.FirstOrDefault(x => x.SizeType == height.SizeType);
                if (employeeHeight is null)
                {
                    employeeHeight = new EmployeeSize
                    {
                        Size = height, SizeType = height.SizeType, Employee = employee
                    };
                    employee.Sizes.Add(employeeHeight);
                }
                else
                {
                    employeeHeight.Size = height;
                }
                break;

            case DataTypeEmployee.WearSize:
                var size = SizeParser.ParseSize(uow, value, sizeService, CategorySizeType.Size);
                if (size is null)
                {
                    break;
                }
                var employeeSize = employee.Sizes.FirstOrDefault(x => x.SizeType == size.SizeType);
                if (employeeSize is null)
                {
                    employeeSize = new EmployeeSize
                    {
                        Size = size, SizeType = size.SizeType, Employee = employee
                    };
                    employee.Sizes.Add(employeeSize);
                }
                else
                {
                    employeeSize.Size = size;
                }
                break;

            case DataTypeEmployee.ShoesSize:
            {
                var shoesSize = SizeParser.ParseSize(uow, value, sizeService, CategorySizeType.Size);
                if (shoesSize is null)
                {
                    break;
                }
                var employeeShoesSize = employee.Sizes.FirstOrDefault(x => x.SizeType == shoesSize.SizeType);
                if (employeeShoesSize is null)
                {
                    employeeShoesSize = new EmployeeSize
                    {
                        Size = shoesSize, SizeType = shoesSize.SizeType, Employee = employee
                    };
                    employee.Sizes.Add(employeeShoesSize);
                }
                else
                {
                    employeeShoesSize.Size = shoesSize;
                }
            }
            break;

            default:
                throw new NotSupportedException($"Тип данных {dataType} не поддерживается.");
            }
        }
Ejemplo n.º 5
0
        public IEnumerable <object> PrepareToSave(IUnitOfWork uow, SettingsMatchEmployeesViewModel settings, SheetRowEmployee row)
        {
            var employee = row.Employees.FirstOrDefault() ?? new EmployeeCard();

            //Здесь колонки сортируются чтобы процесс обработки данных был в порядке следования описания типов в Enum
            //Это надо для того чтобы наличие 2 полей с похожими данными заполнялись правильно. Например чтобы отдельное поле с фамилией могло перезаписать значение фамилии поученной из общего поля ФИО.
            foreach (var column in row.ChangedColumns.Keys.OrderBy(x => x.DataType))
            {
                if (row.ChangedColumns[column].ChangeType == ChangeType.NewEntity || row.ChangedColumns[column].ChangeType == ChangeType.ChangeValue)
                {
                    SetValue(settings, uow, employee, row, column);
                }
            }
            yield return(employee);
        }
Ejemplo n.º 6
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} не поддерживается.");
            }
        }