aboutsummaryrefslogtreecommitdiff
path: root/src/PriceListTools
diff options
context:
space:
mode:
Diffstat (limited to 'src/PriceListTools')
-rw-r--r--src/PriceListTools/AbstractPriceList.cs (renamed from src/PriceListTools/PriceList.cs)2
-rw-r--r--src/PriceListTools/AbstractTool.cs (renamed from src/PriceListTools/PriceListTool.cs)102
-rw-r--r--src/PriceListTools/CombineTool.cs22
-rw-r--r--src/PriceListTools/ConvertTool.cs21
-rw-r--r--src/PriceListTools/ExportTool.cs22
-rw-r--r--src/PriceListTools/MergeTool.cs22
-rw-r--r--src/PriceListTools/SourcePriceList.cs (renamed from src/PriceListTools/Source.cs)25
-rw-r--r--src/PriceListTools/TargetPriceList.cs (renamed from src/PriceListTools/Target.cs)9
8 files changed, 147 insertions, 78 deletions
diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/AbstractPriceList.cs
index 65ff3df..06427a0 100644
--- a/src/PriceListTools/PriceList.cs
+++ b/src/PriceListTools/AbstractPriceList.cs
@@ -2,7 +2,7 @@
namespace RehauSku.PriceListTools
{
- internal class PriceList
+ internal abstract class AbstractPriceList
{
protected const string amountHeader = "Кол-во";
protected const string skuHeader = "Актуальный материал";
diff --git a/src/PriceListTools/PriceListTool.cs b/src/PriceListTools/AbstractTool.cs
index 0a82a41..b4e34cc 100644
--- a/src/PriceListTools/PriceListTool.cs
+++ b/src/PriceListTools/AbstractTool.cs
@@ -1,16 +1,20 @@
using ExcelDna.Integration;
using Microsoft.Office.Interop.Excel;
+using RehauSku.Interface;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Application = Microsoft.Office.Interop.Excel.Application;
+using ProgressBar = RehauSku.Interface.ProgressBar;
namespace RehauSku.PriceListTools
{
- internal abstract class PriceListTool
+ internal abstract class AbstractTool
{
protected private Application ExcelApp = (Application)ExcelDnaUtil.Application;
- protected private Target TargetFile;
+ protected private TargetPriceList TargetFile;
+ protected private ResultBar ResultBar { get; set; }
+ protected private ProgressBar ProgressBar { get; set; }
public void OpenNewPrice()
{
@@ -18,7 +22,7 @@ namespace RehauSku.PriceListTools
try
{
- TargetFile = new Target(wb);
+ TargetFile = new TargetPriceList(wb);
}
catch (Exception ex)
@@ -33,7 +37,7 @@ namespace RehauSku.PriceListTools
}
}
- protected private void FillColumnsWithDictionary(KeyValuePair<Position, double> positionAmount, params int[] columns)
+ protected private void FillPositionAmountToColumns(KeyValuePair<Position, double> positionAmount, params int[] columns)
{
int? row = GetPositionRow(positionAmount.Key.Sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
@@ -53,72 +57,96 @@ namespace RehauSku.PriceListTools
sumCell.Value2 += positionAmount.Value;
}
}
+
+ ResultBar.IncrementSuccess();
+ return;
}
- else
+ if (TargetFile.oldSkuCell != null)
{
- string sku = positionAmount.Key.Sku.Substring(1, 6);
+ Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku);
- row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
-
- if (row != null)
+ if (foundCell != null)
{
+ row = foundCell.Row;
+
foreach (int column in columns)
{
- Range amountCell = TargetFile.Sheet.Cells[row, column];
-
- if (amountCell.Value2 == null)
+ if (TargetFile.Sheet.Cells[row, column].Value2 == null)
{
- amountCell.Value2 = positionAmount.Value;
+ TargetFile.Sheet.Cells[row, column].Value2 = positionAmount.Value;
}
else
{
- amountCell.Value2 += positionAmount.Value;
+ TargetFile.Sheet.Cells[row, column].Value2 += positionAmount.Value;
}
-
- Range oldSkuCell = TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column];
- oldSkuCell.Value2 = positionAmount.Key.Sku;
}
+
+ ResultBar.IncrementReplaced();
+ return;
}
+ }
- else
+ string sku = positionAmount.Key.Sku.Substring(1, 6);
+ row = GetPositionRow(sku, positionAmount.Key.Group, TargetFile.skuCell.Column);
+
+ if (row != null)
+ {
+ foreach (int column in columns)
{
- FillMissing(positionAmount, columns);
+ Range amountCell = TargetFile.Sheet.Cells[row, column];
+
+ if (amountCell.Value2 == null)
+ {
+ amountCell.Value2 = positionAmount.Value;
+ }
+
+ else
+ {
+ amountCell.Value2 += positionAmount.Value;
+ }
}
+
+ ResultBar.IncrementReplaced();
+ return;
+ }
+
+ else
+ {
+ FillMissing(positionAmount, columns);
+ ResultBar.IncrementNotFound();
}
}
protected private void FillMissing(KeyValuePair<Position, double> positionAmount, params int[] columns)
{
- Range foundCell = TargetFile.oldSkuCell.EntireColumn.Find(positionAmount.Key.Sku);
- int row;
+ int row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column]
+ .End[XlDirection.xlUp]
+ .Row + 1;
- if (foundCell == null)
- {
- row = TargetFile.Sheet.Cells[TargetFile.Sheet.Rows.Count, TargetFile.skuCell.Column]
- .End[XlDirection.xlUp]
- .Row + 1;
+ TargetFile.Sheet.Rows[row]
+ .EntireRow
+ .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
- TargetFile.Sheet.Rows[row]
- .EntireRow
- .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
+ Range previous = TargetFile.Sheet.Rows[row - 1];
+ Range current = TargetFile.Sheet.Rows[row];
- Range previous = TargetFile.Sheet.Rows[row - 1];
- Range current = TargetFile.Sheet.Rows[row];
+ previous.Copy(current);
+ current.ClearContents();
- previous.Copy(current);
- current.ClearContents();
+ TargetFile.Sheet.Cells[row, TargetFile.groupCell.Column].Value2 = positionAmount.Key.Group;
+ TargetFile.Sheet.Cells[row, TargetFile.nameCell.Column].Value2 = positionAmount.Key.Name;
- 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;
+ if (TargetFile.oldSkuCell != null)
+ {
TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = "Не найден";
+ TargetFile.Sheet.Cells[row, TargetFile.oldSkuCell.Column].Value2 = positionAmount.Key.Sku;
}
else
{
- row = foundCell.Row;
+ TargetFile.Sheet.Cells[row, TargetFile.skuCell.Column].Value2 = positionAmount.Key.Sku;
}
foreach (int column in columns)
diff --git a/src/PriceListTools/CombineTool.cs b/src/PriceListTools/CombineTool.cs
index da29e4d..af9378c 100644
--- a/src/PriceListTools/CombineTool.cs
+++ b/src/PriceListTools/CombineTool.cs
@@ -1,15 +1,20 @@
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
+using RehauSku.Interface;
+using System.Linq;
namespace RehauSku.PriceListTools
{
- internal class CombineTool : PriceListTool
+ internal class CombineTool : AbstractTool
{
- public List<Source> SourceFiles;
+ public List<SourcePriceList> SourceFiles;
public void FillTarget()
{
- foreach (Source source in SourceFiles)
+ ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(file => file.PositionAmount.Count));
+ ResultBar = new ResultBar();
+
+ foreach (SourcePriceList source in SourceFiles)
{
TargetFile.Sheet.Columns[TargetFile.amountCell.Column]
.EntireColumn
@@ -19,13 +24,18 @@ namespace RehauSku.PriceListTools
newColumnHeader.Value2 = $"{source.Name}";
newColumnHeader.WrapText = true;
- foreach(var kvp in source.PositionAmount)
- FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
+ foreach (var kvp in source.PositionAmount)
+ {
+ FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column - 1, TargetFile.amountCell.Column);
+ ProgressBar.Update();
+ }
}
FilterByAmount();
+ ResultBar.Update();
- Forms.Dialog.SaveWorkbookAs();
+ Interface.Dialog.SaveWorkbookAs();
+ ExcelApp.StatusBar = false;
}
}
}
diff --git a/src/PriceListTools/ConvertTool.cs b/src/PriceListTools/ConvertTool.cs
index f37bfe2..d13c803 100644
--- a/src/PriceListTools/ConvertTool.cs
+++ b/src/PriceListTools/ConvertTool.cs
@@ -1,16 +1,17 @@
-using System;
+using RehauSku.Interface;
+using System;
namespace RehauSku.PriceListTools
{
- internal class ConvertTool : PriceListTool
+ internal class ConvertTool : AbstractTool
{
- private Source Current;
+ private SourcePriceList Current;
public void GetCurrent()
{
try
{
- Current = new Source(ExcelApp.ActiveWorkbook);
+ Current = new SourcePriceList(ExcelApp.ActiveWorkbook);
}
catch (Exception exception)
@@ -26,12 +27,20 @@ namespace RehauSku.PriceListTools
public void FillTarget()
{
+ ProgressBar = new ProgressBar("Заполняю строки...", Current.PositionAmount.Count);
+ ResultBar = new ResultBar();
+
foreach (var kvp in Current.PositionAmount)
- FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
+ {
+ FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
+ ProgressBar.Update();
+ }
FilterByAmount();
+ ResultBar.Update();
- Forms.Dialog.SaveWorkbookAs();
+ Dialog.SaveWorkbookAs();
+ ExcelApp.StatusBar = false;
}
}
} \ No newline at end of file
diff --git a/src/PriceListTools/ExportTool.cs b/src/PriceListTools/ExportTool.cs
index bfb3d8a..f341671 100644
--- a/src/PriceListTools/ExportTool.cs
+++ b/src/PriceListTools/ExportTool.cs
@@ -1,37 +1,37 @@
using Microsoft.Office.Interop.Excel;
-using RehauSku.Assistant;
using System;
using System.Collections.Generic;
+using RehauSku.Interface;
namespace RehauSku.PriceListTools
{
- internal class ExportTool : PriceListTool
+ internal class ExportTool : AbstractTool
{
private Dictionary<Position, double> PositionAmount;
private Range Selection;
- public void TryGetSelection()
+ public ExportTool()
{
Selection = ExcelApp.Selection;
-
- if (Selection == null || Selection.Columns.Count != 2)
- {
- throw new Exception("Неверный диапазон");
- }
}
public void FillTarget()
{
GetSelected();
-
+ ProgressBar = new ProgressBar("Заполняю строки...", PositionAmount.Count);
+ ResultBar = new ResultBar();
+
foreach (var kvp in PositionAmount)
{
- FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
+ FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
+ ProgressBar.Update();
}
FilterByAmount();
+ ResultBar.Update();
- Forms.Dialog.SaveWorkbookAs();
+ Interface.Dialog.SaveWorkbookAs();
+ ExcelApp.StatusBar = false;
}
private void GetSelected()
diff --git a/src/PriceListTools/MergeTool.cs b/src/PriceListTools/MergeTool.cs
index e196b3a..0e3f1dc 100644
--- a/src/PriceListTools/MergeTool.cs
+++ b/src/PriceListTools/MergeTool.cs
@@ -1,22 +1,32 @@
-using System.Collections.Generic;
+using RehauSku.Interface;
+using System.Collections.Generic;
+using System.Linq;
namespace RehauSku.PriceListTools
{
- internal class MergeTool : PriceListTool
+ internal class MergeTool : AbstractTool
{
- public List<Source> SourceFiles;
+ public List<SourcePriceList> SourceFiles;
public void FillTarget()
{
- foreach (Source source in SourceFiles)
+ ProgressBar = new ProgressBar("Заполняю строки...", SourceFiles.Sum(x => x.PositionAmount.Count));
+ ResultBar = new ResultBar();
+
+ foreach (SourcePriceList source in SourceFiles)
{
foreach (var kvp in source.PositionAmount)
- FillColumnsWithDictionary(kvp, TargetFile.amountCell.Column);
+ {
+ FillPositionAmountToColumns(kvp, TargetFile.amountCell.Column);
+ ProgressBar.Update();
+ }
}
FilterByAmount();
+ ResultBar.Update();
- Forms.Dialog.SaveWorkbookAs();
+ Dialog.SaveWorkbookAs();
+ ExcelApp.StatusBar = false;
}
}
}
diff --git a/src/PriceListTools/Source.cs b/src/PriceListTools/SourcePriceList.cs
index 7cf56be..01637f8 100644
--- a/src/PriceListTools/Source.cs
+++ b/src/PriceListTools/SourcePriceList.cs
@@ -3,14 +3,16 @@ using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
+using RehauSku.Interface;
namespace RehauSku.PriceListTools
{
- internal class Source : PriceList
+
+ internal class SourcePriceList : AbstractPriceList
{
public Dictionary<Position, double> PositionAmount { get; private set; }
- public Source(Workbook workbook)
+ public SourcePriceList(Workbook workbook)
{
if (workbook == null)
{
@@ -20,7 +22,7 @@ namespace RehauSku.PriceListTools
Sheet = workbook.ActiveSheet;
Name = workbook.Name;
- Range[] cells = new []
+ Range[] cells = new[]
{
amountCell = Sheet.Cells.Find(amountHeader),
skuCell = Sheet.Cells.Find(skuHeader),
@@ -28,7 +30,7 @@ namespace RehauSku.PriceListTools
nameCell = Sheet.Cells.Find(nameHeader)
};
- if (cells.Any(x => x == null))
+ if (cells.Any(x => x == null))
{
throw new ArgumentException($"Файл {Name} не распознан");
}
@@ -36,11 +38,12 @@ namespace RehauSku.PriceListTools
CreatePositionsDict();
}
- public static List<Source> GetSourceLists(string[] files)
+ public static List<SourcePriceList> GetSourceLists(string[] files)
{
var ExcelApp = (Application)ExcelDnaUtil.Application;
+ ProgressBar bar = new ProgressBar("Открываю исходные файлы...", files.Length);
- List<Source> sourceFiles = new List<Source>();
+ List<SourcePriceList> sourceFiles = new List<SourcePriceList>();
foreach (string file in files)
{
@@ -48,9 +51,10 @@ namespace RehauSku.PriceListTools
Workbook wb = ExcelApp.Workbooks.Open(file);
try
{
- Source priceList = new Source(wb);
+ SourcePriceList priceList = new SourcePriceList(wb);
sourceFiles.Add(priceList);
wb.Close();
+ bar.Update();
}
catch (Exception ex)
{
@@ -60,6 +64,7 @@ namespace RehauSku.PriceListTools
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
wb.Close();
+ bar.Update();
}
ExcelApp.ScreenUpdating = true;
}
@@ -81,6 +86,12 @@ namespace RehauSku.PriceListTools
object name = Sheet.Cells[row, nameCell.Column].Value2;
object sku = Sheet.Cells[row, skuCell.Column].Value2;
+ if (group == null || name == null || sku == null)
+ continue;
+
+ if (!sku.ToString().IsRehauSku())
+ continue;
+
Position p = new Position(group.ToString(), sku.ToString(), name.ToString());
if (PositionAmount.ContainsKey(p))
diff --git a/src/PriceListTools/Target.cs b/src/PriceListTools/TargetPriceList.cs
index 996a092..32b071c 100644
--- a/src/PriceListTools/Target.cs
+++ b/src/PriceListTools/TargetPriceList.cs
@@ -4,12 +4,12 @@ using System.Linq;
namespace RehauSku.PriceListTools
{
- internal class Target : PriceList
+ internal class TargetPriceList : AbstractPriceList
{
private const string oldSkuHeader = "Прежний материал";
public Range oldSkuCell { get; private set; }
- public Target(Workbook workbook)
+ public TargetPriceList(Workbook workbook)
{
Sheet = workbook.ActiveSheet;
Name = workbook.FullName;
@@ -19,10 +19,11 @@ namespace RehauSku.PriceListTools
amountCell = Sheet.Cells.Find(amountHeader),
skuCell = Sheet.Cells.Find(skuHeader),
groupCell = Sheet.Cells.Find(groupHeader),
- nameCell = Sheet.Cells.Find(nameHeader),
- oldSkuCell = Sheet.Cells.Find(oldSkuHeader)
+ nameCell = Sheet.Cells.Find(nameHeader)
};
+ oldSkuCell = Sheet.Cells.Find(oldSkuHeader);
+
if (cells.Any(x => x == null))
{
throw new ArgumentException($"Шаблон { Name } не является прайс-листом");