Add Pricelist Headers to configuration

This commit is contained in:
Sergey Chebotar 2023-04-01 15:24:04 +03:00
parent f01228d945
commit da29243d1d
6 changed files with 131 additions and 68 deletions

View File

@ -1,11 +0,0 @@
namespace RhSolutions.Models
{
internal static class PriceListHeaders
{
public static readonly string Amount = "Кол-во";
public static readonly string OldSku = "Прежний материал";
public static readonly string Sku = "Актуальный материал";
public static readonly string Group = "Программа";
public static readonly string Name = "Наименование";
}
}

View File

@ -1,4 +1,5 @@
using System.IO; using RhSolutions.AddIn;
using System.IO;
namespace RhSolutions.Models; namespace RhSolutions.Models;
@ -16,12 +17,14 @@ internal class SourcePriceList : PriceListBase
Sheet = workbook.ActiveSheet; Sheet = workbook.ActiveSheet;
Name = Path.GetFileNameWithoutExtension(workbook.FullName); Name = Path.GetFileNameWithoutExtension(workbook.FullName);
var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters();
Range[] cells = new[] Range[] cells = new[]
{ {
AmountCell = Sheet.Cells.Find(PriceListHeaders.Amount), AmountCell = Sheet.Cells.Find(pricelistParameters["Amount"]),
SkuCell = Sheet.Cells.Find(PriceListHeaders.Sku), SkuCell = Sheet.Cells.Find(pricelistParameters["Sku"]),
GroupCell = Sheet.Cells.Find(PriceListHeaders.Group), GroupCell = Sheet.Cells.Find(pricelistParameters["Group"]),
NameCell = Sheet.Cells.Find(PriceListHeaders.Name) NameCell = Sheet.Cells.Find(pricelistParameters["Name"])
}; };
if (cells.Any(x => x == null)) if (cells.Any(x => x == null))

View File

@ -1,4 +1,5 @@
using System.IO; using RhSolutions.AddIn;
using System.IO;
namespace RhSolutions.Models; namespace RhSolutions.Models;
@ -17,15 +18,17 @@ internal class TargetPriceList : PriceListBase
Sheet = workbook.ActiveSheet; Sheet = workbook.ActiveSheet;
Name = Path.GetFileNameWithoutExtension(workbook.FullName); Name = Path.GetFileNameWithoutExtension(workbook.FullName);
var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters();
Range[] cells = new[] Range[] cells = new[]
{ {
AmountCell = Sheet.Cells.Find(PriceListHeaders.Amount), AmountCell = Sheet.Cells.Find(pricelistParameters["Amount"]),
SkuCell = Sheet.Cells.Find(PriceListHeaders.Sku), SkuCell = Sheet.Cells.Find(pricelistParameters["Sku"]),
GroupCell = Sheet.Cells.Find(PriceListHeaders.Group), GroupCell = Sheet.Cells.Find(pricelistParameters["Group"]),
NameCell = Sheet.Cells.Find(PriceListHeaders.Name) NameCell = Sheet.Cells.Find(pricelistParameters["Name"])
}; };
OldSkuCell = Sheet.Cells.Find(PriceListHeaders.OldSku); OldSkuCell = Sheet.Cells.Find(pricelistParameters["OldSku"]);
if (cells.Any(x => x == null)) if (cells.Any(x => x == null))
{ {

View File

@ -1,4 +1,6 @@
namespace RhSolutions.Services; using RhSolutions.AddIn;
namespace RhSolutions.Services;
public static class WorksheetExtensions public static class WorksheetExtensions
{ {
@ -9,12 +11,14 @@ public static class WorksheetExtensions
Range groupCell; Range groupCell;
Range nameCell; Range nameCell;
var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters();
Range[] cells = new[] Range[] cells = new[]
{ {
amountCell = worksheet.Cells.Find(PriceListHeaders.Amount), amountCell = worksheet.Cells.Find(pricelistParameters["Amount"]),
skuCell = worksheet.Cells.Find(PriceListHeaders.Sku), skuCell = worksheet.Cells.Find(pricelistParameters["Sku"]),
groupCell = worksheet.Cells.Find(PriceListHeaders.Group), groupCell = worksheet.Cells.Find(pricelistParameters["Group"]),
nameCell = worksheet.Cells.Find(PriceListHeaders.Name) nameCell = worksheet.Cells.Find(pricelistParameters["Name"])
}; };
return cells.All(x => x != null); return cells.All(x => x != null);

View File

@ -1,11 +1,75 @@
using System; using System.Configuration;
using System.Configuration;
using System.IO; using System.IO;
namespace RhSolutions.Services namespace RhSolutions.Services;
public class AddInConfiguration : ApplicationSettingsBase, IAddInConfiguration
{ {
public class AddInConfiguration : ApplicationSettingsBase, IAddInConfiguration private Dictionary<string, string> _priceListParameters;
public AddInConfiguration()
{ {
_priceListParameters = new Dictionary<string, string>()
{
["Amount"] = AmountHeader,
["OldSku"] = OldSkuHeader,
["Sku"] = SkuHeader,
["Group"] = GroupHeader,
["Name"] = NameHeader
};
}
[UserScopedSetting]
[DefaultSettingValue("Кол-во")]
public string AmountHeader
{
get
{
return (string)this[nameof(AmountHeader)];
}
}
[UserScopedSetting]
[DefaultSettingValue("Прежний материал")]
public string OldSkuHeader
{
get
{
return (string)this[nameof(OldSkuHeader)];
}
}
[UserScopedSetting]
[DefaultSettingValue("Актуальный материал")]
public string SkuHeader
{
get
{
return (string)this[nameof(SkuHeader)];
}
}
[UserScopedSetting]
[DefaultSettingValue("Программа")]
public string GroupHeader
{
get
{
return (string)this[nameof(GroupHeader)];
}
}
[UserScopedSetting]
[DefaultSettingValue("Наименование")]
public string NameHeader
{
get
{
return (string)this[nameof(NameHeader)];
}
}
[UserScopedSetting] [UserScopedSetting]
public string PriceListPath public string PriceListPath
{ {
@ -35,5 +99,5 @@ namespace RhSolutions.Services
public string GetPriceListPath() => PriceListPath; public string GetPriceListPath() => PriceListPath;
public void SetPriceListPath(string value) => PriceListPath = value; public void SetPriceListPath(string value) => PriceListPath = value;
public void SaveSettings() => base.Save(); public void SaveSettings() => base.Save();
} public Dictionary<string, string> GetPriceListParameters() => _priceListParameters;
} }

View File

@ -1,13 +1,13 @@
using System.Configuration; using System.Configuration;
namespace RhSolutions.Services namespace RhSolutions.Services;
public interface IAddInConfiguration
{ {
public interface IAddInConfiguration
{
public string GetPriceListPath(); public string GetPriceListPath();
public string GetPriceListFileName(); public string GetPriceListFileName();
public Dictionary<string, string> GetPriceListParameters();
public event SettingChangingEventHandler OnSettingsChange; public event SettingChangingEventHandler OnSettingsChange;
public void SetPriceListPath(string value); public void SetPriceListPath(string value);
public void SaveSettings(); public void SaveSettings();
}
} }