|
|
|
@ -4,8 +4,6 @@ using System.Data.Entity; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Text; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using TinyPosEntity.Entity; |
|
|
|
|
using TinyPosEntity.Service; |
|
|
|
|
|
|
|
|
|
namespace TinyPosEntity |
|
|
|
|
{ |
|
|
|
@ -14,23 +12,24 @@ namespace TinyPosEntity |
|
|
|
|
public static string ConnectionString { get; set; } |
|
|
|
|
|
|
|
|
|
private static EntityController instance; |
|
|
|
|
public static EntityController Instance { get { Init(); return instance; } } |
|
|
|
|
|
|
|
|
|
private EntityController(string connectionString) |
|
|
|
|
{ |
|
|
|
|
EntityContext.ConnectionString = connectionString; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void Init() |
|
|
|
|
public static EntityController GetInstance() |
|
|
|
|
{ |
|
|
|
|
if (string.IsNullOrEmpty(ConnectionString)) |
|
|
|
|
throw new Exception("ConnectionString 값이 필요합니다."); |
|
|
|
|
|
|
|
|
|
if (instance == null) |
|
|
|
|
instance = new EntityController(ConnectionString); |
|
|
|
|
|
|
|
|
|
return instance; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void InitializeDatabase() |
|
|
|
|
public void Initialize() |
|
|
|
|
{ |
|
|
|
|
Database.SetInitializer<EntityContext>(new EntityInitializer()); |
|
|
|
|
|
|
|
|
@ -39,21 +38,94 @@ namespace TinyPosEntity |
|
|
|
|
context.Database.CreateIfNotExists(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ProductTypeService.Instance.Create(GetDefaultProductTypes()); |
|
|
|
|
|
|
|
|
|
AddProductType(GetDefaultProductTypes()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<ProductType> GetDefaultProductTypes() |
|
|
|
|
{ |
|
|
|
|
List<ProductType> productTypeList = new List<ProductType>(); |
|
|
|
|
productTypeList.Add(new ProductType() { Name = "담배" }); |
|
|
|
|
productTypeList.Add(new ProductType() { Name = "주류" }); |
|
|
|
|
productTypeList.Add(new ProductType() { Name = "음료" }); |
|
|
|
|
productTypeList.Add(new ProductType() { Name = "과자" }); |
|
|
|
|
productTypeList.Add(new ProductType() { Name = "식료품" }); |
|
|
|
|
productTypeList.Add(new ProductType() { Name = "잡화" }); |
|
|
|
|
productTypeList.Add(new ProductType() { Name = "기타" }); |
|
|
|
|
productTypeList.Add(new ProductType() |
|
|
|
|
{ |
|
|
|
|
Name = "담배" |
|
|
|
|
}); |
|
|
|
|
productTypeList.Add(new ProductType() |
|
|
|
|
{ |
|
|
|
|
Name = "주류" |
|
|
|
|
}); |
|
|
|
|
productTypeList.Add(new ProductType() |
|
|
|
|
{ |
|
|
|
|
Name = "음료" |
|
|
|
|
}); |
|
|
|
|
productTypeList.Add(new ProductType() |
|
|
|
|
{ |
|
|
|
|
Name = "생필품" |
|
|
|
|
}); |
|
|
|
|
productTypeList.Add(new ProductType() |
|
|
|
|
{ |
|
|
|
|
Name = "과자" |
|
|
|
|
}); |
|
|
|
|
productTypeList.Add(new ProductType() |
|
|
|
|
{ |
|
|
|
|
Name = "기타" |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return productTypeList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void AddProductType(ProductType type) |
|
|
|
|
{ |
|
|
|
|
using (EntityContext context = new EntityContext()) |
|
|
|
|
{ |
|
|
|
|
context.ProductTypes.Add(type); |
|
|
|
|
context.SaveChanges(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void AddProductType(List<ProductType> types) |
|
|
|
|
{ |
|
|
|
|
using (EntityContext context = new EntityContext()) |
|
|
|
|
{ |
|
|
|
|
foreach (ProductType type in types) |
|
|
|
|
{ |
|
|
|
|
context.ProductTypes.Add(type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
context.SaveChanges(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//public void AddStudent(Student student) |
|
|
|
|
//{ |
|
|
|
|
// using (EntityContext context = new EntityContext()) |
|
|
|
|
// { |
|
|
|
|
// context.Students.Add(student); |
|
|
|
|
// context.SaveChanges(); |
|
|
|
|
// } |
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
//public List<Student> FindStudent(string name) |
|
|
|
|
//{ |
|
|
|
|
// List<Student> result = null; |
|
|
|
|
// using (EntityContext context = new EntityContext()) |
|
|
|
|
// { |
|
|
|
|
// var student = from s in context.Students |
|
|
|
|
// where s.StudentName.Equals(name) |
|
|
|
|
// select s; |
|
|
|
|
|
|
|
|
|
// if (student.Count() > 0) |
|
|
|
|
// result = student.ToList(); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// return result; |
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
//public void RemoveStudent(Student student) |
|
|
|
|
//{ |
|
|
|
|
// using (EntityContext context = new EntityContext()) |
|
|
|
|
// { |
|
|
|
|
// context.Database.ExecuteSqlCommand("DELETE FROM dbo.Students WHERE StudentName = {0}", student.StudentName); |
|
|
|
|
// } |
|
|
|
|
//} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|