Add complete position class
This commit is contained in:
parent
a825d8d8a5
commit
711cc313e0
@ -20,8 +20,8 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
TargetFile.Sheet.Cells[TargetFile.amountCell.Row, TargetFile.amountCell.Column - 1].Value2 = $"{source.Name}";
|
||||
|
||||
FillColumn(source.SkuAmount, TargetFile.amountCell.Column - 1);
|
||||
FillColumn(source.SkuAmount, TargetFile.amountCell.Column);
|
||||
FillColumn(source.PositionAmount, TargetFile.amountCell.Column - 1);
|
||||
FillColumn(source.PositionAmount, TargetFile.amountCell.Column);
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
|
@ -27,7 +27,7 @@ namespace RehauSku.PriceListTools
|
||||
public void FillTarget()
|
||||
{
|
||||
ExcelApp.ScreenUpdating = false;
|
||||
FillColumn(Current.SkuAmount, TargetFile.amountCell.Column);
|
||||
FillColumn(Current.PositionAmount, TargetFile.amountCell.Column);
|
||||
FilterByAmount();
|
||||
ExcelApp.ScreenUpdating = true;
|
||||
|
||||
|
@ -31,6 +31,46 @@ namespace RehauSku.PriceListTools
|
||||
Forms.Dialog.SaveWorkbookAs();
|
||||
}
|
||||
|
||||
private void FillColumn(IEnumerable<KeyValuePair<string, double>> dictionary, int column)
|
||||
{
|
||||
List<KeyValuePair<string, double>> missing = new List<KeyValuePair<string, double>>();
|
||||
|
||||
foreach (var kvp in dictionary)
|
||||
{
|
||||
Range cell = TargetFile.skuCell.EntireColumn.Find(kvp.Key);
|
||||
|
||||
if (cell == null)
|
||||
{
|
||||
missing.Add(kvp);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Range sumCell = TargetFile.Sheet.Cells[cell.Row, column];
|
||||
|
||||
if (sumCell.Value2 == null)
|
||||
{
|
||||
sumCell.Value2 = kvp.Value;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
sumCell.Value2 += kvp.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (missing.Count > 0)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show
|
||||
($"{missing.Count} артикулов отсутствует в таблице заказов {RegistryUtil.PriceListPath} Попробовать найти новый вариант?",
|
||||
"Отсутствует позиция в конечной таблице заказов",
|
||||
System.Windows.Forms.MessageBoxButtons.YesNo,
|
||||
System.Windows.Forms.MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void GetSelected()
|
||||
{
|
||||
object[,] cells = Selection.Value2;
|
||||
|
@ -13,7 +13,7 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
foreach (Source source in SourceFiles)
|
||||
{
|
||||
FillColumn(source.SkuAmount, TargetFile.amountCell.Column);
|
||||
FillColumn(source.PositionAmount, TargetFile.amountCell.Column);
|
||||
}
|
||||
|
||||
FilterByAmount();
|
||||
|
@ -7,10 +7,12 @@ namespace RehauSku.PriceListTools
|
||||
protected const string amountHeader = "Кол-во";
|
||||
protected const string skuHeader = "Актуальный материал";
|
||||
protected const string groupHeader = "Программа";
|
||||
protected const string nameHeader = "Наименование";
|
||||
|
||||
public Range amountCell { get; protected set; }
|
||||
public Range skuCell { get; protected set; }
|
||||
public Range groupCell { get; protected set; }
|
||||
public Range nameCell { get; protected set; }
|
||||
|
||||
public Worksheet Sheet { get; protected set; }
|
||||
public string Name { get; protected set; }
|
||||
|
@ -31,13 +31,13 @@ namespace RehauSku.PriceListTools
|
||||
}
|
||||
}
|
||||
|
||||
protected private void FillColumn(IEnumerable<KeyValuePair<string, double>> dictionary, int column)
|
||||
protected private void FillColumn(IEnumerable<KeyValuePair<Position, double>> dictionary, int column)
|
||||
{
|
||||
List<KeyValuePair<string, double>> missing = new List<KeyValuePair<string, double>>();
|
||||
List<KeyValuePair<Position, double>> missing = new List<KeyValuePair<Position, double>>();
|
||||
|
||||
foreach (var kvp in dictionary)
|
||||
{
|
||||
Range cell = TargetFile.Sheet.Columns[TargetFile.skuCell.Column].Find(kvp.Key);
|
||||
Range cell = TargetFile.skuCell.EntireColumn.Find(kvp.Key.Sku);
|
||||
|
||||
if (cell == null)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ namespace RehauSku.PriceListTools
|
||||
{
|
||||
internal class Source : PriceList
|
||||
{
|
||||
public Dictionary<string, double> SkuAmount { get; private set; }
|
||||
public Dictionary<Position, double> PositionAmount { get; private set; }
|
||||
|
||||
public Source(Workbook workbook)
|
||||
{
|
||||
@ -16,37 +16,63 @@ namespace RehauSku.PriceListTools
|
||||
amountCell = Sheet.Cells.Find(amountHeader);
|
||||
skuCell = Sheet.Cells.Find(skuHeader);
|
||||
groupCell = Sheet.Cells.Find(groupHeader);
|
||||
nameCell = Sheet.Cells.Find(nameHeader);
|
||||
|
||||
if (amountCell == null || skuCell == null || groupCell == null)
|
||||
if (amountCell == null || skuCell == null || groupCell == null || nameCell == null)
|
||||
{
|
||||
throw new ArgumentException($"Файл {Name} не распознан");
|
||||
}
|
||||
|
||||
CreateAmountDict();
|
||||
CreatePositionsDict();
|
||||
}
|
||||
|
||||
private void CreateAmountDict()
|
||||
private void CreatePositionsDict()
|
||||
{
|
||||
SkuAmount = new Dictionary<string, double>();
|
||||
PositionAmount = new Dictionary<Position, double>();
|
||||
|
||||
object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2;
|
||||
object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2;
|
||||
var aColumn = amountCell.EntireColumn;
|
||||
|
||||
object[,] amountColumn = amountCell.EntireColumn.Value2;
|
||||
object[,] skuColumn = skuCell.EntireColumn.Value2;
|
||||
object[,] nameColumn = nameCell.EntireColumn.Value2;
|
||||
object[,] groupColumn = nameCell.EntireColumn.Value2;
|
||||
|
||||
for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++)
|
||||
{
|
||||
object amount = amountColumn[row, 1];
|
||||
object group = groupColumn[row, 1];
|
||||
object name = nameColumn[row, 1];
|
||||
object sku = skuColumn[row, 1];
|
||||
|
||||
if (amount != null && (double)amount != 0)
|
||||
{
|
||||
if (SkuAmount.ContainsKey(sku.ToString()))
|
||||
SkuAmount[sku.ToString()] += (double)amount;
|
||||
Position p = new Position(group.ToString(), sku.ToString(), name.ToString());
|
||||
|
||||
if (PositionAmount.ContainsKey(p))
|
||||
{
|
||||
PositionAmount[p] += (double)amount;
|
||||
}
|
||||
else
|
||||
SkuAmount.Add(sku.ToString(), (double)amount);
|
||||
{
|
||||
PositionAmount.Add(p, (double)amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Position
|
||||
{
|
||||
public string SkuGroup { get; private set; }
|
||||
public string Sku { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
|
||||
public Position(string group, string sku, string name)
|
||||
{
|
||||
SkuGroup = group;
|
||||
Sku = sku;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user