public void SetCountDetails(PositionTaskToDept doc, int count)
        {
            var filtered =
                Document.Positions.Where(
                    x =>
                        x.Name == doc.Name
                        && x.GostOnSort == doc.GostOnSort
                        && x.Length == doc.Length
                        && x.MarkSteal == doc.MarkSteal
                        && x.StandartSize == doc.StandartSize
                        && x.Width == doc.Width
                        && x.Designation == doc.Designation
                        && x.Profile == doc.Profile);

            foreach (var positionTaskToDept in filtered)
            {
                if (count <= 0)
                    count = 0;

                positionTaskToDept.CountDetails = count > positionTaskToDept.CountAll
                    ? positionTaskToDept.CountAll
                    : count;

                count -= positionTaskToDept.CountDetails;
            }
        }
 public void ViewFiles(PositionTaskToDept data)
 {
     var filesViewController = _controllersFactory.GetFilesViewController();
     filesViewController.Files = data.Files;
     filesViewController.ShowFilesView();
 }
        public void Remove(PositionTaskToDept doc)
        {
            var filtered =
               Document.Positions.Where(
                   x =>
                       x.Name == doc.Name
                       && x.GostOnSort == doc.GostOnSort
                       && x.Length == doc.Length
                       && x.MarkSteal == doc.MarkSteal
                       && x.StandartSize == doc.StandartSize
                       && x.Width == doc.Width
                       && x.Designation == doc.Designation
                       && x.Profile == doc.Profile).ToList();

            foreach (var positionTaskToDept in filtered)
            {
                Document.Positions.Remove(positionTaskToDept);
            }
        }
        public bool SelectDrawings()
        {
            if (Document.OrderId == null || Document.TechOperationId == null)
                return false;

            var drawings = ShowSelectionDrawingsController();

            if (drawings == null)
                return false;

            var res = false;
            var techRoutes = _dataManagersFactory.GetDataManager<TechRoute>().GetListCollection();
            var techOperations = _dataManagersFactory.GetDataManager<TechOperation>().GetListCollection();
            foreach (var drawing in drawings)
            {
                if (Document.Positions.All(x => x.DrawingId != drawing.Id))
                {
                    var route = techRoutes.FirstOrDefault(x => x.Id == drawing.TechRouteId);
                    var ostRoute = string.Empty;
                    TechOperation nextOperation = null;
                    TechOperation prevOperation = null;
                    if (route != null)
                    {
                        var techOperation =
                            techOperations.FirstOrDefault(x => x.Id == Document.TechOperationId.Value);
                        if (techOperation != null)
                        {
                            if (route.Name.Contains(techOperation.ShortName))
                            {
                                ostRoute =
                                    (route.Name + " ").Substring(route.Name.IndexOf(techOperation.ShortName,
                                        StringComparison.Ordinal) + techOperation.ShortName.Length).Trim();
                                if (ostRoute.StartsWith("-"))
                                    ostRoute = ostRoute.Substring(2).Trim();
                            }

                            var to = route.TechOperations.FirstOrDefault(x => x.Id == Document.TechOperationId.Value);

                            var index = route.TechOperations.IndexOf(to);
                            if (index >= 0 && index < route.TechOperations.Count - 1)
                            {
                                nextOperation = route.TechOperations[index + 1];
                            }

                            if (index > 0 && index <= route.TechOperations.Count - 1)
                            {
                                prevOperation = route.TechOperations[index - 1];
                            }
                        }
                    }

                    var draw = new Drawing();
                    //AutoMapper.Mapper.Map<HierarchyNumberDrawing, Drawing>((HierarchyNumberDrawing)drawing, draw);

                    var position = new PositionTaskToDept
                    {
                        DrawingId = drawing.Id.Value,
                        CountAll = drawing.CountAll,
                        CountDetails = drawing.CountAll,
                        CountProduced = 0,
                        Length = drawing.Length,
                        Width = drawing.Width,
                        Weight = drawing.Weight,
                        Designation = drawing.Designation,
                        GostOnSort = drawing.GostOnSort,
                        MarkSteal = drawing.MarkSteal,
                        Name = drawing.Name,
                        NextOperation = nextOperation,
                        PrevOperation = prevOperation,
                        NumberOnSpec = drawing.NumberOnSpec,
                        Profile = drawing.Profile,
                        StandartSize = drawing.StandartSize,
                        NextRoute = ostRoute,
                        Files = drawing.Files,
                        Drawing = drawing
                    };

                    if (position.Files.Count == 0)
                    {
                        var drawManager = _dataManagersFactory.GetDataManager<Drawing>();
                        var parent = drawing;
                        while (true)
                        {
                            if (parent.ParentId == null)
                                break;

                            parent = drawManager.GetDocument(parent.ParentId);
                            if (parent == null)
                            {
                                break;
                            }

                            if (parent.Files.Count != 0)
                            {
                                position.Files = parent.Files;
                                break;
                            }
                        }
                    }

                    Document.Positions.Add(position);
                    res = true;
                }
            }

            return res;
        }
        public void SetEscised(PositionTaskToDept grDoc, bool value)
        {
            var filtered =
                Document.Positions.Where(
                    x =>
                        x.Name == grDoc.Name
                        && x.GostOnSort == grDoc.GostOnSort
                        && x.Length == grDoc.Length
                        && x.MarkSteal == grDoc.MarkSteal
                        && x.StandartSize == grDoc.StandartSize
                        && x.Width == grDoc.Width
                        && x.Designation == grDoc.Designation
                        && x.Profile == grDoc.Profile
                        && x.Cutted == grDoc.Cutted
                        && x.Escised == grDoc.Escised);

            foreach (var positionTaskToDept in filtered)
            {
                positionTaskToDept.Escised = value;
            }
        }
 public void ShowFilesViewer(PositionTaskToDept document)
 {
     var filesController = ControllersFactory.GetFilesViewController();
     filesController.Files = document.Files;
     filesController.ShowFilesView();
 }