RhSolutions-AddIn/RhSolutions.AddIn/Controllers/CombineTool.cs

67 lines
2.3 KiB
C#
Raw Normal View History

2022-01-09 10:37:25 +03:00
using Microsoft.Office.Interop.Excel;
2023-03-28 09:58:43 +03:00
using RhSolutions.AddIn;
2022-12-20 12:27:47 +03:00
using RhSolutions.Models;
using System;
using System.Collections.Generic;
2022-02-02 10:23:50 +03:00
using System.Linq;
2023-02-08 15:59:30 +03:00
using Range = Microsoft.Office.Interop.Excel.Range;
2022-12-20 12:27:47 +03:00
namespace RhSolutions.Controllers
{
2022-12-20 11:53:55 +03:00
internal class CombineTool : ToolBase
{
private List<SourcePriceList> SourceFiles { get; set; }
public CombineTool()
{
2023-03-28 09:58:43 +03:00
var dialog = RhSolutionsAddIn.Excel.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
dialog.AllowMultiSelect = true;
dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
2023-03-28 09:58:43 +03:00
if (dialog.Show() < 0)
{
2023-03-28 09:58:43 +03:00
List<string> files = new();
foreach (string file in dialog.SelectedItems)
{
files.Add(file);
}
SourceFiles = SourcePriceList.GetSourceLists(files.ToArray());
}
else
{
throw new Exception("Не выбраны файлы");
}
}
2022-01-27 17:34:03 +03:00
public override void FillTarget()
{
2022-04-01 17:55:36 +03:00
using (ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count)))
using (ResultBar = new ResultBar())
{
2022-04-01 17:55:36 +03:00
foreach (SourcePriceList source in SourceFiles)
2022-02-02 10:23:50 +03:00
{
2022-04-01 17:55:36 +03:00
TargetFile.Sheet.Columns[TargetFile.AmountCell.Column]
.EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
Range newColumnHeader = TargetFile.Sheet.Cells[TargetFile.AmountCell.Row, TargetFile.AmountCell.Column - 1];
newColumnHeader.Value2 = $"{source.Name}";
newColumnHeader.WrapText = true;
foreach (var kvp in source.PositionAmount)
{
FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column - 1, TargetFile.AmountCell.Column);
ProgressBar.Update();
}
2022-02-02 10:23:50 +03:00
}
2022-01-09 10:37:25 +03:00
2022-04-01 17:55:36 +03:00
FilterByAmount();
ResultBar.Update();
}
}
}
}