diff --git a/TinyPOS/TinyPosEntity/Entity/Product.cs b/TinyPOS/TinyPosEntity/Entity/Product.cs new file mode 100644 index 0000000..bb0a718 --- /dev/null +++ b/TinyPOS/TinyPosEntity/Entity/Product.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TinyPosEntity.Entity +{ + public class Product + { + public int ProductId { get; set; } + + [MaxLength(450)] + [Index(IsUnique = true)] + public string Barcode { get; set; } + + public ProductType ProductType { get; set; } + + public string Name { get; set; } + + public int Price { get; set; } + } +} diff --git a/TinyPOS/TinyPosEntity/Entity/ProductType.cs b/TinyPOS/TinyPosEntity/Entity/ProductType.cs new file mode 100644 index 0000000..594e0ad --- /dev/null +++ b/TinyPOS/TinyPosEntity/Entity/ProductType.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TinyPosEntity.Entity +{ + public class ProductType + { + public int ProductTypeId { get; set; } + + [MaxLength(450)] + [Index(IsUnique = true)] + public string Name { get; set; } + } +} diff --git a/TinyPOS/TinyPosEntity/Entity/Transaction.cs b/TinyPOS/TinyPosEntity/Entity/Transaction.cs new file mode 100644 index 0000000..a858527 --- /dev/null +++ b/TinyPOS/TinyPosEntity/Entity/Transaction.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TinyPosEntity.Entity +{ + public class Transaction + { + public string TransactionId { get; set; } + + public DateTime Timestamp { get; set; } + } +} diff --git a/TinyPOS/TinyPosEntity/Entity/TransactionItem.cs b/TinyPOS/TinyPosEntity/Entity/TransactionItem.cs new file mode 100644 index 0000000..9bc35fb --- /dev/null +++ b/TinyPOS/TinyPosEntity/Entity/TransactionItem.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TinyPosEntity.Entity +{ + public class TransactionItem + { + public string TransactionItemId { get; set; } + + public Transaction Transaction { get; set; } + + public Product Product { get; set; } + } +} diff --git a/TinyPOS/TinyPosEntity/Service/ProductService.cs b/TinyPOS/TinyPosEntity/Service/ProductService.cs new file mode 100644 index 0000000..d4985ff --- /dev/null +++ b/TinyPOS/TinyPosEntity/Service/ProductService.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TinyPosEntity.Entity; + +namespace TinyPosEntity.Service +{ + public class ProductService + { + static ProductService instance; + public static ProductService Instance { get { Init(); return instance; } } + + private static void Init() + { + if (instance == null) + instance = new ProductService(); + } + + public void Create(Product targetObject) + { + using (EntityContext context = new EntityContext()) + { + context.Products.Add(targetObject); + context.SaveChanges(); + } + } + + public void Create(List targetObject) + { + using (EntityContext context = new EntityContext()) + { + foreach (Product type in targetObject) + { + context.Products.Add(type); + } + + context.SaveChanges(); + } + } + + public Product Find(Product targetObject) + { + using (EntityContext context = new EntityContext()) + { + var qry = from p in context.Products + where p.Name.Equals(targetObject.Barcode) + select p; + + if (qry.Count() < 1) + return null; + + return qry.ToArray()[0]; + } + } + + public Product Find(string barcode) + { + using (EntityContext context = new EntityContext()) + { + var qry = from p in context.Products + where p.Name.Equals(barcode) + select p; + + if (qry.Count() < 1) + return null; + + return qry.ToArray()[0]; + } + } + + public List Find(List transactionItemList) + { + var subQry = from ti in transactionItemList + select ti.Product.ProductId; + + List productIdList = subQry.ToList(); + if (productIdList == null || productIdList.Count < 1) + return null; + + using (EntityContext context = new EntityContext()) + { + var qry = from p in context.Products + where productIdList.Contains(p.ProductId) + orderby p.ProductId ascending + select p; + + if (qry.Count() < 1) + return null; + + return qry.ToList(); + } + } + + public List Find(DateTime fromDateTime, DateTime toDateTime) + { + using (EntityContext context = new EntityContext()) + { + var qry = from p in context.Products + join ti in context.TransactionItems + on p equals ti.Product + join t in context.Transactions + on ti.Transaction equals t + where (t.Timestamp >= fromDateTime && t.Timestamp <= toDateTime) + orderby p.ProductId ascending + select p; + + if (qry.Count() < 1) + return null; + + return qry.ToList(); + } + } + + public void Remove(Product targetObject) + { + using (EntityContext context = new EntityContext()) + { + context.Database.ExecuteSqlCommand( + "DELETE FROM dbo.Products WHERE ProductId = {0}", + targetObject.ProductId); + } + } + + public void Remove(string barcode) + { + using (EntityContext context = new EntityContext()) + { + context.Database.ExecuteSqlCommand( + "DELETE FROM dbo.Products WHERE Barcode = {0}", + barcode); + } + } + } +} diff --git a/TinyPOS/TinyPosEntity/Service/ProductTypeService.cs b/TinyPOS/TinyPosEntity/Service/ProductTypeService.cs new file mode 100644 index 0000000..9af04c6 --- /dev/null +++ b/TinyPOS/TinyPosEntity/Service/ProductTypeService.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TinyPosEntity.Entity; + +namespace TinyPosEntity.Service +{ + public class ProductTypeService + { + static ProductTypeService instance; + public static ProductTypeService Instance { get { Init(); return instance; } } + + private static void Init() + { + if (instance == null) + instance = new ProductTypeService(); + } + + public void Create(ProductType targetObject) + { + using (EntityContext context = new EntityContext()) + { + context.ProductTypes.Add(targetObject); + context.SaveChanges(); + } + } + + public void Create(List targetObject) + { + using (EntityContext context = new EntityContext()) + { + foreach (ProductType type in targetObject) + { + context.ProductTypes.Add(type); + } + + context.SaveChanges(); + } + } + + public List FindAll() + { + using (EntityContext context = new EntityContext()) + { + var qry = from pt in context.ProductTypes + orderby pt.ProductTypeId ascending + select pt; + + if (qry.Count() < 1) + return null; + + return qry.ToList(); + } + } + + public ProductType Find(ProductType targetObject) + { + using (EntityContext context = new EntityContext()) + { + var qry = from pt in context.ProductTypes + where pt.Name.Equals(targetObject.Name) + select pt; + + if (qry.Count() < 1) + return null; + + return qry.ToArray()[0]; + } + } + + public ProductType Find(string name) + { + using (EntityContext context = new EntityContext()) + { + var qry = from pt in context.ProductTypes + where pt.Name.Equals(name) + select pt; + + if (qry.Count() < 1) + return null; + + return qry.ToArray()[0]; + } + } + + public void Remove(ProductType targetObject) + { + using (EntityContext context = new EntityContext()) + { + context.Database.ExecuteSqlCommand( + "DELETE FROM dbo.Students WHERE ProductTypeId = {0}", + targetObject.ProductTypeId); + } + } + + public void Remove(string name) + { + using (EntityContext context = new EntityContext()) + { + context.Database.ExecuteSqlCommand( + "DELETE FROM dbo.Students WHERE Name = {0}", + name); + } + } + } +} diff --git a/TinyPOS/TinyPosEntity/Service/TransactionItemService.cs b/TinyPOS/TinyPosEntity/Service/TransactionItemService.cs new file mode 100644 index 0000000..a34a69c --- /dev/null +++ b/TinyPOS/TinyPosEntity/Service/TransactionItemService.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TinyPosEntity.Entity; + +namespace TinyPosEntity.Service +{ + public class TransactionItemService + { + static TransactionItemService instance; + public static TransactionItemService Instance { get { Init(); return instance; } } + + private static void Init() + { + if (instance == null) + instance = new TransactionItemService(); + } + + public void Create(TransactionItem targetObject) + { + using (EntityContext context = new EntityContext()) + { + context.TransactionItems.Add(targetObject); + context.SaveChanges(); + } + } + + public void Create(List targetObject) + { + using (EntityContext context = new EntityContext()) + { + foreach (TransactionItem type in targetObject) + { + context.TransactionItems.Add(type); + } + + context.SaveChanges(); + } + } + + public List Find(DateTime fromDateTime, DateTime toDateTime) + { + using (EntityContext context = new EntityContext()) + { + var qry = from ti in context.TransactionItems + join t in context.Transactions + on ti.Transaction equals t + where (t.Timestamp >= fromDateTime && t.Timestamp <= toDateTime) + orderby t.Timestamp descending + select ti; + + if (qry.Count() < 1) + return null; + + return qry.ToList(); + } + } + } +} diff --git a/TinyPOS/TinyPosEntity/Service/TransactionService.cs b/TinyPOS/TinyPosEntity/Service/TransactionService.cs new file mode 100644 index 0000000..f3ebd7b --- /dev/null +++ b/TinyPOS/TinyPosEntity/Service/TransactionService.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TinyPosEntity.Entity; + +namespace TinyPosEntity.Service +{ + public class TransactionService + { + static TransactionService instance; + public static TransactionService Instance { get { Init(); return instance; } } + + private static void Init() + { + if (instance == null) + instance = new TransactionService(); + } + + public void Create(Transaction targetObject) + { + using (EntityContext context = new EntityContext()) + { + context.Transactions.Add(targetObject); + context.SaveChanges(); + } + } + + public void Create(List targetObject) + { + using (EntityContext context = new EntityContext()) + { + foreach (Transaction type in targetObject) + { + context.Transactions.Add(type); + } + + context.SaveChanges(); + } + } + + public List Find(DateTime fromDateTime, DateTime toDateTime) + { + using (EntityContext context = new EntityContext()) + { + var qry = from t in context.Transactions + where (t.Timestamp >= fromDateTime && t.Timestamp <= toDateTime) + orderby t.Timestamp descending + select t; + + if (qry.Count() < 1) + return null; + + return qry.ToList(); + } + } + } +}