2022-01-27 17:34:03 +03:00
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
2021-12-24 16:22:03 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-02-02 10:23:50 +03:00
|
|
|
|
using RehauSku.Interface;
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
|
|
|
|
namespace RehauSku.PriceListTools
|
|
|
|
|
{
|
2022-02-02 18:02:17 +03:00
|
|
|
|
internal class ExportTool : AbstractTool
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
2022-01-31 17:54:18 +03:00
|
|
|
|
private Dictionary<Position, double> PositionAmount;
|
2022-01-09 10:37:25 +03:00
|
|
|
|
private Range Selection;
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
2022-02-05 13:04:18 +03:00
|
|
|
|
public ExportTool()
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
|
|
|
|
Selection = ExcelApp.Selection;
|
|
|
|
|
}
|
2022-02-01 20:32:29 +03:00
|
|
|
|
|
2022-01-27 17:34:03 +03:00
|
|
|
|
public void FillTarget()
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
GetSelected();
|
2022-02-04 09:17:12 +03:00
|
|
|
|
ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count);
|
|
|
|
|
ResultBar = new ResultBar();
|
2022-02-02 10:23:50 +03:00
|
|
|
|
|
2022-02-01 20:32:29 +03:00
|
|
|
|
foreach (var kvp in PositionAmount)
|
|
|
|
|
{
|
2022-02-03 21:44:24 +03:00
|
|
|
|
FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
|
2022-02-04 09:17:12 +03:00
|
|
|
|
ProgressBar.Update();
|
2022-02-01 20:32:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 17:34:03 +03:00
|
|
|
|
FilterByAmount();
|
2022-02-04 09:17:12 +03:00
|
|
|
|
ResultBar.Update();
|
2022-01-09 10:49:41 +03:00
|
|
|
|
|
2022-02-02 09:46:47 +03:00
|
|
|
|
Interface.Dialog.SaveWorkbookAs();
|
2022-02-04 09:17:12 +03:00
|
|
|
|
ExcelApp.StatusBar = false;
|
2021-12-24 16:22:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 17:34:03 +03:00
|
|
|
|
private void GetSelected()
|
2021-12-24 16:22:03 +03:00
|
|
|
|
{
|
2022-02-01 20:32:29 +03:00
|
|
|
|
object[,] cells = Selection.Value2;
|
2022-01-31 17:54:18 +03:00
|
|
|
|
PositionAmount = new Dictionary<Position, double>();
|
|
|
|
|
|
2021-12-24 16:22:03 +03:00
|
|
|
|
int rowsCount = Selection.Rows.Count;
|
|
|
|
|
|
|
|
|
|
for (int row = 1; row <= rowsCount; row++)
|
|
|
|
|
{
|
|
|
|
|
if (cells[row, 1] == null || cells[row, 2] == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
string sku = null;
|
|
|
|
|
double? amount = null;
|
|
|
|
|
|
|
|
|
|
for (int column = 1; column <= 2; column++)
|
|
|
|
|
{
|
|
|
|
|
object current = cells[row, column];
|
|
|
|
|
|
|
|
|
|
if (current.ToString().IsRehauSku())
|
|
|
|
|
{
|
|
|
|
|
sku = current.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (current.GetType() == typeof(string)
|
|
|
|
|
&& double.TryParse(current.ToString(), out _))
|
|
|
|
|
{
|
|
|
|
|
amount = double.Parse((string)current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (current.GetType() == typeof(double))
|
|
|
|
|
{
|
|
|
|
|
amount = (double)current;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sku == null || amount == null)
|
2022-01-27 20:43:19 +03:00
|
|
|
|
{
|
2021-12-24 16:22:03 +03:00
|
|
|
|
continue;
|
2022-01-27 20:43:19 +03:00
|
|
|
|
}
|
2021-12-24 16:22:03 +03:00
|
|
|
|
|
2022-02-01 20:32:29 +03:00
|
|
|
|
Position position = new Position(null, sku, null);
|
|
|
|
|
|
|
|
|
|
if (PositionAmount.ContainsKey(position))
|
2022-01-27 20:43:19 +03:00
|
|
|
|
{
|
2022-02-01 20:32:29 +03:00
|
|
|
|
PositionAmount[position] += amount.Value;
|
2022-01-27 20:43:19 +03:00
|
|
|
|
}
|
2022-01-31 17:54:18 +03:00
|
|
|
|
|
2021-12-24 16:22:03 +03:00
|
|
|
|
else
|
2022-01-27 20:43:19 +03:00
|
|
|
|
{
|
2022-02-01 20:32:29 +03:00
|
|
|
|
PositionAmount.Add(position, amount.Value);
|
2022-01-27 20:43:19 +03:00
|
|
|
|
}
|
2021-12-24 16:22:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|