Refactoring, Not fount table formatting etc
This commit is contained in:
parent
cfb15d1279
commit
7e5020ec25
@ -1,8 +1,8 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System.IO;
|
|
||||||
using RehauSku.Forms;
|
using RehauSku.Forms;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using ExcelDna.Integration;
|
|
||||||
|
|
||||||
namespace RehauSku
|
namespace RehauSku
|
||||||
{
|
{
|
||||||
@ -24,22 +24,27 @@ namespace RehauSku
|
|||||||
RootKey.Close();
|
RootKey.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsPriceListPathEmpty()
|
|
||||||
{
|
|
||||||
return string.IsNullOrEmpty(priceListPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string PriceListPath
|
public static string PriceListPath
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (IsPriceListPathEmpty() || !File.Exists(priceListPath))
|
if (string.IsNullOrEmpty(priceListPath) || !File.Exists(priceListPath))
|
||||||
{
|
{
|
||||||
//MessageBox.Show("Прайс-лист отсутствует или неверный файл прайс-листа", "Укажите файл прайс-листа", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
DialogResult result = MessageBox.Show("Прайс-лист отсутствует или неверный файл шаблона прайс-листа. " +
|
||||||
string fileName = Dialog.GetFilePath();
|
"Укажите файл шаблона прайс-листа.",
|
||||||
priceListPath = fileName;
|
"Нет файла шаблона",
|
||||||
RootKey.SetValue("PriceListPath", fileName);
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
return priceListPath;
|
|
||||||
|
if (result == DialogResult.OK)
|
||||||
|
{
|
||||||
|
string fileName = Dialog.GetFilePath();
|
||||||
|
priceListPath = fileName;
|
||||||
|
RootKey.SetValue("PriceListPath", fileName);
|
||||||
|
return priceListPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
throw new Exception("Нет файла шаблона");
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -9,8 +9,6 @@ namespace RehauSku.PriceListTools
|
|||||||
|
|
||||||
public void FillTarget()
|
public void FillTarget()
|
||||||
{
|
{
|
||||||
ExcelApp.ScreenUpdating = false;
|
|
||||||
|
|
||||||
foreach (Source source in SourceFiles)
|
foreach (Source source in SourceFiles)
|
||||||
{
|
{
|
||||||
TargetFile.Sheet.Columns[TargetFile.amountCell.Column]
|
TargetFile.Sheet.Columns[TargetFile.amountCell.Column]
|
||||||
@ -21,11 +19,11 @@ namespace RehauSku.PriceListTools
|
|||||||
newColumnHeader.Value2 = $"{source.Name}";
|
newColumnHeader.Value2 = $"{source.Name}";
|
||||||
newColumnHeader.WrapText = true;
|
newColumnHeader.WrapText = true;
|
||||||
|
|
||||||
FillColumnsWithDictionary(source.PositionAmount, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
|
foreach(var kvp in source.PositionAmount)
|
||||||
|
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterByAmount();
|
FilterByAmount();
|
||||||
ExcelApp.ScreenUpdating = true;
|
|
||||||
|
|
||||||
Forms.Dialog.SaveWorkbookAs();
|
Forms.Dialog.SaveWorkbookAs();
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,10 @@ namespace RehauSku.PriceListTools
|
|||||||
|
|
||||||
public void FillTarget()
|
public void FillTarget()
|
||||||
{
|
{
|
||||||
ExcelApp.ScreenUpdating = false;
|
foreach (var kvp in Current.PositionAmount)
|
||||||
FillColumnsWithDictionary(Current.PositionAmount, TargetFile.amountCell.Column);
|
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
|
||||||
|
|
||||||
FilterByAmount();
|
FilterByAmount();
|
||||||
ExcelApp.ScreenUpdating = true;
|
|
||||||
|
|
||||||
Forms.Dialog.SaveWorkbookAs();
|
Forms.Dialog.SaveWorkbookAs();
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,17 @@ namespace RehauSku.PriceListTools
|
|||||||
throw new Exception("Неверный диапазон");
|
throw new Exception("Неверный диапазон");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FillTarget()
|
public void FillTarget()
|
||||||
{
|
{
|
||||||
ExcelApp.ScreenUpdating = false;
|
|
||||||
GetSelected();
|
GetSelected();
|
||||||
FillColumnsWithDictionary(PositionAmount, TargetFile.amountCell.Column);
|
|
||||||
|
foreach (var kvp in PositionAmount)
|
||||||
|
{
|
||||||
|
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
|
||||||
|
}
|
||||||
|
|
||||||
FilterByAmount();
|
FilterByAmount();
|
||||||
ExcelApp.ScreenUpdating = true;
|
|
||||||
|
|
||||||
Forms.Dialog.SaveWorkbookAs();
|
Forms.Dialog.SaveWorkbookAs();
|
||||||
}
|
}
|
||||||
@ -33,7 +37,6 @@ namespace RehauSku.PriceListTools
|
|||||||
private void GetSelected()
|
private void GetSelected()
|
||||||
{
|
{
|
||||||
object[,] cells = Selection.Value2;
|
object[,] cells = Selection.Value2;
|
||||||
Dictionary<string, double> SkuAmount = new Dictionary<string, double>();
|
|
||||||
PositionAmount = new Dictionary<Position, double>();
|
PositionAmount = new Dictionary<Position, double>();
|
||||||
|
|
||||||
int rowsCount = Selection.Rows.Count;
|
int rowsCount = Selection.Rows.Count;
|
||||||
@ -72,21 +75,18 @@ namespace RehauSku.PriceListTools
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SkuAmount.ContainsKey(sku))
|
Position position = new Position(null, sku, null);
|
||||||
|
|
||||||
|
if (PositionAmount.ContainsKey(position))
|
||||||
{
|
{
|
||||||
SkuAmount[sku] += amount.Value;
|
PositionAmount[position] += amount.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SkuAmount.Add(sku, amount.Value);
|
PositionAmount.Add(position, amount.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var kvp in SkuAmount)
|
|
||||||
{
|
|
||||||
PositionAmount.Add(new Position(null, kvp.Key, null), kvp.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace RehauSku.PriceListTools
|
namespace RehauSku.PriceListTools
|
||||||
{
|
{
|
||||||
@ -9,15 +8,13 @@ namespace RehauSku.PriceListTools
|
|||||||
|
|
||||||
public void FillTarget()
|
public void FillTarget()
|
||||||
{
|
{
|
||||||
ExcelApp.ScreenUpdating = false;
|
|
||||||
|
|
||||||
foreach (Source source in SourceFiles)
|
foreach (Source source in SourceFiles)
|
||||||
{
|
{
|
||||||
FillColumnsWithDictionary(source.PositionAmount, TargetFile.amountCell.Column);
|
foreach (var kvp in source.PositionAmount)
|
||||||
|
FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterByAmount();
|
FilterByAmount();
|
||||||
ExcelApp.ScreenUpdating = true;
|
|
||||||
|
|
||||||
Forms.Dialog.SaveWorkbookAs();
|
Forms.Dialog.SaveWorkbookAs();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ namespace RehauSku.PriceListTools
|
|||||||
{
|
{
|
||||||
protected private Application ExcelApp = (Application)ExcelDnaUtil.Application;
|
protected private Application ExcelApp = (Application)ExcelDnaUtil.Application;
|
||||||
protected private Target TargetFile;
|
protected private Target TargetFile;
|
||||||
protected private List<KeyValuePair<Position, double>> Missing;
|
|
||||||
|
|
||||||
public void OpenNewPrice()
|
public void OpenNewPrice()
|
||||||
{
|
{
|
||||||
@ -34,77 +33,15 @@ namespace RehauSku.PriceListTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected private void FillColumnsWithDictionary(IEnumerable<KeyValuePair<Position, double>> dictionary, params int[] columns)
|
protected private void FillColumnsWithDictionary(KeyValuePair<Position, double> positionAmount, params int[] columns)
|
||||||
{
|
{
|
||||||
Missing = new List<KeyValuePair<Position, double>>();
|
int? row = GetPositionRow(positionAmount.Key.Sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
|
||||||
|
|
||||||
foreach (var positionAmount in dictionary)
|
if (row != null)
|
||||||
{
|
{
|
||||||
FillPositionAmountToColumns(positionAmount, columns);
|
foreach (int column in columns)
|
||||||
}
|
|
||||||
|
|
||||||
if (Missing.Count > 0)
|
|
||||||
{
|
|
||||||
DialogResult result =
|
|
||||||
MessageBox.Show
|
|
||||||
($"{Missing.Count} артикулов отсутствует в таблице заказов {RegistryUtil.PriceListPath} Попробовать найти новый вариант?",
|
|
||||||
"Отсутствует позиция в конечной таблице заказов",
|
|
||||||
MessageBoxButtons.YesNo,
|
|
||||||
MessageBoxIcon.Information);
|
|
||||||
|
|
||||||
if (result == DialogResult.Yes)
|
|
||||||
{
|
{
|
||||||
var lookUp = new List<KeyValuePair<Position, double>>(Missing);
|
Range sumCell = TargetFile.Sheet.Cells[row, column];
|
||||||
|
|
||||||
foreach (var missingPosition in lookUp)
|
|
||||||
{
|
|
||||||
TryFillVariantlessSkuToColumns(missingPosition, columns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Missing.Count > 0)
|
|
||||||
{
|
|
||||||
FillMissing(columns);
|
|
||||||
MessageBox.Show
|
|
||||||
($"{Missing.Count} артикулов отсутствует в таблице заказов {RegistryUtil.PriceListPath}\n" +
|
|
||||||
$"Под основной таблицей составлен список не найденных артикулов",
|
|
||||||
"Отсутствует позиция в конечной таблице заказов",
|
|
||||||
MessageBoxButtons.OK,
|
|
||||||
MessageBoxIcon.Information);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected private void FillPositionAmountToColumns(KeyValuePair<Position, double> positionAmount, int[] columns)
|
|
||||||
{
|
|
||||||
Range foundCell = TargetFile.skuCell.EntireColumn.Find(positionAmount.Key.Sku);
|
|
||||||
|
|
||||||
if (foundCell == null)
|
|
||||||
{
|
|
||||||
Missing.Add(positionAmount);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
|
|
||||||
|
|
||||||
while (foundCell != null && foundCellGroup != positionAmount.Key.Group)
|
|
||||||
{
|
|
||||||
if (positionAmount.Key.Group == null) break;
|
|
||||||
|
|
||||||
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
|
|
||||||
foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundCell == null)
|
|
||||||
{
|
|
||||||
Missing.Add(positionAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (var column in columns)
|
|
||||||
{
|
|
||||||
Range sumCell = TargetFile.Sheet.Cells[foundCell.Row, column];
|
|
||||||
|
|
||||||
if (sumCell.Value2 == null)
|
if (sumCell.Value2 == null)
|
||||||
{
|
{
|
||||||
@ -117,81 +54,115 @@ namespace RehauSku.PriceListTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected private void TryFillVariantlessSkuToColumns(KeyValuePair<Position, double> positionAmount, int[] columns)
|
else
|
||||||
{
|
|
||||||
string sku = positionAmount.Key.Sku.Substring(1, 6);
|
|
||||||
|
|
||||||
Range foundCell = TargetFile.skuCell.EntireColumn.Find(sku);
|
|
||||||
|
|
||||||
if (foundCell == null)
|
|
||||||
{
|
{
|
||||||
return;
|
string sku = positionAmount.Key.Sku.Substring(1, 6);
|
||||||
}
|
|
||||||
|
|
||||||
string foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
|
row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
|
||||||
|
|
||||||
while (foundCell != null && foundCellGroup != positionAmount.Key.Group)
|
if (row != null)
|
||||||
{
|
|
||||||
if (positionAmount.Key.Group == null) break;
|
|
||||||
|
|
||||||
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
|
|
||||||
foundCellGroup = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundCell == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var column in columns)
|
|
||||||
{
|
|
||||||
Range sumCell = TargetFile.Sheet.Cells[foundCell.Row, column];
|
|
||||||
|
|
||||||
if (sumCell.Value2 == null)
|
|
||||||
{
|
{
|
||||||
sumCell.Value2 = positionAmount.Value;
|
foreach (int column in columns)
|
||||||
|
{
|
||||||
|
Range amountCell = TargetFile.Sheet.Cells[row, column];
|
||||||
|
|
||||||
|
if (amountCell.Value2 == null)
|
||||||
|
{
|
||||||
|
amountCell.Value2 = positionAmount.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
amountCell.Value2 += positionAmount.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Range oldSkuCell = TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column];
|
||||||
|
oldSkuCell.Value2 = positionAmount.Key.Sku;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sumCell.Value2 += positionAmount.Value;
|
FillMissing(positionAmount, columns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Missing.Remove(positionAmount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected private void FillMissing(int[] columns)
|
protected private void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns)
|
||||||
{
|
{
|
||||||
int startRow =
|
Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku);
|
||||||
TargetFile.Sheet.AutoFilter.Range.Row +
|
int row;
|
||||||
TargetFile.Sheet.AutoFilter.Range.Rows.Count + 5;
|
|
||||||
|
|
||||||
for (int i = 0; i < Missing.Count; i++)
|
if (foundCell == null)
|
||||||
{
|
{
|
||||||
Range group = TargetFile.Sheet.Cells[startRow + i, TargetFile.groupCell.Column];
|
row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column]
|
||||||
Range sku = TargetFile.Sheet.Cells[startRow + i, TargetFile.skuCell.Column];
|
.End[XlDirection.xlUp]
|
||||||
Range name = TargetFile.Sheet.Cells[startRow + i, TargetFile.nameCell.Column];
|
.Row + 1;
|
||||||
|
|
||||||
group.Value2 = Missing[i].Key.Group;
|
TargetFile.Sheet.Rows[row]
|
||||||
sku.Value2 = Missing[i].Key.Sku;
|
.EntireRow
|
||||||
name.Value2 = Missing[i].Key.Name;
|
.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
|
||||||
|
|
||||||
group.ClearFormats();
|
Range previous = TargetFile.Sheet.Rows[row - 1];
|
||||||
sku.ClearFormats();
|
Range current = TargetFile.Sheet.Rows[row];
|
||||||
name.ClearFormats();
|
|
||||||
|
|
||||||
foreach (int column in columns)
|
previous.Copy(current);
|
||||||
|
current.ClearContents();
|
||||||
|
|
||||||
|
TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group;
|
||||||
|
TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku;
|
||||||
|
TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name;
|
||||||
|
TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = "Не найден";
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
row = foundCell.Row;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (int column in columns)
|
||||||
|
{
|
||||||
|
if (TargetFile.Sheet.Cells[row, column].Value2 == null)
|
||||||
{
|
{
|
||||||
Range amount = TargetFile.Sheet.Cells[startRow + i, column];
|
TargetFile.Sheet.Cells[row, column].Value2 = positionAmount.Value;
|
||||||
amount.Value2 = Missing[i].Value;
|
}
|
||||||
amount.ClearFormats();
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TargetFile.Sheet.Cells[row, column].Value2 += positionAmount.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected private int? GetPositionRow(string sku, string group, int column)
|
||||||
|
{
|
||||||
|
int? row = null;
|
||||||
|
Range foundCell = TargetFile.Sheet.Columns[column].Find(sku);
|
||||||
|
string foundGroupValue;
|
||||||
|
|
||||||
|
if (foundCell == null) return null;
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
row = foundCell.Row;
|
||||||
|
foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(group) || group.Equals(foundGroupValue))
|
||||||
|
return row;
|
||||||
|
|
||||||
|
else
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
foundCell = TargetFile.skuCell.EntireColumn.FindNext(foundCell);
|
||||||
|
if (foundCell == null) return row;
|
||||||
|
|
||||||
|
foundGroupValue = TargetFile.Sheet.Cells[foundCell.Row, TargetFile.groupCell.Column].Value2.ToString();
|
||||||
|
if (group.Equals(foundGroupValue)) return foundCell.Row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected private void FilterByAmount()
|
protected private void FilterByAmount()
|
||||||
{
|
{
|
||||||
AutoFilter filter = TargetFile.Sheet.AutoFilter;
|
AutoFilter filter = TargetFile.Sheet.AutoFilter;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Microsoft.Office.Interop.Excel;
|
using Microsoft.Office.Interop.Excel;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace RehauSku.PriceListTools
|
namespace RehauSku.PriceListTools
|
||||||
{
|
{
|
||||||
@ -19,12 +20,15 @@ namespace RehauSku.PriceListTools
|
|||||||
Sheet = workbook.ActiveSheet;
|
Sheet = workbook.ActiveSheet;
|
||||||
Name = workbook.Name;
|
Name = workbook.Name;
|
||||||
|
|
||||||
amountCell = Sheet.Cells.Find(amountHeader);
|
Range[] cells = new []
|
||||||
skuCell = Sheet.Cells.Find(skuHeader);
|
{
|
||||||
groupCell = Sheet.Cells.Find(groupHeader);
|
amountCell = Sheet.Cells.Find(amountHeader),
|
||||||
nameCell = Sheet.Cells.Find(nameHeader);
|
skuCell = Sheet.Cells.Find(skuHeader),
|
||||||
|
groupCell = Sheet.Cells.Find(groupHeader),
|
||||||
|
nameCell = Sheet.Cells.Find(nameHeader)
|
||||||
|
};
|
||||||
|
|
||||||
if (amountCell == null || skuCell == null || groupCell == null || nameCell == null)
|
if (cells.Any(x => x == null))
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Файл {Name} не распознан");
|
throw new ArgumentException($"Файл {Name} не распознан");
|
||||||
}
|
}
|
||||||
@ -38,9 +42,9 @@ namespace RehauSku.PriceListTools
|
|||||||
|
|
||||||
List<Source> sourceFiles = new List<Source>();
|
List<Source> sourceFiles = new List<Source>();
|
||||||
|
|
||||||
ExcelApp.ScreenUpdating = false;
|
|
||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
|
ExcelApp.ScreenUpdating = false;
|
||||||
Workbook wb = ExcelApp.Workbooks.Open(file);
|
Workbook wb = ExcelApp.Workbooks.Open(file);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -57,8 +61,8 @@ namespace RehauSku.PriceListTools
|
|||||||
System.Windows.Forms.MessageBoxIcon.Information);
|
System.Windows.Forms.MessageBoxIcon.Information);
|
||||||
wb.Close();
|
wb.Close();
|
||||||
}
|
}
|
||||||
|
ExcelApp.ScreenUpdating = true;
|
||||||
}
|
}
|
||||||
ExcelApp.ScreenUpdating = true;
|
|
||||||
|
|
||||||
return sourceFiles;
|
return sourceFiles;
|
||||||
}
|
}
|
||||||
@ -67,7 +71,7 @@ namespace RehauSku.PriceListTools
|
|||||||
{
|
{
|
||||||
PositionAmount = new Dictionary<Position, double>();
|
PositionAmount = new Dictionary<Position, double>();
|
||||||
|
|
||||||
for (int row = amountCell.Row + 1; row < Sheet.AutoFilter.Range.Rows.Count; row++)
|
for (int row = amountCell.Row + 1; row <= Sheet.Cells[Sheet.Rows.Count, amountCell.Column].End[XlDirection.xlUp].Row; row++)
|
||||||
{
|
{
|
||||||
object amount = Sheet.Cells[row, amountCell.Column].Value2;
|
object amount = Sheet.Cells[row, amountCell.Column].Value2;
|
||||||
|
|
||||||
@ -83,6 +87,7 @@ namespace RehauSku.PriceListTools
|
|||||||
{
|
{
|
||||||
PositionAmount[p] += (double)amount;
|
PositionAmount[p] += (double)amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PositionAmount.Add(p, (double)amount);
|
PositionAmount.Add(p, (double)amount);
|
||||||
|
@ -1,21 +1,29 @@
|
|||||||
using Microsoft.Office.Interop.Excel;
|
using Microsoft.Office.Interop.Excel;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace RehauSku.PriceListTools
|
namespace RehauSku.PriceListTools
|
||||||
{
|
{
|
||||||
internal class Target : PriceList
|
internal class Target : PriceList
|
||||||
{
|
{
|
||||||
|
private const string oldSkuHeader = "Прежний материал";
|
||||||
|
public Range oldSkuCell { get; private set; }
|
||||||
|
|
||||||
public Target(Workbook workbook)
|
public Target(Workbook workbook)
|
||||||
{
|
{
|
||||||
Sheet = workbook.ActiveSheet;
|
Sheet = workbook.ActiveSheet;
|
||||||
Name = workbook.FullName;
|
Name = workbook.FullName;
|
||||||
|
|
||||||
amountCell = Sheet.Cells.Find(amountHeader);
|
Range[] cells = new[]
|
||||||
skuCell = Sheet.Cells.Find(skuHeader);
|
{
|
||||||
groupCell = Sheet.Cells.Find(groupHeader);
|
amountCell = Sheet.Cells.Find(amountHeader),
|
||||||
nameCell = Sheet.Cells.Find(nameHeader);
|
skuCell = Sheet.Cells.Find(skuHeader),
|
||||||
|
groupCell = Sheet.Cells.Find(groupHeader),
|
||||||
|
nameCell = Sheet.Cells.Find(nameHeader),
|
||||||
|
oldSkuCell = Sheet.Cells.Find(oldSkuHeader)
|
||||||
|
};
|
||||||
|
|
||||||
if (amountCell == null || skuCell == null || groupCell == null || nameCell == null)
|
if (cells.Any(x => x == null))
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Шаблон { Name } не является прайс-листом");
|
throw new ArgumentException($"Шаблон { Name } не является прайс-листом");
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
using System.Runtime.InteropServices;
|
using ExcelDna.Integration.CustomUI;
|
||||||
using System.Windows.Forms;
|
|
||||||
using ExcelDna.Integration.CustomUI;
|
|
||||||
using RehauSku.PriceListTools;
|
|
||||||
using RehauSku.Forms;
|
using RehauSku.Forms;
|
||||||
|
using RehauSku.PriceListTools;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace RehauSku.Ribbon
|
namespace RehauSku.Ribbon
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user