RhSolutions-AddIn/src/PriceListTools/PriceList.cs

43 lines
1.2 KiB
C#
Raw Normal View History

2021-12-24 16:22:03 +03:00
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
2022-01-09 10:37:25 +03:00
using System.IO;
using System.Linq;
2021-12-24 16:22:03 +03:00
namespace RehauSku.PriceListTools
{
2022-01-09 10:37:25 +03:00
internal class PriceList
2021-12-24 16:22:03 +03:00
{
2022-01-09 10:37:25 +03:00
public readonly string Name;
2021-12-24 16:22:03 +03:00
public readonly PriceListSheet OfferSheet;
2022-01-09 10:37:25 +03:00
public List<PriceListSheet> Sheets { get; private set; }
2021-12-24 16:22:03 +03:00
private const string offerSheetHeader = "КП";
2021-12-24 16:22:03 +03:00
public PriceList(Workbook workbook)
{
2022-01-09 10:37:25 +03:00
Name = workbook.Name;
Sheets = new List<PriceListSheet>();
2021-12-24 16:22:03 +03:00
2022-01-09 10:37:25 +03:00
foreach (Worksheet worksheet in workbook.Sheets)
2021-12-24 16:22:03 +03:00
{
2022-01-09 10:37:25 +03:00
PriceListSheet priceListSheet = new PriceListSheet(worksheet);
2022-01-09 10:37:25 +03:00
if (priceListSheet.FillSkuAmount())
Sheets.Add(priceListSheet);
2021-12-24 16:22:03 +03:00
}
2022-01-09 10:37:25 +03:00
OfferSheet = Sheets.Where(s => s.Name == offerSheetHeader).FirstOrDefault();
2021-12-24 16:22:03 +03:00
}
2022-01-09 10:37:25 +03:00
public static string CreateNewFile()
{
2022-01-09 10:37:25 +03:00
string fileExtension = Path.GetExtension(RegistryUtil.PriceListPath);
string path = Path.GetTempFileName() + fileExtension;
2021-12-24 16:22:03 +03:00
2022-01-09 10:37:25 +03:00
File.Copy(RegistryUtil.PriceListPath, path);
return path;
2021-12-24 16:22:03 +03:00
}
}
}