diff --git a/BPASmart.Model/BPASmart.Model.csproj b/BPASmart.Model/BPASmart.Model.csproj index 92946c2e..30051f2e 100644 --- a/BPASmart.Model/BPASmart.Model.csproj +++ b/BPASmart.Model/BPASmart.Model.csproj @@ -7,6 +7,7 @@ + diff --git a/BPASmart.Model/BinConfigFile.cs b/BPASmart.Model/Config/BinConfigFile.cs similarity index 100% rename from BPASmart.Model/BinConfigFile.cs rename to BPASmart.Model/Config/BinConfigFile.cs diff --git a/BPASmart.Model/FileConfigModel.cs b/BPASmart.Model/Config/FileConfigModel.cs similarity index 100% rename from BPASmart.Model/FileConfigModel.cs rename to BPASmart.Model/Config/FileConfigModel.cs diff --git a/BPASmart.Model/GlobalVar.cs b/BPASmart.Model/Config/GlobalVar.cs similarity index 100% rename from BPASmart.Model/GlobalVar.cs rename to BPASmart.Model/Config/GlobalVar.cs diff --git a/BPASmart.Model/LocalPar.cs b/BPASmart.Model/Config/LocalPar.cs similarity index 100% rename from BPASmart.Model/LocalPar.cs rename to BPASmart.Model/Config/LocalPar.cs diff --git a/BPASmart.Model/ProjectModel.cs b/BPASmart.Model/Config/ProjectModel.cs similarity index 100% rename from BPASmart.Model/ProjectModel.cs rename to BPASmart.Model/Config/ProjectModel.cs diff --git a/BPASmart.Model/IRecipeMaterials.cs b/BPASmart.Model/IRecipeMaterials.cs new file mode 100644 index 00000000..6cb23f2c --- /dev/null +++ b/BPASmart.Model/IRecipeMaterials.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPASmart.Model; + +namespace BPASmart.Model +{ + public interface IRecipeMaterials + { + Task AddAsync(RecipeMaterials recipeMaterials); + Task AddRangeAsync(RecipeMaterials[] recipeMaterials); + Task UpdateAsync(RecipeMaterials recipeMaterials); + Task DeleteAsync(string ID); + Task> GetData(); + } +} diff --git a/BPASmart.Model/配方/RecipeMaterials.cs b/BPASmart.Model/配方/RecipeMaterials.cs index a50ce693..c7cdac30 100644 --- a/BPASmart.Model/配方/RecipeMaterials.cs +++ b/BPASmart.Model/配方/RecipeMaterials.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -28,6 +29,7 @@ namespace BPASmart.Model /// /// 物料重量 /// + [NotMapped] public int MaterialWeight { get { return _materialWeight; } set { _materialWeight = value; OnPropertyChanged(); } } private int _materialWeight; /// @@ -39,6 +41,7 @@ namespace BPASmart.Model /// /// 自定义原料属性集合 /// + [NotMapped] public ObservableCollection PropertyCollections = new ObservableCollection(); } diff --git a/BPASmart.Server/SqliteContext.cs b/BPASmart.Server/SqliteContext.cs new file mode 100644 index 00000000..bfb081d6 --- /dev/null +++ b/BPASmart.Server/SqliteContext.cs @@ -0,0 +1,72 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPASmart.Model; +using System.Collections.ObjectModel; + +namespace BPASmart.Server +{ + public class SqliteContext : DbContext, IRecipeMaterials + { + private volatile static SqliteContext _Instance; + public static SqliteContext GetInstance => _Instance ?? (_Instance = new SqliteContext()); + private SqliteContext() { } + + + string path + { + get + { + Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\DB")); + return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DB\\RecipeInfo.db"; + } + } + + public DbSet RecipeMaterialsS { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite($"FileName={path}"); + } + + public async Task AddAsync(RecipeMaterials recipeMaterials) + { + Database.EnsureCreated(); + await RecipeMaterialsS.AddAsync(recipeMaterials); + return await SaveChangesAsync() > 1; + } + + public async Task AddRangeAsync(RecipeMaterials[] recipeMaterials) + { + Database.EnsureCreated(); + await RecipeMaterialsS.AddRangeAsync(recipeMaterials); + return await SaveChangesAsync() > 1; + } + + public async Task UpdateAsync(RecipeMaterials recipeMaterials) + { + Database.EnsureCreated(); + RecipeMaterialsS.Update(recipeMaterials); + return await SaveChangesAsync() > 1; + } + + public async Task DeleteAsync(string ID) + { + Database.EnsureCreated(); + RecipeMaterialsS.Remove(RecipeMaterialsS.FirstOrDefault(p => p.ID == ID)); + return await SaveChangesAsync() > 1; + } + + public async Task> GetData() + { + return await Task.Factory.StartNew(new Func>(() => + { + Database.EnsureCreated(); + return RecipeMaterialsS.ToList(); + })); + } + } +} diff --git a/BPASmart.Server/SqliteHelper.cs b/BPASmart.Server/SqliteHelper.cs deleted file mode 100644 index 9c3f604a..00000000 --- a/BPASmart.Server/SqliteHelper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPASmart.Model; - -namespace BPASmart.Server -{ - public class SqliteHelper : DbContext - { - - string path - { - get - { - Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\DB")); - return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DB\\RecipeInfo.db"; - } - } - - //public DbSet<> - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlite($"FileName={path}"); - } - } -}