Bläddra i källkod

SQLITE修改

样式分支
pry 2 år sedan
förälder
incheckning
03e67bd614
10 ändrade filer med 95 tillägg och 30 borttagningar
  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 Visa fil

@@ -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 Visa fil


BPASmart.Model/FileConfigModel.cs → BPASmart.Model/Config/FileConfigModel.cs Visa fil


BPASmart.Model/GlobalVar.cs → BPASmart.Model/Config/GlobalVar.cs Visa fil


BPASmart.Model/LocalPar.cs → BPASmart.Model/Config/LocalPar.cs Visa fil


BPASmart.Model/ProjectModel.cs → BPASmart.Model/Config/ProjectModel.cs Visa fil


+ 19
- 0
BPASmart.Model/IRecipeMaterials.cs Visa fil

@@ -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 Visa fil

@@ -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 Visa fil

@@ -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 Visa fil

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

Laddar…
Avbryt
Spara