public static void SetLaborIntensityOfProducts(LoggerForm logger) { try { logger.DefaultBoldText("Подготовка к работе."); var worksheet = (Worksheet)Globals.ThisAddIn.Application.ActiveSheet; var usedRange = (object[, ])worksheet.UsedRange.get_Value(Type.Missing); var settings = Properties.Settings.Default.LaborIntensityOfProductsSetting.Split().Select((x, i) => (Value: int.Parse(x), Group: i / 4)) .GroupBy(x => x.Group).Where(x => x.All(x => x.Value > 0)).Select(x => x.Select(y => y.Value).ToArray()).ToArray(); if (settings.Length <= 0 || !settings.All(x => x.Max() < usedRange.GetLength(1))) { logger.ErrorText(" ⚠ НАСТРОЙКИ НЕ КОРРЕКТНЫ\r\n"); return; } logger.SuccessText(" ✓ ВЫПОЛНЕНО\r\n\r\n"); logger.DefaultBoldText($"Сбор данных:\r\n"); var laborIntensityList = LoadLaborIntensityList(logger, Properties.Settings.Default.LIPMainDirectoryPath , Properties.Settings.Default.LIPExcelFileName); logger.SuccessText($"Загружено {laborIntensityList.Count} записей\r\n\r\n"); if (logger.IsClosed) { return; } logger.DefaultBoldText($"Заполнение таблицы:\r\n"); int rowCount = usedRange.GetLength(0); for (int row = 1; row <= rowCount; row++) { foreach (var setting in settings) { // 0 - заказ, 1 - марка, 2 - норма/часы, 3 - норма/чвсы (без сварки) if (usedRange[row, setting[0]] != null && usedRange[row, setting[1]] != null) { var laborIntensity = laborIntensityList.FirstOrDefault(x => x.Order == usedRange[row, setting[0]].ToString() && x.Mark == usedRange[row, setting[1]].ToString()); if (laborIntensity != null) { worksheet.Cells[row, setting[2]] = laborIntensity.HoursRate; worksheet.Cells[row, setting[3]] = laborIntensity.HoursRateWithoutWelds; logger.DefaultText($"[ст. {row}] - заказ {usedRange[row, setting[0]]}, марка {usedRange[row, setting[1]]} "); logger.DefaultBoldText($"(Н/ч = {laborIntensity.HoursRate}; Н/ч (без сварки) = {laborIntensity.HoursRateWithoutWelds}))\r\n"); } } } } logger.DefaultBoldText($"\r\nВыполнение завершено.\r\n"); } catch (Exception ex) { logger.ExceptionText(ex); } finally { logger.Complete(); } }
public static void SetWeldedAssembliesList(LoggerForm logger) { try { logger.DefaultBoldText("Подготовка к работе."); var worksheet = (Worksheet)Globals.ThisAddIn.Application.ActiveSheet; var usedRange = (object[, ])worksheet.UsedRange.get_Value(Type.Missing); var settings = Properties.Settings.Default.WeldedAssembliesSetting.Split().Select((x, i) => (Value: int.Parse(x), Group: i / 4)) .GroupBy(x => x.Group).Where(x => x.All(x => x.Value > 0)).Select(x => x.Select(y => y.Value).ToArray()).ToArray(); if (settings.Length <= 0 || !settings.All(x => x.Max() < usedRange.GetLength(1))) { logger.ErrorText(" ⚠ НАСТРОЙКИ НЕ КОРРЕКТНЫ\r\n"); return; } logger.SuccessText(" ✓ ВЫПОЛНЕНО\r\n\r\n"); logger.DefaultBoldText($"Сбор данных:\r\n"); var laborIntensityList = LoadLaborIntensityList(logger, Properties.Settings.Default.WAMainDirectoryPath , Properties.Settings.Default.WAExcelFileName); logger.SuccessText($"Загружено {laborIntensityList.Count} записей\r\n\r\n"); if (logger.IsClosed) { return; } logger.DefaultBoldText($"Заполнение таблицы:\r\n"); int rowCount = usedRange.GetLength(0); for (int row = 1; row <= rowCount; row++) { foreach (var setting in settings) { // 0 - заказ, 1 - марка, 2 - группа, 3 - норма // if (setting.All(x => usedRange[row, x] != null)) if (usedRange[row, setting[0]] != null && usedRange[row, setting[1]] != null && usedRange[row, setting[2]] != null) { var laborIntensity = laborIntensityList.FirstOrDefault(x => x.Order == usedRange[row, setting[0]].ToString() && x.Mark == usedRange[row, setting[1]].ToString()); if (laborIntensity != null) { double?value = worksheet.Cells[row, setting[3]] = (usedRange[row, setting[2]].ToString()) switch { "НО" => laborIntensity.NO1, "НО1" => laborIntensity.NO1, "НО1.1" => laborIntensity.NO11, "НО2" => laborIntensity.NO2, "НО2.1" => laborIntensity.NO21, "ГО1" => laborIntensity.GO1, "ГО2" => laborIntensity.GO2, "ГО1.1" => laborIntensity.GO11, "ГО1.2" => laborIntensity.GO12, _ => null, }; logger.DefaultText($"[ст. {row}] - заказ {usedRange[row, setting[0]]}, марка {usedRange[row, setting[1]]} "); if (value.HasValue) { logger.DefaultBoldText($"({usedRange[row, setting[2]]} = {value})\r\n"); } else { logger.ErrorText($"(Нет данных о группе [{usedRange[row, setting[2]]}]) \r\n"); } } } } } logger.DefaultBoldText($"\r\nВыполнение завершено.\r\n"); } catch (Exception ex) { logger.ExceptionText(ex); } finally { logger.Complete(); } }