Selaa lähdekoodia

SQLITE修改

样式分支
pry 2 vuotta sitten
vanhempi
commit
03e67bd614
10 muutettua tiedostoa jossa 95 lisäystä ja 30 poistoa
  1. +1
    -0
      BPASmart.Model/BPASmart.Model.csproj
  2. +0
    -0
      BPASmart.Model/Config/BinConfigFile.cs
  3. +0
    -0
      BPASmart.Model/Config/FileConfigModel.cs
  4. +0
    -0
      BPASmart.Model/Config/GlobalVar.cs
  5. +0
    -0
      BPASmart.Model/Config/LocalPar.cs
  6. +0
    -0
      BPASmart.Model/Config/ProjectModel.cs
  7. +19
    -0
      BPASmart.Model/IRecipeMaterials.cs
  8. +3
    -0
      BPASmart.Model/配方/RecipeMaterials.cs
  9. +72
    -0
      BPASmart.Server/SqliteContext.cs
  10. +0
    -30
      BPASmart.Server/SqliteHelper.cs

+ 1
- 0
BPASmart.Model/BPASmart.Model.csproj Näytä tiedosto

@@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.9" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.IO.Ports" Version="6.0.0" />


BPASmart.Model/BinConfigFile.cs → BPASmart.Model/Config/BinConfigFile.cs Näytä tiedosto


BPASmart.Model/FileConfigModel.cs → BPASmart.Model/Config/FileConfigModel.cs Näytä tiedosto


BPASmart.Model/GlobalVar.cs → BPASmart.Model/Config/GlobalVar.cs Näytä tiedosto


BPASmart.Model/LocalPar.cs → BPASmart.Model/Config/LocalPar.cs Näytä tiedosto


BPASmart.Model/ProjectModel.cs → BPASmart.Model/Config/ProjectModel.cs Näytä tiedosto


+ 19
- 0
BPASmart.Model/IRecipeMaterials.cs Näytä tiedosto

@@ -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<bool> AddAsync(RecipeMaterials recipeMaterials);
Task<bool> AddRangeAsync(RecipeMaterials[] recipeMaterials);
Task<bool> UpdateAsync(RecipeMaterials recipeMaterials);
Task<bool> DeleteAsync(string ID);
Task<List<RecipeMaterials>> GetData();
}
}

+ 3
- 0
BPASmart.Model/配方/RecipeMaterials.cs Näytä tiedosto

@@ -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
/// <summary>
/// 物料重量
/// </summary>
[NotMapped]
public int MaterialWeight { get { return _materialWeight; } set { _materialWeight = value; OnPropertyChanged(); } }
private int _materialWeight;
/// <summary>
@@ -39,6 +41,7 @@ namespace BPASmart.Model
/// <summary>
/// 自定义原料属性集合
/// </summary>
[NotMapped]
public ObservableCollection<Property> PropertyCollections = new ObservableCollection<Property>();
}



+ 72
- 0
BPASmart.Server/SqliteContext.cs Näytä tiedosto

@@ -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<RecipeMaterials> RecipeMaterialsS { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite($"FileName={path}");
}

public async Task<bool> AddAsync(RecipeMaterials recipeMaterials)
{
Database.EnsureCreated();
await RecipeMaterialsS.AddAsync(recipeMaterials);
return await SaveChangesAsync() > 1;
}

public async Task<bool> AddRangeAsync(RecipeMaterials[] recipeMaterials)
{
Database.EnsureCreated();
await RecipeMaterialsS.AddRangeAsync(recipeMaterials);
return await SaveChangesAsync() > 1;
}

public async Task<bool> UpdateAsync(RecipeMaterials recipeMaterials)
{
Database.EnsureCreated();
RecipeMaterialsS.Update(recipeMaterials);
return await SaveChangesAsync() > 1;
}

public async Task<bool> DeleteAsync(string ID)
{
Database.EnsureCreated();
RecipeMaterialsS.Remove(RecipeMaterialsS.FirstOrDefault(p => p.ID == ID));
return await SaveChangesAsync() > 1;
}

public async Task<List<RecipeMaterials>> GetData()
{
return await Task.Factory.StartNew(new Func<List<RecipeMaterials>>(() =>
{
Database.EnsureCreated();
return RecipeMaterialsS.ToList();
}));
}
}
}

+ 0
- 30
BPASmart.Server/SqliteHelper.cs Näytä tiedosto

@@ -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}");
}
}
}

Ladataan…
Peruuta
Tallenna