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;
@ -16,12 +17,14 @@ internal class SourcePriceList : PriceListBase
Sheet = workbook.ActiveSheet;
Name = Path.GetFileNameWithoutExtension(workbook.FullName);
var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters();
Range[] cells = new[]
{
AmountCell = Sheet.Cells.Find(PriceListHeaders.Amount),
SkuCell = Sheet.Cells.Find(PriceListHeaders.Sku),
GroupCell = Sheet.Cells.Find(PriceListHeaders.Group),
NameCell = Sheet.Cells.Find(PriceListHeaders.Name)
AmountCell = Sheet.Cells.Find(pricelistParameters["Amount"]),
SkuCell = Sheet.Cells.Find(pricelistParameters["Sku"]),
GroupCell = Sheet.Cells.Find(pricelistParameters["Group"]),
NameCell = Sheet.Cells.Find(pricelistParameters["Name"])
};
if (cells.Any(x => x == null))

View File

@ -1,4 +1,5 @@
using System.IO;
using RhSolutions.AddIn;
using System.IO;
namespace RhSolutions.Models;
@ -17,15 +18,17 @@ internal class TargetPriceList : PriceListBase
Sheet = workbook.ActiveSheet;
Name = Path.GetFileNameWithoutExtension(workbook.FullName);
var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters();
Range[] cells = new[]
{
AmountCell = Sheet.Cells.Find(PriceListHeaders.Amount),
SkuCell = Sheet.Cells.Find(PriceListHeaders.Sku),
GroupCell = Sheet.Cells.Find(PriceListHeaders.Group),
NameCell = Sheet.Cells.Find(PriceListHeaders.Name)
AmountCell = Sheet.Cells.Find(pricelistParameters["Amount"]),
SkuCell = Sheet.Cells.Find(pricelistParameters["Sku"]),
GroupCell = Sheet.Cells.Find(pricelistParameters["Group"]),
NameCell = Sheet.Cells.Find(pricelistParameters["Name"])
};
OldSkuCell = Sheet.Cells.Find(PriceListHeaders.OldSku);
OldSkuCell = Sheet.Cells.Find(pricelistParameters["OldSku"]);
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
{
@ -9,12 +11,14 @@ public static class WorksheetExtensions
Range groupCell;
Range nameCell;
var pricelistParameters = RhSolutionsAddIn.Configuration.GetPriceListParameters();
Range[] cells = new[]
{
amountCell = worksheet.Cells.Find(PriceListHeaders.Amount),
skuCell = worksheet.Cells.Find(PriceListHeaders.Sku),
groupCell = worksheet.Cells.Find(PriceListHeaders.Group),
nameCell = worksheet.Cells.Find(PriceListHeaders.Name)
amountCell = worksheet.Cells.Find(pricelistParameters["Amount"]),
skuCell = worksheet.Cells.Find(pricelistParameters["Sku"]),
groupCell = worksheet.Cells.Find(pricelistParameters["Group"]),
nameCell = worksheet.Cells.Find(pricelistParameters["Name"])
};
return cells.All(x => x != null);

View File

@ -1,39 +1,103 @@
using System;
using System.Configuration;
using System.Configuration;
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()
{
[UserScopedSetting]
public string PriceListPath
_priceListParameters = new Dictionary<string, string>()
{
get
{
return (string)this[nameof(PriceListPath)];
}
set
{
this[nameof(PriceListPath)] = value;
}
}
public event SettingChangingEventHandler OnSettingsChange
{
add
{
base.SettingChanging += value;
}
remove
{
base.SettingChanging -= value;
}
}
public string GetPriceListFileName() => Path.GetFileName(PriceListPath);
public string GetPriceListPath() => PriceListPath;
public void SetPriceListPath(string value) => PriceListPath = value;
public void SaveSettings() => base.Save();
["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]
public string PriceListPath
{
get
{
return (string)this[nameof(PriceListPath)];
}
set
{
this[nameof(PriceListPath)] = value;
}
}
public event SettingChangingEventHandler OnSettingsChange
{
add
{
base.SettingChanging += value;
}
remove
{
base.SettingChanging -= value;
}
}
public string GetPriceListFileName() => Path.GetFileName(PriceListPath);
public string GetPriceListPath() => PriceListPath;
public void SetPriceListPath(string value) => PriceListPath = value;
public void SaveSettings() => base.Save();
public Dictionary<string, string> GetPriceListParameters() => _priceListParameters;
}

View File

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