2022-01-27 10:22:30 +03:00
|
|
|
|
using ExcelDna.Integration;
|
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace RehauSku.PriceListTools
|
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
internal abstract class PriceListTool
|
2022-01-27 10:22:30 +03:00
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
protected private Application ExcelApp = (Application)ExcelDnaUtil.Application;
|
|
|
|
|
protected private Target TargetFile;
|
2022-01-28 15:38:57 +03:00
|
|
|
|
protected private List<KeyValuePair<Position, double>> Missing;
|
2022-01-27 10:22:30 +03:00
|
|
|
|
|
2022-01-27 17:34:03 +03:00
|
|
|
|
public void OpenNewPrice()
|
2022-01-27 10:22:30 +03:00
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
Workbook wb = ExcelApp.Workbooks.Open(RegistryUtil.PriceListPath);
|
2022-01-27 10:22:30 +03:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
TargetFile = new Target(wb);
|
2022-01-27 10:22:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show
|
|
|
|
|
(ex.Message,
|
|
|
|
|
"Ошибка открытия шаблонного прайс-листа",
|
|
|
|
|
System.Windows.Forms.MessageBoxButtons.OK,
|
|
|
|
|
System.Windows.Forms.MessageBoxIcon.Information);
|
|
|
|
|
wb.Close();
|
2022-01-27 17:34:03 +03:00
|
|
|
|
throw ex;
|
2022-01-27 10:22:30 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 15:11:39 +03:00
|
|
|
|
protected private void FillColumn(IEnumerable<KeyValuePair<Position, double>> dictionary, params int[] columns)
|
2022-01-27 10:22:30 +03:00
|
|
|
|
{
|
2022-01-28 15:38:57 +03:00
|
|
|
|
Missing = new List<KeyValuePair<Position, double>>();
|
2022-01-28 08:51:47 +03:00
|
|
|
|
|
2022-01-27 20:43:19 +03:00
|
|
|
|
foreach (var kvp in dictionary)
|
2022-01-27 10:22:30 +03:00
|
|
|
|
{
|
2022-01-28 15:38:57 +03:00
|
|
|
|
FillPosition(kvp, columns);
|
2022-01-27 10:22:30 +03:00
|
|
|
|
}
|
2022-01-27 20:43:19 +03:00
|
|
|
|
|
2022-01-28 15:38:57 +03:00
|
|
|
|
if (Missing.Count > 0)
|
2022-01-28 09:14:56 +03:00
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show
|
2022-01-28 15:38:57 +03:00
|
|
|
|
($"{Missing.Count} артикулов отсутствует в таблице заказов {RegistryUtil.PriceListPath} Попробовать найти новый вариант?",
|
2022-01-28 09:14:56 +03:00
|
|
|
|
"Отсутствует позиция в конечной таблице заказов",
|
2022-01-28 09:27:45 +03:00
|
|
|
|
System.Windows.Forms.MessageBoxButtons.YesNo,
|
2022-01-28 09:14:56 +03:00
|
|
|
|
System.Windows.Forms.MessageBoxIcon.Information);
|
|
|
|
|
}
|
2022-01-27 10:22:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 15:38:57 +03:00
|
|
|
|
protected private void FillPosition(KeyValuePair<Position, double> kvp, int[] columns)
|
2022-01-28 15:21:58 +03:00
|
|
|
|
{
|
|
|
|
|
Range foundCell = TargetFile.skuCell.EntireColumn.Find(kvp.Key.Sku);
|
|
|
|
|
if (foundCell == null)
|
|
|
|
|
{
|
2022-01-28 15:38:57 +03:00
|
|
|
|
Missing.Add(kvp);
|
2022-01-28 15:21:58 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 15:38:57 +03:00
|
|
|
|
string foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
|
2022-01-28 15:21:58 +03:00
|
|
|
|
|
|
|
|
|
while (foundCell != null && foundCellGroup != kvp.Key.Group)
|
|
|
|
|
{
|
|
|
|
|
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
|
2022-01-28 15:38:57 +03:00
|
|
|
|
foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
|
2022-01-28 15:21:58 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (foundCell == null)
|
|
|
|
|
{
|
2022-01-28 15:38:57 +03:00
|
|
|
|
Missing.Add(kvp);
|
2022-01-28 15:21:58 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var column in columns)
|
|
|
|
|
{
|
|
|
|
|
Range sumCell = TargetFile.Sheet.Cells[foundCell.Row, column];
|
|
|
|
|
if (sumCell.Value2 == null)
|
|
|
|
|
{
|
|
|
|
|
sumCell.Value2 = kvp.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sumCell.Value2 += kvp.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 10:22:30 +03:00
|
|
|
|
protected private void FilterByAmount()
|
|
|
|
|
{
|
2022-01-27 17:34:03 +03:00
|
|
|
|
AutoFilter filter = TargetFile.Sheet.AutoFilter;
|
2022-01-27 10:22:30 +03:00
|
|
|
|
|
2022-01-27 17:34:03 +03:00
|
|
|
|
filter.Range.AutoFilter(TargetFile.amountCell.Column, "<>");
|
|
|
|
|
TargetFile.Sheet.Range["A1"].Activate();
|
2022-01-27 10:22:30 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|