From 4a2ca16d8b4aa34041adb558b2db91709908aff5 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 26 Jan 2022 17:41:46 +0300 Subject: Watch only current sheets in files --- src/PriceListTools/PriceList.cs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/PriceListTools/PriceList.cs') diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index bc11a17..b8bd7b7 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -1,4 +1,5 @@ using Microsoft.Office.Interop.Excel; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -8,25 +9,34 @@ namespace RehauSku.PriceListTools internal class PriceList { public readonly string Name; - public readonly PriceListSheet OfferSheet; - public List Sheets { get; private set; } + //public readonly PriceListSheet OfferSheet; + public PriceListSheet Sheet { get; private set; } - private const string offerSheetHeader = "КП"; + + //private const string offerSheetHeader = "КП"; public PriceList(Workbook workbook) { Name = workbook.Name; - Sheets = new List(); + Sheet = new PriceListSheet(workbook.ActiveSheet); - foreach (Worksheet worksheet in workbook.Sheets) - { - PriceListSheet priceListSheet = new PriceListSheet(worksheet); + //foreach (Worksheet worksheet in workbook.Sheets) + //{ + // try + // { + // PriceListSheet priceListSheet = new PriceListSheet(worksheet); + // //priceListSheet.FillSkuAmount(); + // Sheets.Add(priceListSheet); + // } + // catch (Exception ex) + // { + // throw ex; + // } + //} - if (priceListSheet.FillSkuAmount()) - Sheets.Add(priceListSheet); - } - OfferSheet = Sheets.Where(s => s.Name == offerSheetHeader).FirstOrDefault(); + + //OfferSheet = Sheet.Where(s => s.Name == offerSheetHeader).FirstOrDefault(); } public static string CreateNewFile() -- cgit v1.2.3 From ec1059ed5d4c158e29587af8a35bd9b5c783b325 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 26 Jan 2022 17:43:09 +0300 Subject: Remove Create new file method in PriceList class --- src/PriceListTools/PriceList.cs | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/PriceListTools/PriceList.cs') diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index b8bd7b7..e6aa826 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -38,15 +38,6 @@ namespace RehauSku.PriceListTools //OfferSheet = Sheet.Where(s => s.Name == offerSheetHeader).FirstOrDefault(); } - - public static string CreateNewFile() - { - string fileExtension = Path.GetExtension(RegistryUtil.PriceListPath); - string path = Path.GetTempFileName() + fileExtension; - - File.Copy(RegistryUtil.PriceListPath, path); - return path; - } } } -- cgit v1.2.3 From c0139ca228bdca91df0a66201f59f8074c6a0db6 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 26 Jan 2022 17:50:07 +0300 Subject: Remove unnecessary fields --- src/PriceListTools/PriceList.cs | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'src/PriceListTools/PriceList.cs') diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index e6aa826..e2fd142 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -9,34 +9,12 @@ namespace RehauSku.PriceListTools internal class PriceList { public readonly string Name; - //public readonly PriceListSheet OfferSheet; public PriceListSheet Sheet { get; private set; } - - //private const string offerSheetHeader = "КП"; - public PriceList(Workbook workbook) { Name = workbook.Name; Sheet = new PriceListSheet(workbook.ActiveSheet); - - //foreach (Worksheet worksheet in workbook.Sheets) - //{ - // try - // { - // PriceListSheet priceListSheet = new PriceListSheet(worksheet); - // //priceListSheet.FillSkuAmount(); - // Sheets.Add(priceListSheet); - // } - // catch (Exception ex) - // { - // throw ex; - // } - //} - - - - //OfferSheet = Sheet.Where(s => s.Name == offerSheetHeader).FirstOrDefault(); } } } -- cgit v1.2.3 From 55bbd801a5593512921ccd4671a50069896affa0 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 26 Jan 2022 18:17:44 +0300 Subject: Remove PriceList class --- src/PriceListTools/PriceList.cs | 91 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 6 deletions(-) (limited to 'src/PriceListTools/PriceList.cs') diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index e2fd142..588a0bc 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -1,21 +1,100 @@ using Microsoft.Office.Interop.Excel; -using System; using System.Collections.Generic; -using System.IO; -using System.Linq; +using System; namespace RehauSku.PriceListTools { internal class PriceList { + private const string amountHeader = "Кол-во"; + private const string skuHeader = "Актуальный материал"; + private const string groupHeader = "Программа"; + + public readonly Worksheet Sheet; public readonly string Name; - public PriceListSheet Sheet { get; private set; } + public Dictionary SkuAmount { get; private set; } + + public readonly Range amountCell; + public readonly Range skuCell; + public readonly Range groupCell; + + public Dictionary Map { get; private set; } + + public PriceList(Worksheet sheet) + { + Sheet = sheet; + Name = sheet.Name; + + amountCell = Sheet.Cells.Find(amountHeader); + skuCell = Sheet.Cells.Find(skuHeader); + groupCell = Sheet.Cells.Find(groupHeader); + + if (amountCell == null || skuCell == null || groupCell == null) + { + throw new ArgumentException($"Лист { Name } не распознан"); + } + + FillSkuAmount(); + } public PriceList(Workbook workbook) { - Name = workbook.Name; - Sheet = new PriceListSheet(workbook.ActiveSheet); + Sheet = workbook.ActiveSheet; + Name = workbook.Name + '\n' + Sheet.Name; + + amountCell = Sheet.Cells.Find(amountHeader); + skuCell = Sheet.Cells.Find(skuHeader); + groupCell = Sheet.Cells.Find(groupHeader); + + if (amountCell == null || skuCell == null || groupCell == null) + { + throw new ArgumentException($"Лист { Name } не распознан"); + } + + FillSkuAmount(); + } + + private void FillSkuAmount() + { + SkuAmount = new Dictionary(); + + object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2; + object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2; + + for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++) + { + object amount = amountColumn[row, 1]; + object sku = skuColumn[row, 1]; + + if (amount != null && (double)amount != 0) + { + if (SkuAmount.ContainsKey(sku.ToString())) + SkuAmount[sku.ToString()] += (double)amount; + + else + SkuAmount.Add(sku.ToString(), (double)amount); + } + } } + + //public void CreateMap() + //{ + // Range amountCell = Sheet.Cells.Find(amountHeader); + // Range skuCell = Sheet.Cells.Find(skuHeader); + // Range groupCell = Sheet.Cells.Find(groupHeader); + + // headerRowNumber = amountCell.Row; + // skuColumnNumber = skuCell.Column; + // amountColumnNumber = amountCell.Column; + // groupColumnNumber = groupCell.Column; + + // for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++) + // { + // string sku = + // } + + //} } + } -- cgit v1.2.3 From 94e0c84ce1e62826d963c0809be1c4d242694444 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 26 Jan 2022 18:37:24 +0300 Subject: Move Autofilter method to abstract class --- src/PriceListTools/PriceList.cs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'src/PriceListTools/PriceList.cs') diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index 588a0bc..1bf9663 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -18,24 +18,7 @@ namespace RehauSku.PriceListTools public readonly Range skuCell; public readonly Range groupCell; - public Dictionary Map { get; private set; } - - public PriceList(Worksheet sheet) - { - Sheet = sheet; - Name = sheet.Name; - - amountCell = Sheet.Cells.Find(amountHeader); - skuCell = Sheet.Cells.Find(skuHeader); - groupCell = Sheet.Cells.Find(groupHeader); - - if (amountCell == null || skuCell == null || groupCell == null) - { - throw new ArgumentException($"Лист { Name } не распознан"); - } - - FillSkuAmount(); - } + //public Dictionary Map { get; private set; } public PriceList(Workbook workbook) { -- cgit v1.2.3 From 8e3dff1788905c203509f866921957b027cb2643 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 27 Jan 2022 09:59:33 +0300 Subject: Extract PriceList Base Class --- src/PriceListTools/PriceList.cs | 83 +++++------------------------------------ 1 file changed, 9 insertions(+), 74 deletions(-) (limited to 'src/PriceListTools/PriceList.cs') diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index 1bf9663..5ec870e 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -1,83 +1,18 @@ using Microsoft.Office.Interop.Excel; -using System.Collections.Generic; -using System; namespace RehauSku.PriceListTools { internal class PriceList { - private const string amountHeader = "Кол-во"; - private const string skuHeader = "Актуальный материал"; - private const string groupHeader = "Программа"; + protected const string amountHeader = "Кол-во"; + protected const string skuHeader = "Актуальный материал"; + protected const string groupHeader = "Программа"; - public readonly Worksheet Sheet; - public readonly string Name; - public Dictionary SkuAmount { get; private set; } + public Range amountCell { get; protected set; } + public Range skuCell { get; protected set; } + public Range groupCell { get; protected set; } - public readonly Range amountCell; - public readonly Range skuCell; - public readonly Range groupCell; - - //public Dictionary Map { get; private set; } - - public PriceList(Workbook workbook) - { - Sheet = workbook.ActiveSheet; - Name = workbook.Name + '\n' + Sheet.Name; - - amountCell = Sheet.Cells.Find(amountHeader); - skuCell = Sheet.Cells.Find(skuHeader); - groupCell = Sheet.Cells.Find(groupHeader); - - if (amountCell == null || skuCell == null || groupCell == null) - { - throw new ArgumentException($"Лист { Name } не распознан"); - } - - FillSkuAmount(); - } - - private void FillSkuAmount() - { - SkuAmount = new Dictionary(); - - object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2; - object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2; - - for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++) - { - object amount = amountColumn[row, 1]; - object sku = skuColumn[row, 1]; - - if (amount != null && (double)amount != 0) - { - if (SkuAmount.ContainsKey(sku.ToString())) - SkuAmount[sku.ToString()] += (double)amount; - - else - SkuAmount.Add(sku.ToString(), (double)amount); - } - } - } - - //public void CreateMap() - //{ - // Range amountCell = Sheet.Cells.Find(amountHeader); - // Range skuCell = Sheet.Cells.Find(skuHeader); - // Range groupCell = Sheet.Cells.Find(groupHeader); - - // headerRowNumber = amountCell.Row; - // skuColumnNumber = skuCell.Column; - // amountColumnNumber = amountCell.Column; - // groupColumnNumber = groupCell.Column; - - // for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++) - // { - // string sku = - // } - - //} + public Worksheet Sheet { get; protected set; } + public string Name { get; protected set; } } - -} - +} \ No newline at end of file -- cgit v1.2.3 From 711cc313e0eaed646c5058ef294de6d89770e352 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 28 Jan 2022 11:41:35 +0300 Subject: Add complete position class --- src/PriceListTools/PriceList.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/PriceListTools/PriceList.cs') diff --git a/src/PriceListTools/PriceList.cs b/src/PriceListTools/PriceList.cs index 5ec870e..65ff3df 100644 --- a/src/PriceListTools/PriceList.cs +++ b/src/PriceListTools/PriceList.cs @@ -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; } -- cgit v1.2.3