Explorar el Código

SQLITE修改

样式分支
pry hace 2 años
padre
commit
03e67bd614
Se han modificado 10 ficheros con 95 adiciones y 30 borrados
  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 Ver fichero

@@ -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 Ver fichero


BPASmart.Model/FileConfigModel.cs → BPASmart.Model/Config/FileConfigModel.cs Ver fichero


BPASmart.Model/GlobalVar.cs → BPASmart.Model/Config/GlobalVar.cs Ver fichero


BPASmart.Model/LocalPar.cs → BPASmart.Model/Config/LocalPar.cs Ver fichero


BPASmart.Model/ProjectModel.cs → BPASmart.Model/Config/ProjectModel.cs Ver fichero


+ 19
- 0
BPASmart.Model/IRecipeMaterials.cs Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

@@ -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 Ver fichero

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

Cargando…
Cancelar
Guardar