aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools/PriceList.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/PriceListTools/PriceList.cs')
-rw-r--r--src/PriceListTools/PriceList.cs100
1 files changed, 73 insertions, 27 deletions
diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs
index 35b3f7d..c39b0ba 100644
--- a/src/PriceListTools/PriceList.cs
+++ b/src/PriceListTools/PriceList.cs
@@ -1,5 +1,6 @@
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
+using System.Linq;
namespace RehauSku.PriceListTools
{
@@ -9,31 +10,25 @@ namespace RehauSku.PriceListTools
public readonly PriceListSheet OfferSheet;
public readonly PriceListSheet ActiveSheet;
- private const string _amountHeader = "Кол-во";
- private const string _skuHeader = "Актуальный материал";
- private const string _offerSheetHeader = "КП";
+ private const string amountHeader = "Кол-во";
+ private const string skuHeader = "Актуальный материал";
+ private const string offerSheetHeader = "КП";
public PriceList(Workbook workbook)
{
Workbook = workbook;
- OfferSheet = new PriceListSheet(workbook.Sheets[_offerSheetHeader]);
+ OfferSheet = new PriceListSheet(workbook.Sheets[offerSheetHeader]);
Worksheet active = workbook.ActiveSheet;
- if (active.Name == _offerSheetHeader)
+ if (active.Name == offerSheetHeader)
ActiveSheet = OfferSheet;
else
- ActiveSheet = new PriceListSheet(active);
+ ActiveSheet = new PriceListSheet(active);
}
- public bool IsValid()
- {
- return OfferSheet.IsValid() &&
- ActiveSheet.IsValid();
- }
-
- public void Fill(Dictionary<string, double> values)
+ public void FillWithValues(Dictionary<string, double> values)
{
Worksheet ws = OfferSheet.sheet;
ws.Activate();
@@ -45,6 +40,7 @@ namespace RehauSku.PriceListTools
foreach (KeyValuePair<string, double> kvp in values)
{
Range cell = ws.Columns[skuColumn].Find(kvp.Key);
+
if (cell == null)
{
System.Windows.Forms.MessageBox.Show
@@ -53,6 +49,7 @@ namespace RehauSku.PriceListTools
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
}
+
else
{
ws.Cells[cell.Row, amountColumn].Value = kvp.Value;
@@ -68,33 +65,82 @@ namespace RehauSku.PriceListTools
ws.Application.StatusBar = $"Экспортировано {exportedValues} строк из {values.Count}";
}
+ public void FillWithValues(Dictionary<string, double>[] values, string[] filenames)
+ {
+ Worksheet ws = OfferSheet.sheet;
+ ws.Activate();
+
+ int amountColumn = OfferSheet.amountColumn.Value;
+ int skuColumn = OfferSheet.skuColumn.Value;
+ int headerColumn = OfferSheet.headerRow.Value;
+
+ int exportedValues = 0;
+
+ for (int i = 0; i < values.Length; i++)
+ {
+ ws.Columns[amountColumn]
+ .EntireColumn
+ .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
+
+ foreach (var kvp in values[i])
+ {
+ Range cell = ws.Columns[skuColumn].Find(kvp.Key);
+
+ if (cell == null)
+ {
+ System.Windows.Forms.MessageBox.Show
+ ($"Артикул {kvp.Key} отсутствует в таблице заказов {RegistryUtil.PriceListPath}",
+ "Отсутствует позиция в конечной таблице заказов",
+ System.Windows.Forms.MessageBoxButtons.OK,
+ System.Windows.Forms.MessageBoxIcon.Information);
+ }
+
+ else
+ {
+ ws.Cells[cell.Row, amountColumn].Value2 = kvp.Value;
+ Range sumCell = ws.Cells[cell.Row, amountColumn + i + 1];
+
+ if (sumCell.Value2 == null)
+ sumCell.Value2 = kvp.Value;
+ else
+ sumCell.Value2 += kvp.Value;
+
+ exportedValues++;
+ }
+ }
+
+ ws.Cells[headerColumn, amountColumn].Value2 = filenames[i];
+ }
+
+ AutoFilter filter = ws.AutoFilter;
+ int firstFilterColumn = filter.Range.Column;
+
+ filter.Range.AutoFilter(amountColumn - firstFilterColumn + 1 + values.Length, "<>");
+ ws.Range["A1"].Activate();
+ ws.Application.StatusBar = $"Экспортировано {exportedValues} строк из {values.Sum(x => x.Count)}";
+ }
+
public class PriceListSheet
{
public readonly Worksheet sheet;
public readonly int? headerRow;
- public readonly int? amountColumn;
+
public readonly int? skuColumn;
- public object[,] amountCells;
+ public readonly int? amountColumn;
+
public object[,] skuCells;
+ public object[,] amountCells;
public PriceListSheet(Worksheet sheet)
{
this.sheet = sheet;
- headerRow = sheet.Cells.Find(_amountHeader).Row;
- amountColumn = sheet.Cells.Find(_amountHeader).Column;
- skuColumn = sheet.Cells.Find(_skuHeader).Column;
+ headerRow = sheet.Cells.Find(amountHeader).Row;
+ amountColumn = sheet.Cells.Find(amountHeader).Column;
+ skuColumn = sheet.Cells.Find(skuHeader).Column;
amountCells = sheet.Columns[amountColumn].Value2;
skuCells = sheet.Columns[skuColumn].Value2;
- }
-
- public bool IsValid()
- {
- return sheet != null &&
- headerRow != null &&
- amountColumn != null &&
- skuColumn != null;
- }
+ }
}
}
}