Rework so employee dont use repos but servies
This commit is contained in:
11
PointOfSale/Pos.Models/ReceiptDetailModel.cs
Normal file
11
PointOfSale/Pos.Models/ReceiptDetailModel.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Pos.Models
|
||||||
|
{
|
||||||
|
public class ReceiptDetailModel
|
||||||
|
{
|
||||||
|
public int SaleId { get; set; }
|
||||||
|
public List<ReceiptLineModel> Lines { get; set; } = new();
|
||||||
|
public decimal Total { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
10
PointOfSale/Pos.Models/ReceiptLineModel.cs
Normal file
10
PointOfSale/Pos.Models/ReceiptLineModel.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Pos.Models
|
||||||
|
{
|
||||||
|
public class ReceiptLineModel
|
||||||
|
{
|
||||||
|
public string Product { get; set; } = string.Empty;
|
||||||
|
public int Pieces { get; set; }
|
||||||
|
public decimal Price { get; set; }
|
||||||
|
public decimal Total { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
PointOfSale/Pos.Models/ReceiptSummaryModel.cs
Normal file
11
PointOfSale/Pos.Models/ReceiptSummaryModel.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Pos.Models
|
||||||
|
{
|
||||||
|
public class ReceiptSummaryModel
|
||||||
|
{
|
||||||
|
public int SaleId { get; set; }
|
||||||
|
public DateTime SaleTime { get; set; }
|
||||||
|
public decimal Total { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
54
PointOfSale/Pos.Service/EmployeeService.cs
Normal file
54
PointOfSale/Pos.Service/EmployeeService.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Database.Models;
|
||||||
|
using Database.Repository;
|
||||||
|
|
||||||
|
namespace Pos.Service
|
||||||
|
{
|
||||||
|
public class EmployeeService
|
||||||
|
{
|
||||||
|
private readonly EmployeeRepository _employeeRepository =
|
||||||
|
new EmployeeRepository();
|
||||||
|
|
||||||
|
public List<EmployeeEntity> GetEmployees()
|
||||||
|
{
|
||||||
|
return _employeeRepository.GetAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddEmployee(string name)
|
||||||
|
{
|
||||||
|
_employeeRepository.Add(ValidateName(name));
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RenameEmployee(int employeeId, string name)
|
||||||
|
{
|
||||||
|
ValidateId(employeeId);
|
||||||
|
_employeeRepository.Edit(employeeId, ValidateName(name));
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ArchiveEmployee(int employeeId)
|
||||||
|
{
|
||||||
|
ValidateId(employeeId);
|
||||||
|
_employeeRepository.Delete(employeeId);
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ValidateName(string name)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
|
throw new ArgumentException(
|
||||||
|
"Medarbejderens navn skal være udfyldt.",
|
||||||
|
nameof(name));
|
||||||
|
|
||||||
|
return name.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateId(int employeeId)
|
||||||
|
{
|
||||||
|
if (employeeId <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(employeeId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
85
PointOfSale/Pos.Service/ProductGroupService.cs
Normal file
85
PointOfSale/Pos.Service/ProductGroupService.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Database.Models;
|
||||||
|
using Database.Repository;
|
||||||
|
|
||||||
|
namespace Pos.Service
|
||||||
|
{
|
||||||
|
public class ProductGroupService
|
||||||
|
{
|
||||||
|
private readonly ProductGroupRepository _productGroupRepository =
|
||||||
|
new ProductGroupRepository();
|
||||||
|
|
||||||
|
public List<ProductGroupEntity> GetProductGroups()
|
||||||
|
{
|
||||||
|
return _productGroupRepository.GetAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasProductGroups()
|
||||||
|
{
|
||||||
|
return _productGroupRepository.Any();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddProductGroup(string name)
|
||||||
|
{
|
||||||
|
_productGroupRepository.Add(ValidateName(name));
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RenameProductGroup(int productGroupId, string name)
|
||||||
|
{
|
||||||
|
ValidateId(productGroupId);
|
||||||
|
_productGroupRepository.Edit(
|
||||||
|
ValidateName(name),
|
||||||
|
productGroupId);
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ArchiveProductGroup(int productGroupId)
|
||||||
|
{
|
||||||
|
ValidateId(productGroupId);
|
||||||
|
_productGroupRepository.Archive(productGroupId);
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateOrder(IReadOnlyList<int> orderedProductGroupIds)
|
||||||
|
{
|
||||||
|
ValidateOrder(orderedProductGroupIds);
|
||||||
|
_productGroupRepository.SetOrder(orderedProductGroupIds);
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ValidateName(string name)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
|
throw new ArgumentException(
|
||||||
|
"Produktgruppen skal have et navn.",
|
||||||
|
nameof(name));
|
||||||
|
|
||||||
|
return name.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateId(int productGroupId)
|
||||||
|
{
|
||||||
|
if (productGroupId <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(productGroupId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateOrder(IReadOnlyList<int> orderedIds)
|
||||||
|
{
|
||||||
|
if (orderedIds == null)
|
||||||
|
throw new ArgumentNullException(nameof(orderedIds));
|
||||||
|
|
||||||
|
if (orderedIds.Any(id => id <= 0))
|
||||||
|
throw new ArgumentException(
|
||||||
|
"Rækkefølgen indeholder et ugyldigt id.",
|
||||||
|
nameof(orderedIds));
|
||||||
|
|
||||||
|
if (orderedIds.Distinct().Count() != orderedIds.Count)
|
||||||
|
throw new ArgumentException(
|
||||||
|
"Rækkefølgen indeholder dubletter.",
|
||||||
|
nameof(orderedIds));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
95
PointOfSale/Pos.Service/ProductService.cs
Normal file
95
PointOfSale/Pos.Service/ProductService.cs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Database.Models;
|
||||||
|
using Database.Repository;
|
||||||
|
|
||||||
|
namespace Pos.Service
|
||||||
|
{
|
||||||
|
public class ProductService
|
||||||
|
{
|
||||||
|
private readonly ProductRepository _productRepository =
|
||||||
|
new ProductRepository();
|
||||||
|
|
||||||
|
public List<ProductEntity> GetProducts(int productGroupId)
|
||||||
|
{
|
||||||
|
ValidateId(productGroupId, nameof(productGroupId));
|
||||||
|
return _productRepository.GetByProductGroup(productGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductEntity GetProduct(int productId)
|
||||||
|
{
|
||||||
|
ValidateId(productId, nameof(productId));
|
||||||
|
return _productRepository.GetById(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddProduct(string name, int productGroupId)
|
||||||
|
{
|
||||||
|
ValidateId(productGroupId, nameof(productGroupId));
|
||||||
|
_productRepository.Add(ValidateName(name), productGroupId);
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateProduct(
|
||||||
|
int productId,
|
||||||
|
int productGroupId,
|
||||||
|
string name)
|
||||||
|
{
|
||||||
|
ValidateId(productId, nameof(productId));
|
||||||
|
ValidateId(productGroupId, nameof(productGroupId));
|
||||||
|
_productRepository.Update(
|
||||||
|
productId,
|
||||||
|
productGroupId,
|
||||||
|
ValidateName(name));
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ArchiveProduct(int productId)
|
||||||
|
{
|
||||||
|
ValidateId(productId, nameof(productId));
|
||||||
|
_productRepository.Archive(productId);
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateOrder(
|
||||||
|
int productGroupId,
|
||||||
|
IReadOnlyList<int> orderedProductIds)
|
||||||
|
{
|
||||||
|
ValidateId(productGroupId, nameof(productGroupId));
|
||||||
|
|
||||||
|
if (orderedProductIds == null)
|
||||||
|
throw new ArgumentNullException(nameof(orderedProductIds));
|
||||||
|
|
||||||
|
if (orderedProductIds.Any(id => id <= 0))
|
||||||
|
throw new ArgumentException(
|
||||||
|
"Rækkefølgen indeholder et ugyldigt id.",
|
||||||
|
nameof(orderedProductIds));
|
||||||
|
|
||||||
|
if (orderedProductIds.Distinct().Count() != orderedProductIds.Count)
|
||||||
|
throw new ArgumentException(
|
||||||
|
"Rækkefølgen indeholder dubletter.",
|
||||||
|
nameof(orderedProductIds));
|
||||||
|
|
||||||
|
_productRepository.SetOrder(
|
||||||
|
productGroupId,
|
||||||
|
orderedProductIds);
|
||||||
|
CacheService.Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ValidateName(string name)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
|
throw new ArgumentException(
|
||||||
|
"Produktet skal have et navn.",
|
||||||
|
nameof(name));
|
||||||
|
|
||||||
|
return name.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateId(int id, string parameterName)
|
||||||
|
{
|
||||||
|
if (id <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(parameterName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
74
PointOfSale/Pos.Service/SaleHistoryService.cs
Normal file
74
PointOfSale/Pos.Service/SaleHistoryService.cs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Database.Models;
|
||||||
|
using Database.Repository;
|
||||||
|
using Pos.Models;
|
||||||
|
|
||||||
|
namespace Pos.Service
|
||||||
|
{
|
||||||
|
public class SaleHistoryService
|
||||||
|
{
|
||||||
|
private readonly SaleRepository _saleRepository =
|
||||||
|
new SaleRepository();
|
||||||
|
|
||||||
|
public List<ReceiptSummaryModel> Search(
|
||||||
|
DateTime startDate,
|
||||||
|
DateTime endDate)
|
||||||
|
{
|
||||||
|
if (endDate.Date < startDate.Date)
|
||||||
|
throw new ArgumentException(
|
||||||
|
"Slutdatoen må ikke ligge før startdatoen.");
|
||||||
|
|
||||||
|
List<SaleEntity> sales =
|
||||||
|
_saleRepository.GetByDateRange(startDate, endDate);
|
||||||
|
|
||||||
|
List<ReceiptSummaryModel> receipts =
|
||||||
|
new List<ReceiptSummaryModel>();
|
||||||
|
|
||||||
|
foreach (SaleEntity sale in sales)
|
||||||
|
{
|
||||||
|
decimal total = _saleRepository
|
||||||
|
.GetSaleLineBySaleId(sale.Id)
|
||||||
|
.Sum(line => line.Total);
|
||||||
|
|
||||||
|
receipts.Add(new ReceiptSummaryModel
|
||||||
|
{
|
||||||
|
SaleId = sale.Id,
|
||||||
|
SaleTime = sale.Time,
|
||||||
|
Total = total
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return receipts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReceiptDetailModel GetReceipt(int saleId)
|
||||||
|
{
|
||||||
|
if (saleId <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(saleId));
|
||||||
|
|
||||||
|
List<SaleLineEntity> saleLines =
|
||||||
|
_saleRepository.GetSaleLineBySaleId(saleId);
|
||||||
|
|
||||||
|
ReceiptDetailModel receipt = new ReceiptDetailModel
|
||||||
|
{
|
||||||
|
SaleId = saleId
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (SaleLineEntity saleLine in saleLines)
|
||||||
|
{
|
||||||
|
receipt.Lines.Add(new ReceiptLineModel
|
||||||
|
{
|
||||||
|
Product = saleLine.Product,
|
||||||
|
Pieces = saleLine.Pieces,
|
||||||
|
Price = saleLine.Price,
|
||||||
|
Total = saleLine.Total
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
receipt.Total = receipt.Lines.Sum(line => line.Total);
|
||||||
|
return receipt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,10 +69,30 @@ namespace Database.Repository
|
|||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetOrder(IReadOnlyList<int> orderedIds)
|
||||||
|
{
|
||||||
|
using PosDbContext context = new PosDbContext();
|
||||||
|
List<ProductGroupEntity> productGroups = context.ProductGroups
|
||||||
|
.Where(productGroup => orderedIds.Contains(productGroup.Id))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (productGroups.Count != orderedIds.Count)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"En eller flere produktgrupper findes ikke.");
|
||||||
|
|
||||||
|
Dictionary<int, ProductGroupEntity> productGroupsById =
|
||||||
|
productGroups.ToDictionary(productGroup => productGroup.Id);
|
||||||
|
|
||||||
|
for (int index = 0; index < orderedIds.Count; index++)
|
||||||
|
productGroupsById[orderedIds[index]].Index = index;
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
public bool Any()
|
public bool Any()
|
||||||
{
|
{
|
||||||
using PosDbContext context = new PosDbContext();
|
using PosDbContext context = new PosDbContext();
|
||||||
bool any = context.ProductGroups.Any();
|
bool any = context.ProductGroups.Any(c => !c.IsArchived);
|
||||||
return any;
|
return any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Database.Models;
|
using Database.Models;
|
||||||
|
|
||||||
@@ -38,6 +39,33 @@ namespace Database.Repository
|
|||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetOrder(
|
||||||
|
int productGroupId,
|
||||||
|
IReadOnlyList<int> orderedIds)
|
||||||
|
{
|
||||||
|
using PosDbContext context = new PosDbContext();
|
||||||
|
List<ProductEntity> products = context.Products
|
||||||
|
.Where(product => product.ProductGroupId == productGroupId)
|
||||||
|
.Where(product => orderedIds.Contains(product.Id))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (products.Count != orderedIds.Count)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Et eller flere produkter findes ikke i produktgruppen.");
|
||||||
|
|
||||||
|
Dictionary<int, ProductEntity> productsById =
|
||||||
|
products.ToDictionary(product => product.Id);
|
||||||
|
|
||||||
|
for (int index = 0; index < orderedIds.Count; index++)
|
||||||
|
{
|
||||||
|
ProductEntity product = productsById[orderedIds[index]];
|
||||||
|
product.Index = index;
|
||||||
|
product.IsModified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
public ProductEntity GetById(int id)
|
public ProductEntity GetById(int id)
|
||||||
{
|
{
|
||||||
using PosDbContext context = new PosDbContext();
|
using PosDbContext context = new PosDbContext();
|
||||||
@@ -72,7 +100,11 @@ namespace Database.Repository
|
|||||||
product.ProductGroupId = productGroupId;
|
product.ProductGroupId = productGroupId;
|
||||||
using PosDbContext context = new PosDbContext();
|
using PosDbContext context = new PosDbContext();
|
||||||
//Get the highest index
|
//Get the highest index
|
||||||
ProductEntity highest = context.Products.OrderByDescending(c => c.Index).Take(1).FirstOrDefault();
|
ProductEntity highest = context.Products
|
||||||
|
.Where(c => c.ProductGroupId == productGroupId)
|
||||||
|
.OrderByDescending(c => c.Index)
|
||||||
|
.Take(1)
|
||||||
|
.FirstOrDefault();
|
||||||
if (highest == null)
|
if (highest == null)
|
||||||
{
|
{
|
||||||
highest = new ProductEntity();
|
highest = new ProductEntity();
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Models;
|
using Pos.Models;
|
||||||
using Database.Repository;
|
|
||||||
using Pos.Service;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos
|
namespace Pos
|
||||||
@@ -25,6 +24,9 @@ namespace Pos
|
|||||||
private List<ListReceiptModel> _receiptList = new List<ListReceiptModel>();
|
private List<ListReceiptModel> _receiptList = new List<ListReceiptModel>();
|
||||||
private bool _init = false;
|
private bool _init = false;
|
||||||
private int _saleId = 0;
|
private int _saleId = 0;
|
||||||
|
private readonly SaleHistoryService _saleHistoryService =
|
||||||
|
new SaleHistoryService();
|
||||||
|
private readonly SaleService _saleService = new SaleService();
|
||||||
|
|
||||||
public PrintReceiptWindow()
|
public PrintReceiptWindow()
|
||||||
{
|
{
|
||||||
@@ -38,28 +40,39 @@ namespace Pos
|
|||||||
|
|
||||||
private void Search_OnClick(object sender, RoutedEventArgs e)
|
private void Search_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
DateTime startDate = (DateTime)StartDatePicker.SelectedDate;
|
if (StartDatePicker.SelectedDate is not DateTime startDate ||
|
||||||
DateTime endDate = (DateTime)EndDatePicker.SelectedDate;
|
EndDatePicker.SelectedDate is not DateTime endDate)
|
||||||
SaleRepository saleRepository = new SaleRepository();
|
return;
|
||||||
List<SaleEntity> saleEntities = saleRepository.GetByDateRange(startDate, endDate);
|
|
||||||
foreach (SaleEntity entity in saleEntities)
|
|
||||||
{
|
|
||||||
List<SaleLineEntity> saleLineBySaleId = saleRepository.GetSaleLineBySaleId(entity.Id);
|
|
||||||
decimal total = 0;
|
|
||||||
foreach (SaleLineEntity lineEntity in saleLineBySaleId)
|
|
||||||
{
|
|
||||||
total += lineEntity.Total;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
List<ReceiptSummaryModel> receipts;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
receipts = _saleHistoryService.Search(startDate, endDate);
|
||||||
|
}
|
||||||
|
catch (ArgumentException exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
exception.Message,
|
||||||
|
"Ugyldigt datointerval",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_receiptList.Clear();
|
||||||
|
foreach (ReceiptSummaryModel receipt in receipts)
|
||||||
|
{
|
||||||
ListReceiptModel receiptModel = new ListReceiptModel
|
ListReceiptModel receiptModel = new ListReceiptModel
|
||||||
{
|
{
|
||||||
Id = entity.Id,
|
Id = receipt.SaleId,
|
||||||
Content = $"{entity.Time:dd-MM-yyyy HH:mm} - Pris: {total:0.00}"
|
Content =
|
||||||
|
$"{receipt.SaleTime:dd-MM-yyyy HH:mm} - Pris: {receipt.Total:0.00}"
|
||||||
};
|
};
|
||||||
_receiptList.Add(receiptModel);
|
_receiptList.Add(receiptModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
_init = true;
|
_init = true;
|
||||||
|
ListReciept.ItemsSource = null;
|
||||||
ListReciept.ItemsSource = _receiptList;
|
ListReciept.ItemsSource = _receiptList;
|
||||||
_init = false;
|
_init = false;
|
||||||
}
|
}
|
||||||
@@ -78,23 +91,21 @@ namespace Pos
|
|||||||
|
|
||||||
private void ListReciept_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void ListReciept_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (_init)
|
if (_init || e.AddedItems.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ListReceiptModel data = (ListReceiptModel) e.AddedItems[0];
|
ListReceiptModel data = (ListReceiptModel) e.AddedItems[0];
|
||||||
_saleId = data.Id;
|
_saleId = data.Id;
|
||||||
SaleRepository saleRepository = new SaleRepository();
|
ReceiptDetailModel receipt =
|
||||||
List<SaleLineEntity> saleLineBySaleId = saleRepository.GetSaleLineBySaleId(data.Id);
|
_saleHistoryService.GetReceipt(data.Id);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
decimal total = 0;
|
foreach (ReceiptLineModel saleLine in receipt.Lines)
|
||||||
foreach (SaleLineEntity saleLine in saleLineBySaleId)
|
|
||||||
{
|
{
|
||||||
total += saleLine.Total;
|
|
||||||
sb.AppendLine(
|
sb.AppendLine(
|
||||||
$"{saleLine.Product} - {saleLine.Pieces} stk. a' {saleLine.Price.ToString("0.00")} = {saleLine.Total.ToString("0.00")}");
|
$"{saleLine.Product} - {saleLine.Pieces} stk. a' {saleLine.Price:0.00} = {saleLine.Total:0.00}");
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.AppendLine($"Total: {total.ToString("0.00")} kr.");
|
sb.AppendLine($"Total: {receipt.Total:0.00} kr.");
|
||||||
PrintReceipt.Visibility = Visibility.Visible;
|
PrintReceipt.Visibility = Visibility.Visible;
|
||||||
SaleLines.Clear();
|
SaleLines.Clear();
|
||||||
SaleLines.Text = sb.ToString();
|
SaleLines.Text = sb.ToString();
|
||||||
@@ -102,8 +113,7 @@ namespace Pos
|
|||||||
|
|
||||||
private void PrintReceipt_OnClick(object sender, RoutedEventArgs e)
|
private void PrintReceipt_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
SaleService saleService = new SaleService();
|
_saleService.PrintReceipt(_saleId);
|
||||||
saleService.PrintReceipt(_saleId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ namespace Pos
|
|||||||
{
|
{
|
||||||
private bool _initialLoad = true;
|
private bool _initialLoad = true;
|
||||||
private TotalSaleDetail totalSaleDetail;
|
private TotalSaleDetail totalSaleDetail;
|
||||||
|
private readonly SaleService _saleService = new SaleService();
|
||||||
public SaleOfDay()
|
public SaleOfDay()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
SaleService saleService = new SaleService();
|
totalSaleDetail = _saleService.TotalSale(DateTime.Now);
|
||||||
totalSaleDetail = saleService.TotalSale(DateTime.Now);
|
|
||||||
TotalSale.Content = $"Dagens salg: kr. {totalSaleDetail.TotalSale:0.00}";
|
TotalSale.Content = $"Dagens salg: kr. {totalSaleDetail.TotalSale:0.00}";
|
||||||
StartDatePicker.SelectedDate = DateTime.Now;
|
StartDatePicker.SelectedDate = DateTime.Now;
|
||||||
GridSaleDetail.ItemsSource = totalSaleDetail.TotalSaleCategories;
|
GridSaleDetail.ItemsSource = totalSaleDetail.TotalSaleCategories;
|
||||||
@@ -29,18 +29,20 @@ namespace Pos
|
|||||||
if (_initialLoad)
|
if (_initialLoad)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_initialLoad = false;
|
if (StartDatePicker.SelectedDate is not DateTime selectedDate)
|
||||||
DateTime selectedDate = DateTime.Parse(sender.ToString());
|
return;
|
||||||
SaleService saleService = new SaleService();
|
|
||||||
totalSaleDetail = saleService.TotalSale(selectedDate);
|
totalSaleDetail = _saleService.TotalSale(selectedDate);
|
||||||
TotalSale.Content = $"Dagens salg: kr. {totalSaleDetail.TotalSale:0.00}";
|
TotalSale.Content = $"Dagens salg: kr. {totalSaleDetail.TotalSale:0.00}";
|
||||||
GridSaleDetail.ItemsSource = totalSaleDetail.TotalSaleCategories;
|
GridSaleDetail.ItemsSource = totalSaleDetail.TotalSaleCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PrintSale_OnClick(object sender, RoutedEventArgs e)
|
private void PrintSale_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
SaleService saleService = new SaleService();
|
if (StartDatePicker.SelectedDate is not DateTime selectedDate)
|
||||||
saleService.PrintSaleOfDay(StartDatePicker.SelectedDate.Value,totalSaleDetail);
|
return;
|
||||||
|
|
||||||
|
_saleService.PrintSaleOfDay(selectedDate, totalSaleDetail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting
|
namespace Pos.Setting
|
||||||
{
|
{
|
||||||
@@ -20,6 +20,9 @@ namespace Pos.Setting
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class AddEmployeeWindow : Window
|
public partial class AddEmployeeWindow : Window
|
||||||
{
|
{
|
||||||
|
private readonly EmployeeService _employeeService =
|
||||||
|
new EmployeeService();
|
||||||
|
|
||||||
public AddEmployeeWindow()
|
public AddEmployeeWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -27,9 +30,19 @@ namespace Pos.Setting
|
|||||||
|
|
||||||
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
EmployeeRepository employeeRepository = new EmployeeRepository();
|
try
|
||||||
employeeRepository.Add(txtStaff.Text);
|
{
|
||||||
this.Close();
|
_employeeService.AddEmployee(txtStaff.Text);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (ArgumentException exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
exception.Message,
|
||||||
|
"Ugyldig medarbejder",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting
|
namespace Pos.Setting
|
||||||
{
|
{
|
||||||
@@ -21,6 +21,8 @@ namespace Pos.Setting
|
|||||||
public partial class DeleteEmployeeWindow : Window
|
public partial class DeleteEmployeeWindow : Window
|
||||||
{
|
{
|
||||||
private int _employeeId;
|
private int _employeeId;
|
||||||
|
private readonly EmployeeService _employeeService =
|
||||||
|
new EmployeeService();
|
||||||
|
|
||||||
public DeleteEmployeeWindow(int employeeId, string staffName)
|
public DeleteEmployeeWindow(int employeeId, string staffName)
|
||||||
{
|
{
|
||||||
@@ -31,9 +33,8 @@ namespace Pos.Setting
|
|||||||
|
|
||||||
private void btnYes_Click(object sender, RoutedEventArgs e)
|
private void btnYes_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
EmployeeRepository employeeRepository = new EmployeeRepository();
|
_employeeService.ArchiveEmployee(_employeeId);
|
||||||
employeeRepository.Delete(_employeeId);
|
Close();
|
||||||
this.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnNo_Click(object sender, RoutedEventArgs e)
|
private void btnNo_Click(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting
|
namespace Pos.Setting
|
||||||
{
|
{
|
||||||
@@ -21,6 +21,8 @@ namespace Pos.Setting
|
|||||||
public partial class EditEmployeeWindow : Window
|
public partial class EditEmployeeWindow : Window
|
||||||
{
|
{
|
||||||
private int _employeeId;
|
private int _employeeId;
|
||||||
|
private readonly EmployeeService _employeeService =
|
||||||
|
new EmployeeService();
|
||||||
|
|
||||||
public EditEmployeeWindow(int employeeId, string staffName)
|
public EditEmployeeWindow(int employeeId, string staffName)
|
||||||
{
|
{
|
||||||
@@ -31,9 +33,21 @@ namespace Pos.Setting
|
|||||||
|
|
||||||
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
EmployeeRepository employeeRepository = new EmployeeRepository();
|
try
|
||||||
employeeRepository.Edit(_employeeId,txtEmployee.Text);
|
{
|
||||||
this.Close();
|
_employeeService.RenameEmployee(
|
||||||
|
_employeeId,
|
||||||
|
txtEmployee.Text);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (ArgumentException exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
exception.Message,
|
||||||
|
"Ugyldig medarbejder",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Models;
|
using Database.Models;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting
|
namespace Pos.Setting
|
||||||
{
|
{
|
||||||
@@ -24,6 +24,8 @@ namespace Pos.Setting
|
|||||||
{
|
{
|
||||||
private int _selectedEmployee = -1;
|
private int _selectedEmployee = -1;
|
||||||
private string _employeeName = string.Empty;
|
private string _employeeName = string.Empty;
|
||||||
|
private readonly EmployeeService _employeeService =
|
||||||
|
new EmployeeService();
|
||||||
public EmployeeWindow()
|
public EmployeeWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -62,15 +64,14 @@ namespace Pos.Setting
|
|||||||
deleteEmployeeWindow.Show();
|
deleteEmployeeWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WindowClosed(object? sender, EventArgs e)
|
private void WindowClosed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
using EmployeeRepository employeeRepository = new EmployeeRepository();
|
List<EmployeeEntity> allStaff = _employeeService.GetEmployees();
|
||||||
List<EmployeeEntity> allStaff = employeeRepository.GetAll();
|
|
||||||
LstStaff.Items.Clear();
|
LstStaff.Items.Clear();
|
||||||
foreach (EmployeeEntity staff in allStaff)
|
foreach (EmployeeEntity staff in allStaff)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Database.Repository;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting.ProductGroup
|
namespace Pos.Setting.ProductGroup
|
||||||
{
|
{
|
||||||
@@ -11,6 +11,11 @@ namespace Pos.Setting.ProductGroup
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class AddProductWindow : Window
|
public partial class AddProductWindow : Window
|
||||||
{
|
{
|
||||||
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
|
private readonly ProductService _productService =
|
||||||
|
new ProductService();
|
||||||
|
|
||||||
public AddProductWindow()
|
public AddProductWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -19,13 +24,16 @@ namespace Pos.Setting.ProductGroup
|
|||||||
|
|
||||||
private void LoadData(int selectedIndex)
|
private void LoadData(int selectedIndex)
|
||||||
{
|
{
|
||||||
ProductGroupRepository productGroupRepository = new ProductGroupRepository();
|
List<Database.Models.ProductGroupEntity> productGroups =
|
||||||
List<Database.Models.ProductGroupEntity> products = productGroupRepository.GetAll();
|
_productGroupService.GetProductGroups();
|
||||||
foreach (Database.Models.ProductGroupEntity productGroup in products)
|
|
||||||
|
foreach (Database.Models.ProductGroupEntity productGroup in productGroups)
|
||||||
{
|
{
|
||||||
ComboBoxItem comboBoxItem = new ComboBoxItem();
|
ComboBoxItem comboBoxItem = new ComboBoxItem
|
||||||
comboBoxItem.Tag = productGroup.Id;
|
{
|
||||||
comboBoxItem.Content = productGroup.Name;
|
Tag = productGroup.Id,
|
||||||
|
Content = productGroup.Name
|
||||||
|
};
|
||||||
cmbProductGroup.Items.Add(comboBoxItem);
|
cmbProductGroup.Items.Add(comboBoxItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,12 +42,23 @@ namespace Pos.Setting.ProductGroup
|
|||||||
|
|
||||||
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ComboBoxItem item = (ComboBoxItem) cmbProductGroup.SelectedItem;
|
ComboBoxItem item = (ComboBoxItem)cmbProductGroup.SelectedItem;
|
||||||
string name = txtProduct.Text;
|
|
||||||
int id = Convert.ToInt32(item.Tag);
|
try
|
||||||
ProductRepository productRepository = new ProductRepository();
|
{
|
||||||
productRepository.Add(name,id);
|
_productService.AddProduct(
|
||||||
this.Close();
|
txtProduct.Text,
|
||||||
|
Convert.ToInt32(item.Tag));
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (ArgumentException exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
exception.Message,
|
||||||
|
"Ugyldigt produkt",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting.Product
|
namespace Pos.Setting.Product
|
||||||
{
|
{
|
||||||
@@ -21,20 +21,21 @@ namespace Pos.Setting.Product
|
|||||||
public partial class ArchiveProductWindow : Window
|
public partial class ArchiveProductWindow : Window
|
||||||
{
|
{
|
||||||
private int _productId;
|
private int _productId;
|
||||||
|
private readonly ProductService _productService =
|
||||||
|
new ProductService();
|
||||||
public ArchiveProductWindow(int productId)
|
public ArchiveProductWindow(int productId)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_productId = productId;
|
_productId = productId;
|
||||||
ProductRepository productRepository = new ProductRepository();
|
Database.Models.ProductEntity product =
|
||||||
Database.Models.ProductEntity product = productRepository.GetById(_productId);
|
_productService.GetProduct(_productId);
|
||||||
txtDelProduct.Text = product.Name;
|
txtDelProduct.Text = product.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnYes_Click(object sender, RoutedEventArgs e)
|
private void btnYes_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ProductRepository productRepository = new ProductRepository();
|
_productService.ArchiveProduct(_productId);
|
||||||
productRepository.Archive(_productId);
|
Close();
|
||||||
this.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnNo_Click(object sender, RoutedEventArgs e)
|
private void btnNo_Click(object sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting.Product
|
namespace Pos.Setting.Product
|
||||||
{
|
{
|
||||||
@@ -23,6 +23,8 @@ namespace Pos.Setting.Product
|
|||||||
{
|
{
|
||||||
ObservableCollection<Database.Models.ProductEntity> _productList = new ObservableCollection<Database.Models.ProductEntity>();
|
ObservableCollection<Database.Models.ProductEntity> _productList = new ObservableCollection<Database.Models.ProductEntity>();
|
||||||
private int _productGroupId;
|
private int _productGroupId;
|
||||||
|
private readonly ProductService _productService =
|
||||||
|
new ProductService();
|
||||||
public ChangeProductOrderWindow(int productGroupId)
|
public ChangeProductOrderWindow(int productGroupId)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -32,8 +34,8 @@ namespace Pos.Setting.Product
|
|||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
ProductRepository productRepository = new ProductRepository();
|
List<Database.Models.ProductEntity> products =
|
||||||
List<Database.Models.ProductEntity> products = productRepository.GetByProductGroup(_productGroupId);
|
_productService.GetProducts(_productGroupId);
|
||||||
foreach (Database.Models.ProductEntity product in products)
|
foreach (Database.Models.ProductEntity product in products)
|
||||||
{
|
{
|
||||||
_productList.Add(product);
|
_productList.Add(product);
|
||||||
@@ -86,13 +88,10 @@ namespace Pos.Setting.Product
|
|||||||
|
|
||||||
private void btnSave_Click(object sender, RoutedEventArgs e)
|
private void btnSave_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ProductRepository productRepository = new ProductRepository();
|
_productService.UpdateOrder(
|
||||||
for (int i = 0; i < _productList.Count; i++)
|
_productGroupId,
|
||||||
{
|
_productList.Select(product => product.Id).ToList());
|
||||||
Database.Models.ProductEntity product = _productList[i];
|
Close();
|
||||||
productRepository.SetIndex(product.Id, i);
|
|
||||||
}
|
|
||||||
this.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting.Product
|
namespace Pos.Setting.Product
|
||||||
{
|
{
|
||||||
@@ -23,6 +23,10 @@ namespace Pos.Setting.Product
|
|||||||
private int _productId;
|
private int _productId;
|
||||||
private int _selectedProductGroupId;
|
private int _selectedProductGroupId;
|
||||||
private Database.Models.ProductEntity _product;
|
private Database.Models.ProductEntity _product;
|
||||||
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
|
private readonly ProductService _productService =
|
||||||
|
new ProductService();
|
||||||
|
|
||||||
public EditProductWindow(int productId, int selectedProductGroupId)
|
public EditProductWindow(int productId, int selectedProductGroupId)
|
||||||
{
|
{
|
||||||
@@ -34,8 +38,8 @@ namespace Pos.Setting.Product
|
|||||||
|
|
||||||
private void Init()
|
private void Init()
|
||||||
{
|
{
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
List<Database.Models.ProductGroupEntity> productGroups =
|
||||||
List<Database.Models.ProductGroupEntity> productGroups = categoryRepository.GetAll();
|
_productGroupService.GetProductGroups();
|
||||||
foreach (Database.Models.ProductGroupEntity productGroup in productGroups)
|
foreach (Database.Models.ProductGroupEntity productGroup in productGroups)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -46,17 +50,29 @@ namespace Pos.Setting.Product
|
|||||||
}
|
}
|
||||||
cmbProductGroup.SelectedIndex = _selectedProductGroupId;
|
cmbProductGroup.SelectedIndex = _selectedProductGroupId;
|
||||||
|
|
||||||
ProductRepository productRepository = new ProductRepository();
|
_product = _productService.GetProduct(_productId);
|
||||||
_product = productRepository.GetById(_productId);
|
|
||||||
txtProduct.Text = _product.Name;
|
txtProduct.Text = _product.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ComboBoxItem item = (ComboBoxItem)cmbProductGroup.SelectedItem;
|
ComboBoxItem item = (ComboBoxItem)cmbProductGroup.SelectedItem;
|
||||||
ProductRepository productRepository = new ProductRepository();
|
try
|
||||||
productRepository.Update(_product.Id,(int)item.Tag,txtProduct.Text);
|
{
|
||||||
this.Close();
|
_productService.UpdateProduct(
|
||||||
|
_product.Id,
|
||||||
|
(int)item.Tag,
|
||||||
|
txtProduct.Text);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (ArgumentException exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
exception.Message,
|
||||||
|
"Ugyldigt produkt",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
using Pos.Setting.Product;
|
using Pos.Setting.Product;
|
||||||
|
|
||||||
namespace Pos.Setting.ProductGroup
|
namespace Pos.Setting.ProductGroup
|
||||||
@@ -14,7 +14,10 @@ namespace Pos.Setting.ProductGroup
|
|||||||
public partial class ProductWindow : Window
|
public partial class ProductWindow : Window
|
||||||
{
|
{
|
||||||
private List<Database.Models.ProductGroupEntity> _productGroups;
|
private List<Database.Models.ProductGroupEntity> _productGroups;
|
||||||
private int _productId;
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
|
private readonly ProductService _productService =
|
||||||
|
new ProductService();
|
||||||
|
|
||||||
public ProductWindow()
|
public ProductWindow()
|
||||||
{
|
{
|
||||||
@@ -26,8 +29,7 @@ namespace Pos.Setting.ProductGroup
|
|||||||
|
|
||||||
private void Init()
|
private void Init()
|
||||||
{
|
{
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
_productGroups = _productGroupService.GetProductGroups();
|
||||||
_productGroups = categoryRepository.GetAll();
|
|
||||||
cmbCat.Items.Clear();
|
cmbCat.Items.Clear();
|
||||||
foreach (Database.Models.ProductGroupEntity productGroup in _productGroups)
|
foreach (Database.Models.ProductGroupEntity productGroup in _productGroups)
|
||||||
{
|
{
|
||||||
@@ -38,14 +40,19 @@ namespace Pos.Setting.ProductGroup
|
|||||||
cmbCat.Items.Add(comboBoxItem);
|
cmbCat.Items.Add(comboBoxItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmbCat.SelectedIndex = 0;
|
if (_productGroups.Count > 0)
|
||||||
|
cmbCat.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
|
|
||||||
ProductRepository productRepository = new ProductRepository();
|
if (cmbCat.SelectedIndex < 0)
|
||||||
List<Database.Models.ProductEntity> products = productRepository.GetByProductGroup(_productGroups[cmbCat.SelectedIndex].Id);
|
return;
|
||||||
|
|
||||||
|
List<Database.Models.ProductEntity> products =
|
||||||
|
_productService.GetProducts(
|
||||||
|
_productGroups[cmbCat.SelectedIndex].Id);
|
||||||
lstProductGroup.Items.Clear();
|
lstProductGroup.Items.Clear();
|
||||||
foreach (Database.Models.ProductEntity product in products)
|
foreach (Database.Models.ProductEntity product in products)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting.Category
|
namespace Pos.Setting.Category
|
||||||
{
|
{
|
||||||
@@ -20,6 +20,9 @@ namespace Pos.Setting.Category
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class AddProductGroupWindow : Window
|
public partial class AddProductGroupWindow : Window
|
||||||
{
|
{
|
||||||
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
|
|
||||||
public AddProductGroupWindow()
|
public AddProductGroupWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -27,9 +30,19 @@ namespace Pos.Setting.Category
|
|||||||
|
|
||||||
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
try
|
||||||
categoryRepository.Add(txtProductGroup.Text);
|
{
|
||||||
this.Close();
|
_productGroupService.AddProductGroup(txtProductGroup.Text);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (ArgumentException exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
exception.Message,
|
||||||
|
"Ugyldig produktgruppe",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting.Category
|
namespace Pos.Setting.Category
|
||||||
{
|
{
|
||||||
@@ -21,6 +21,8 @@ namespace Pos.Setting.Category
|
|||||||
public partial class ArchiveProductGroupWindow : Window
|
public partial class ArchiveProductGroupWindow : Window
|
||||||
{
|
{
|
||||||
private readonly int _id;
|
private readonly int _id;
|
||||||
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
public ArchiveProductGroupWindow(string name, int id)
|
public ArchiveProductGroupWindow(string name, int id)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -36,9 +38,8 @@ namespace Pos.Setting.Category
|
|||||||
|
|
||||||
private void btnYes_Click(object sender, RoutedEventArgs e)
|
private void btnYes_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
_productGroupService.ArchiveProductGroup(_id);
|
||||||
categoryRepository.Archive(_id);
|
Close();
|
||||||
this.Close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting.Category
|
namespace Pos.Setting.Category
|
||||||
{
|
{
|
||||||
@@ -22,6 +22,8 @@ namespace Pos.Setting.Category
|
|||||||
public partial class ChangeProductGroupOrderWindow : Window
|
public partial class ChangeProductGroupOrderWindow : Window
|
||||||
{
|
{
|
||||||
ObservableCollection<Database.Models.ProductGroupEntity> _prodGroupList = new ObservableCollection<Database.Models.ProductGroupEntity>();
|
ObservableCollection<Database.Models.ProductGroupEntity> _prodGroupList = new ObservableCollection<Database.Models.ProductGroupEntity>();
|
||||||
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
public ChangeProductGroupOrderWindow()
|
public ChangeProductGroupOrderWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -30,8 +32,8 @@ namespace Pos.Setting.Category
|
|||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
List<Database.Models.ProductGroupEntity> categories =
|
||||||
List<Database.Models.ProductGroupEntity> categories = categoryRepository.GetAll();
|
_productGroupService.GetProductGroups();
|
||||||
foreach (Database.Models.ProductGroupEntity category in categories)
|
foreach (Database.Models.ProductGroupEntity category in categories)
|
||||||
{
|
{
|
||||||
_prodGroupList.Add(category);
|
_prodGroupList.Add(category);
|
||||||
@@ -84,13 +86,9 @@ namespace Pos.Setting.Category
|
|||||||
|
|
||||||
private void btnSave_Click(object sender, RoutedEventArgs e)
|
private void btnSave_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
_productGroupService.UpdateOrder(
|
||||||
for (int i = 0; i < _prodGroupList.Count; i++)
|
_prodGroupList.Select(productGroup => productGroup.Id).ToList());
|
||||||
{
|
Close();
|
||||||
Database.Models.ProductGroupEntity productGroup = _prodGroupList[i];
|
|
||||||
categoryRepository.SetIndex(productGroup.Id,i);
|
|
||||||
}
|
|
||||||
this.Close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
|
|
||||||
namespace Pos.Setting.Category
|
namespace Pos.Setting.Category
|
||||||
{
|
{
|
||||||
@@ -21,6 +21,8 @@ namespace Pos.Setting.Category
|
|||||||
public partial class EditProductGroupWindow : Window
|
public partial class EditProductGroupWindow : Window
|
||||||
{
|
{
|
||||||
private readonly int _id;
|
private readonly int _id;
|
||||||
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
|
|
||||||
public EditProductGroupWindow(string name, int id)
|
public EditProductGroupWindow(string name, int id)
|
||||||
{
|
{
|
||||||
@@ -31,9 +33,21 @@ namespace Pos.Setting.Category
|
|||||||
|
|
||||||
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
try
|
||||||
categoryRepository.Edit(txtProductGroup.Text,_id);
|
{
|
||||||
this.Close();
|
_productGroupService.RenameProductGroup(
|
||||||
|
_id,
|
||||||
|
txtProductGroup.Text);
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (ArgumentException exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
exception.Message,
|
||||||
|
"Ugyldig produktgruppe",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
using Pos.Service;
|
||||||
using Pos.Setting.Category;
|
using Pos.Setting.Category;
|
||||||
|
|
||||||
namespace Pos.Category
|
namespace Pos.Category
|
||||||
@@ -23,6 +23,8 @@ namespace Pos.Category
|
|||||||
{
|
{
|
||||||
private int _id = -1;
|
private int _id = -1;
|
||||||
private string _name = string.Empty;
|
private string _name = string.Empty;
|
||||||
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
|
|
||||||
public ProductGroupWindow()
|
public ProductGroupWindow()
|
||||||
{
|
{
|
||||||
@@ -53,8 +55,8 @@ namespace Pos.Category
|
|||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
List<Database.Models.ProductGroupEntity> categories =
|
||||||
List<Database.Models.ProductGroupEntity> categories = categoryRepository.GetAll();
|
_productGroupService.GetProductGroups();
|
||||||
LstCategory.Items.Clear();
|
LstCategory.Items.Clear();
|
||||||
foreach (Database.Models.ProductGroupEntity category in categories)
|
foreach (Database.Models.ProductGroupEntity category in categories)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Database.Repository;
|
|
||||||
using Pos.Category;
|
using Pos.Category;
|
||||||
|
using Pos.Service;
|
||||||
using Pos.Setting.ProductGroup;
|
using Pos.Setting.ProductGroup;
|
||||||
|
|
||||||
namespace Pos.Setting
|
namespace Pos.Setting
|
||||||
@@ -22,6 +22,9 @@ namespace Pos.Setting
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class SettingWindow : Window
|
public partial class SettingWindow : Window
|
||||||
{
|
{
|
||||||
|
private readonly ProductGroupService _productGroupService =
|
||||||
|
new ProductGroupService();
|
||||||
|
|
||||||
public SettingWindow()
|
public SettingWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -42,10 +45,8 @@ namespace Pos.Setting
|
|||||||
|
|
||||||
private void btnProductGroups_Click(object sender, RoutedEventArgs e)
|
private void btnProductGroups_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ProductWindow productWindow = new ProductWindow();
|
|
||||||
//Check if there is any categories, if not close this window with a message.
|
//Check if there is any categories, if not close this window with a message.
|
||||||
ProductGroupRepository categoryRepository = new ProductGroupRepository();
|
bool anyExist = _productGroupService.HasProductGroups();
|
||||||
bool anyExist = categoryRepository.Any();
|
|
||||||
if (!anyExist)
|
if (!anyExist)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Der er ingen kategorier, opret dem først", "Kategorier", MessageBoxButton.OK,
|
MessageBox.Show("Der er ingen kategorier, opret dem først", "Kategorier", MessageBoxButton.OK,
|
||||||
@@ -53,6 +54,7 @@ namespace Pos.Setting
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ProductWindow productWindow = new ProductWindow();
|
||||||
productWindow.Show();
|
productWindow.Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user