57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using RhSolutions.AddIn;
|
||
using RhSolutions.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace RhSolutions.Controllers
|
||
{
|
||
internal class MergeTool : ToolBase
|
||
{
|
||
private List<SourcePriceList> SourceFiles { get; set; }
|
||
|
||
public MergeTool()
|
||
{
|
||
var dialog = RhSolutionsAddIn.Excel.FileDialog[Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFilePicker];
|
||
dialog.AllowMultiSelect = true;
|
||
dialog.Filters.Add("Файлы Excel", "*.xls; *.xlsx; *.xlsm");
|
||
|
||
if ( dialog.Show() < 0)
|
||
{
|
||
List<string> files = new();
|
||
|
||
foreach (string file in dialog.SelectedItems)
|
||
{
|
||
files.Add(file);
|
||
}
|
||
|
||
SourceFiles = SourcePriceList.GetSourceLists(files.ToArray());
|
||
}
|
||
|
||
else
|
||
{
|
||
throw new Exception("Не выбраны файлы");
|
||
}
|
||
}
|
||
|
||
public override void FillTarget()
|
||
{
|
||
using (ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count)))
|
||
using (ResultBar = new ResultBar())
|
||
{
|
||
foreach (SourcePriceList source in SourceFiles)
|
||
{
|
||
foreach (var kvp in source.PositionAmount)
|
||
{
|
||
FillPositionAmountToColumns(kvp, TargetFile.AmountCell.Column);
|
||
ProgressBar.Update();
|
||
}
|
||
}
|
||
|
||
FilterByAmount();
|
||
ResultBar.Update();
|
||
}
|
||
}
|
||
}
|
||
}
|