public TempDrawingsStorage ConvertSiemensProjectToDomainModel(SiemensProject siemensProject) { var drawSotrage = new TempDrawingsStorage(); var project = new Drawing { Count = 1, CountAll = 1 }; LoadFromArticle(siemensProject, project, drawSotrage); return drawSotrage; }
public TempDrawingsStorage ConvertExcelProjectToDomainModel(ExcelProject excelProject) { var drawSotrage = new TempDrawingsStorage(); var project = new Drawing { Count = 1, CountAll = 1 }; LoadFromProject(excelProject, project, drawSotrage); return drawSotrage; }
public virtual void SaveDrawingsToDataBase(TempDrawingsStorage storage) { storage.Drawings.Where(x => x.ParentId == null).ToList().ForEach(x => x.ParentId = ParentId); foreach (var drawing in storage.Drawings.OrderBy(x => x.Id)) { var oldId = drawing.Id; drawing.Id = null; DrawingsDataManager.Insert(drawing); storage.Drawings.Where(x => x.ParentId == oldId).ToList().ForEach(x => x.ParentId = drawing.Id); } }
public void SaveDrawingsToDataBase(TempDrawingsStorage storage) { var drawingsList = storage.Drawings.ToList().OrderBy(x => x.Id).ToList().Copy(); drawingsList.Where(x => x.ParentId == null).ToList().ForEach(x => x.ParentId = _parentId); var taskList = new List<Task>(); foreach (var drawing in drawingsList) { var oldId = drawing.Id; drawing.Id = null; _drawingsDataManager.Insert(drawing); drawingsList.Where(x => x.ParentId == oldId).ToList().ForEach(x => x.ParentId = drawing.Id); taskList.Add(_factory.StartNew(() => { LoadFiles(drawing, drawingsList); _drawingsDataManager.Update(drawing); })); } Task.WaitAll(taskList.ToArray()); }
private async void wizardControl1_NextClick(object sender, WizardCommandButtonClickEventArgs e) { if (e.Page == welcomeWizardPage) { wpPreviewPackSiemens.Enabled = false; rtbPreviewLoad.Text = string.Empty; var logger = new Logger(); ExcelProject project = null; var task = new Task(() => { project = Controller.LoadStructureExcel(btnPath.Text, logger); }); waitPanel.Visible = true; wpPreviewPackSiemens.AllowNext = false; wpPreviewPackSiemens.AllowBack = false; wpPreviewPackSiemens.AllowCancel = false; task.Start(); await task; waitPanel.Visible = false; wpPreviewPackSiemens.AllowBack = true; wpPreviewPackSiemens.AllowCancel = true; wpPreviewPackSiemens.Enabled = true; foreach (var mess in logger.Messages) { rtbPreviewLoad.AppendText(string.Format("{0}\n\r", mess.Message)); } if (!logger.ErrorHappens) { _project = project; wpPreviewPackSiemens.AllowNext = true; rtbPreviewLoad.Text += rtbPreviewLoad.Text.Length == 0 ? "Загрузка прошла успешно, ошибок нет!\nМожно переходить к следующему этапу." : "Есть предупреждения. Переходите к следующему этапу, если вы игнорируете их."; } } if (e.Page == wpPreviewPackSiemens) { wpConvertedDataView.AllowNext = false; wpConvertedDataView.AllowBack = false; wpConvertedDataView.AllowCancel = false; waitPanelConversion.Visible = true; var logger = new Logger(); var task = new Task(() => { _storage = Controller.ConvertExcelToDrawings(_project, logger); }); task.Start(); await task; waitPanelConversion.Visible = false; if (_storage != null) { tlDarwings.DataSource = _storage.Drawings; } lbMessages.DataSource = logger.Messages.Select(mess => new MessageListBox {Tag = mess.Tag, Message = mess.Message}).ToList(); waitPanelConversion.Visible = false; wpConvertedDataView.AllowNext = true; wpConvertedDataView.AllowBack = true; wpConvertedDataView.AllowCancel = true; SetVisibleLevelsLine(); } }
private void LoadFromArticle(SiemensProject siemensProject, Drawing drawing, TempDrawingsStorage drawStorage) { var childrenProject = new List<Drawing>(); drawing.Name = $"{siemensProject.Article.Head.ARTName} {siemensProject.Article.Head.ARTNameRem}".Trim(); drawing.Designation = SiemensMaterialParser.GetDesignation(siemensProject.Article); drawing.GostOnMaterial = string.Empty; drawing.GostOnSort = string.Empty; drawing.MarkSteal = string.Empty; drawing.StandartSize = string.Empty; drawing.Profile = string.Empty; drawing.Files = siemensProject.FileNames.Select(x => new UppyFileInfo() { FileName = x }).ToList(); if (siemensProject.Article.BOM.Length == 1 && siemensProject.Article.BOM[0].ARTARTPartID.Contains("#") && SiemensMaterialParser.GetDesignation(siemensProject.Article.BOM[0]) == string.Empty) { //для проектов состоящих из одного подпроекта, являющегося терминальным - загоняем всю инфу в проект var position = siemensProject.Article.BOM[0]; drawing.Weight = Convert.ToDecimal(siemensProject.Article.Head.ARTWeight) / Convert.ToInt32(position.ARTARTQuant) / 1000; drawing.CountAll = drawing.CountAll * Convert.ToInt32(position.ARTARTQuant); drawing.WeightAll = drawing.Weight * drawing.CountAll; drawing.Count = Convert.ToInt32(position.ARTARTQuant) * drawing.Count; try { drawing.Length = SiemensMaterialParser.GetLength(position); drawing.Width = SiemensMaterialParser.GetWidth(position); } catch (Exception ex) { AppendMessageToLog(new LogMessage("Ошибка парсиинга длина и/или ширины.", drawing, TypeMessage.Error)); } drawing.GostOnSort = Normalizer.SetEmptySpacesGost(SiemensMaterialParser.GetGOSTS(position)); drawing.StandartSize = SiemensMaterialParser.GetStandartSize(position); drawing.Designation = SiemensMaterialParser.GetDesignation(position) == string.Empty ? drawing.Designation : SiemensMaterialParser.GetDesignation(position); drawing.MarkSteal = SiemensMaterialParser.GetMarkSteal(position); drawing.Profile = NameMaterialSearch.GetNameMaterialByGost(drawing.GostOnSort); drawing.MarkSteal = Normalizer.RemoveUnUseInfoAboutMarkSteal(drawing.MarkSteal); DrawingStandartezer?.WriteToDrawingsStandartsField(drawing); if (DrawingExcluder?.IsNeedExclude(drawing) != true) drawStorage.Add(drawing); else { } } else { DrawingStandartezer?.WriteToDrawingsStandartsField(drawing); if (DrawingExcluder?.IsNeedExclude(drawing) == true) return; drawStorage.Add(drawing); foreach (var position in siemensProject.Article.BOM) { var subProject = new Drawing { ParentId = drawing.Id, Count = Convert.ToInt32(position.ARTARTQuant), Note = string.Empty, NumberOnSpec = Normalizer.NormalizePositionNumber(position.ARTARTPosNo), Profile = string.Empty }; subProject.CountAll = subProject.Count * drawing.CountAll; if (position.ARTARTPartID.Contains("#")) { //дальше лезть не надо subProject.Name = position.ARTARTPosName.Trim(); subProject.Designation = position.ARTARTSZNo.Trim() == "Y13 00 049" ? string.Empty : position.ARTARTSZNo.Trim(); if (subProject.Designation == string.Empty) { subProject.Designation = $"{drawing.Designation} поз. {subProject.NumberOnSpec}".Trim(); } try { subProject.Length = SiemensMaterialParser.GetLength(position); subProject.Width = SiemensMaterialParser.GetWidth(position); } catch (Exception ex) { AppendMessageToLog(new LogMessage("Ошибка парсиинга длина и/или ширины.", drawing, TypeMessage.Error)); } subProject.GostOnSort = Normalizer.SetEmptySpacesGost(SiemensMaterialParser.GetGOSTS(position)); subProject.StandartSize = SiemensMaterialParser.GetStandartSize(position); subProject.Designation = SiemensMaterialParser.GetDesignation(position) == string.Empty ? subProject.Designation : SiemensMaterialParser.GetDesignation(position); subProject.MarkSteal = SiemensMaterialParser.GetMarkSteal(position); subProject.Profile = NameMaterialSearch.GetNameMaterialByGost(subProject.GostOnSort); //subProject.Dimension = string.Empty; subProject.GostOnMaterial = string.Empty; subProject.Weight = Convert.ToDecimal(position.ARTARTPosWeight) / 1000 / subProject.Count; subProject.WeightAll = subProject.CountAll * subProject.Weight; subProject.MarkSteal = Normalizer.RemoveUnUseInfoAboutMarkSteal(subProject.MarkSteal); DrawingStandartezer?.WriteToDrawingsStandartsField(subProject); //DrawingStandartezer?.WriteToDrawingsStandartsRates(drawing); if (DrawingExcluder?.IsNeedExclude(subProject) == true) continue; childrenProject.Add(subProject); drawStorage.Add(subProject); } else { //ищем следующий файл if (!string.IsNullOrWhiteSpace(position.ARTARTPartID)) { var subSiemensProject = siemensProject.Positions.FirstOrDefault( x => x.Article.Head.ARTPartID.Contains(position.ARTARTPartID)); LoadFromArticle(subSiemensProject, subProject, drawStorage); if (DrawingExcluder?.IsNeedExclude(subProject) == true) continue; childrenProject.Add(subProject); } else { subProject.Note = position.ARTARTPosNo + "_ERROR!!!!"; subProject.Name = position.Items.Aggregate((x, y) => x.Trim() + " " + y.Trim()).Trim(); subProject.Designation = string.Empty; //subProject.Dimension = string.Empty; subProject.GostOnMaterial = string.Empty; subProject.GostOnSort = string.Empty; subProject.MarkSteal = string.Empty; subProject.StandartSize = string.Empty; drawStorage.Add(subProject); AppendMessageToLog(new LogMessage("Ошибка поиска следующего файла.", subProject, TypeMessage.Warning)); if (DrawingExcluder?.IsNeedExclude(subProject) == true) continue; childrenProject.Add(subProject); } } } drawing.WeightAll = childrenProject.Sum(x => x.WeightAll); } if (Math.Round(drawing.WeightAll) == 0) { drawing.WeightAll = Convert.ToDecimal(siemensProject.Article.Head.ARTWeight) * drawing.CountAll / 1000; } drawing.Weight = drawing.WeightAll / drawing.CountAll; }
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; }