Example #1
0
 public string GetDesignation(ExcelProject position)
 {
     var des = position.GetField(3) == null ? string.Empty : position.GetField(3).ToString().Trim();
     if (des.Contains("\\") || des.Contains("/"))
         return String.Empty;
     return des;
 }
Example #2
0
        public string GetNumberBySpec(ExcelProject position)
        {
            var spec = position.GetField(2) == null ? string.Empty : position.GetField(2).ToString().Trim();
           

            return spec;
        }
Example #3
0
        public int? GetLength(ExcelProject position)
        {
            var sep = position.GetField(11) == null ? string.Empty : position.GetField(11).ToString().Trim();
            if (!string.IsNullOrWhiteSpace(sep))
            {
                return Convert.ToInt32(sep);
            }

            return null;
        }
Example #4
0
 public string GetMarkSteal(ExcelProject position)
 {
     return position.GetField(9) == null ? string.Empty : position.GetField(9).ToString().Trim();
 }
Example #5
0
 public string GetStandartSize(ExcelProject position)
 {
     return position.GetField(6) == null ? string.Empty : position.GetField(6).ToString().Trim();
 }
Example #6
0
 public string GetGOSTS(ExcelProject position)
 {
     return position.GetField(8) == null ? string.Empty : position.GetField(8).ToString().Trim();
 }
Example #7
0
        protected virtual List<ExcelProject> GetListRows(string fileName)
        {
            var stream = File.OpenRead(fileName);
            var excelPack = new ExcelPackage();
            excelPack.Load(stream);
            stream.Close();

            var header = excelPack.Workbook.Worksheets[1].Cells[2, 1, 2, 18];

            var listRows = new List<ExcelProject>();

            var listCaption = new List<string>();
            for (int i = 0; i < 18; i++)
            {
                listCaption.Add(((object[,])header.Value)[0, i].ToString());
            }

            for (int i = 3; i <= excelPack.Workbook.Worksheets[1].Dimension.Rows; i++)
            {
                var structure = new ExcelProject();
                
                var dataRow = excelPack.Workbook.Worksheets[1].Cells[i, 1, i, 18];
                structure.Row = new object[18];
                for (int j = 0; j < 18; j++)
                {
                    structure.Row[j] = ((object[,])dataRow.Value)[0, j];
                }

                structure.ColumnsCaptions = listCaption;
                structure.FileNames = _docsFileName.GetFilesByNameDrawing(structure.GetField(3)?.ToString());
                listRows.Add(structure);
            }

            return listRows;
        }
        private void LoadFromProject(ExcelProject excelProject, Drawing drawing, TempDrawingsStorage drawStorage)
        {
            var childrenProject = new List<Drawing>();

            drawing.Name = excelProject.GetField(4)?.ToString().Trim();
            drawing.Designation = excelProject.GetField(3)?.ToString().Trim();
            drawing.Designation = drawing.Designation?.Replace("СБ", String.Empty).Trim() ?? String.Empty;
            drawing.GostOnMaterial = string.Empty;
            drawing.GostOnSort = string.Empty;
            drawing.MarkSteal = string.Empty;
            drawing.StandartSize = string.Empty;
            drawing.Profile = string.Empty;
            drawing.Files = excelProject.FileNames.Select(x => new UppyFileInfo() { FileName = x }).ToList();
            drawing.OP = excelProject.GetField(17) == null ? String.Empty : excelProject.GetField(17).ToString();

            DrawingStandartezer?.WriteToDrawingsStandartsField(drawing);

            if (DrawingExcluder?.IsNeedExclude(drawing) == true)
                return;

            drawStorage.Add(drawing);

            foreach (ExcelProject position in excelProject.Positions)
            {
                var subProject = new Drawing
                {
                    ParentId = drawing.Id,
                    Count = Convert.ToInt32(position.GetField(13)),
                    Note = string.Empty,
                    NumberOnSpec = Normalizer.NormalizePositionNumber(position.GetField(3)?.ToString()),
                    Profile = string.Empty
                };

                subProject.CountAll = subProject.Count * drawing.CountAll;

                if (position.Positions == null || position.Positions.Count == 0)
                {
                    //дальше лезть не надо
                    subProject.Name = position.GetField(4)?.ToString().Trim();
                    subProject.Designation = ExcelMaterialParser.GetDesignation(position) == string.Empty ? subProject.Designation : ExcelMaterialParser.GetDesignation(position);
                    subProject.NumberOnSpec = ExcelMaterialParser.GetNumberBySpec(position);

                    if (subProject.Designation == string.Empty)
                    {
                        subProject.Designation = $"{drawing.Designation} поз. {subProject.NumberOnSpec}".Trim();
                    }

                    try
                    {
                        subProject.Length = ExcelMaterialParser.GetLength(position);
                        subProject.Width = ExcelMaterialParser.GetWidth(position);
                    }
                    catch (Exception ex)
                    {
                        AppendMessageToLog(new LogMessage("Ошибка парсиинга длина и/или ширины.", drawing, TypeMessage.Error));
                    }

                    subProject.GostOnSort = Normalizer.SetEmptySpacesGost(ExcelMaterialParser.GetGOSTS(position));
                    subProject.StandartSize = ExcelMaterialParser.GetStandartSize(position);
                    
                    subProject.MarkSteal = ExcelMaterialParser.GetMarkSteal(position);
                    subProject.Profile = NameMaterialSearch.GetNameMaterialByGost(subProject.GostOnSort);
                    //subProject.Dimension = string.Empty;
                    subProject.GostOnMaterial = string.Empty;
                    subProject.Weight = Convert.ToDecimal(position.GetField(15));
                    subProject.WeightAll = subProject.CountAll * subProject.Weight;
                    subProject.MarkSteal = Normalizer.RemoveUnUseInfoAboutMarkSteal(subProject.MarkSteal);
                    DrawingStandartezer?.WriteToDrawingsStandartsField(subProject);
                    //DrawingStandartezer?.WriteToDrawingsStandartsRates(drawing);
                    subProject.OP = position.GetField(17) == null ? String.Empty : position.GetField(17).ToString();
                    subProject.Files = position.FileNames.Select(x => new UppyFileInfo() { FileName = x }).ToList();

                    if (DrawingExcluder?.IsNeedExclude(subProject) == true)
                        continue;

                    childrenProject.Add(subProject);
                    drawStorage.Add(subProject);
                }
                else
                {
                    LoadFromProject(position, subProject, drawStorage);
                    childrenProject.Add(subProject);
                }
            }

            drawing.WeightAll = childrenProject.Sum(x => x.WeightAll);


            if (Math.Round(drawing.WeightAll) == 0)
            {
                drawing.WeightAll = Convert.ToDecimal(excelProject.GetField(15)) * drawing.CountAll;
            }

            drawing.Weight = drawing.WeightAll / drawing.CountAll;
        }