|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- using BPASmartClient.MorkCL.Model.DB;
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.MorkCL.Server
- {
- internal class SqliteHelper : ISqlite
- {
-
- private volatile static SqliteHelper _Instance;
- public static SqliteHelper GetInstance => _Instance ?? (_Instance = new SqliteHelper());
- private SqliteHelper() { }
-
- static string path
- {
- get
- {
- Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory);
- return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\DB\\Material.db");
- }
- }
-
- public SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
- {
- ConnectionString = $"Data Source={path}",
- DbType = DbType.Sqlite,
- IsAutoCloseConnection = true,//设置自动关闭连接
- });
-
- /// <summary>
- /// 初始化
- /// </summary>
- public void Init()
- {
- try
- {
- if (!File.Exists(path))
- {
- //创建数据库
- Db.DbMaintenance.CreateDatabase();
-
- //创建数据表
- string spnaName = "BPASmartClient.MorkCL.Model.DB";//实体类的命名空间
- Type[] ass = Assembly.LoadFrom(AppContext.BaseDirectory + "BPASmartClient.MorkCL.dll").GetTypes().Where(p => p.Namespace == spnaName).ToArray();
- Db.CodeFirst.SetStringDefaultLength(200).InitTables(ass);
- }
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- }
- }
-
- #region 主料数据操作
- /// <summary>
- /// 添加主料
- /// </summary>
- /// <param name="mb"></param>
- /// <returns></returns>
- public bool AddIngredients(IngredientsTB mb)
- {
- IngredientsTB tempMB = new IngredientsTB()
- {
- Id = Guid.NewGuid().ToString(),
- Name = mb.Name,
- Description = mb.Description,
- Loc = mb.Loc,
- };
- if (Db.Queryable<IngredientsTB>().Any(p => p.Name == mb.Name)) return false;
- return Db.Insertable(tempMB).ExecuteCommand() > 0;
- }
-
- /// <summary>
- /// 编辑主料
- /// </summary>
- /// <param name="req"></param>
- /// <returns></returns>
- public bool EditIngredients(IngredientsTB req)
- {
- IngredientsTB tempMB = Db.Queryable<IngredientsTB>().First(p => p.Id == req.Id);
- if (tempMB == null) return false;
- tempMB.Name = req.Name;
- tempMB.Loc = req.Loc;
- tempMB.Description = req.Description;
- return Db.Updateable(tempMB).ExecuteCommand() > 0;
- }
-
- /// <summary>
- /// 删除主料
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelIngredients(string id)
- {
- return Db.Ado.ExecuteCommand($"DELETE From [IngredientsTB] WHERE Id='{id}'") > 0;
- }
-
- /// <summary>
- /// 获取所有主料
- /// </summary>
- /// <returns></returns>
- public List<IngredientsTB> GetIngredients()
- {
- return Db.Queryable<IngredientsTB>().ToList();
- }
-
- /// <summary>
- /// 获取指定主料信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public IngredientsTB GetIngredientsInfo(string id)
- {
- return Db.Queryable<IngredientsTB>().First(p => p.Id == id);
- }
-
- /// <summary>
- /// 查询指定位置是否占用。
- /// </summary>
- /// <param name="loc"></param>
- /// <returns></returns>
- public bool GetIngredientsInfoByLoc(int loc)
- {
- return Db.Queryable<IngredientsTB>().Any(p => p.Loc == loc);
- }
-
- #endregion
-
-
- #region 辅料数据操作
- /// <summary>
- /// 添加辅料
- /// </summary>
- /// <param name="mb"></param>
- /// <returns></returns>
- public bool AddAccessories(AccessoriesTB mb)
- {
- AccessoriesTB tempMB = new AccessoriesTB()
- {
- Id = Guid.NewGuid().ToString(),
- Name = mb.Name,
- Description = mb.Description,
- Loc = mb.Loc,
- };
- if (Db.Queryable<AccessoriesTB>().Any(p => p.Name == mb.Name)) return false;
- return Db.Insertable(tempMB).ExecuteCommand() > 0;
- }
-
- /// <summary>
- /// 编辑辅料
- /// </summary>
- /// <param name="req"></param>
- /// <returns></returns>
- public bool EditAccessories(AccessoriesTB req)
- {
- AccessoriesTB tempMB = Db.Queryable<AccessoriesTB>().First(p => p.Id == req.Id);
- if (tempMB == null) return false;
- tempMB.Name = req.Name;
- tempMB.Loc = req.Loc;
- tempMB.Description = req.Description;
- return Db.Updateable(tempMB).ExecuteCommand() > 0;
- }
-
- /// <summary>
- /// 删除辅料
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelAccessories(string id)
- {
- return Db.Ado.ExecuteCommand($"DELETE From [AccessoriesTB] WHERE Id='{id}'") > 0;
- }
-
- /// <summary>
- /// 获取所有辅料
- /// </summary>
- /// <returns></returns>
- public List<AccessoriesTB> GetAccessories()
- {
- return Db.Queryable<AccessoriesTB>().ToList();
- }
-
- /// <summary>
- /// 获取指定的辅料
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public AccessoriesTB GetAccessoriesInfo(string id)
- {
- return Db.Queryable<AccessoriesTB>().First(p => p.Id == id);
- }
-
- /// <summary>
- /// 查询指定位置是否占用。
- /// </summary>
- /// <param name="loc"></param>
- /// <returns></returns>
- public bool GetAccessoriesInfoByLoc(int loc)
- {
- return Db.Queryable<AccessoriesTB>().Any(p => p.Loc == loc);
- }
-
- #endregion
-
- #region 调料数据操作
- /// <summary>
- /// 添加调料
- /// </summary>
- /// <param name="mb"></param>
- /// <returns></returns>
- public bool AddSeasoning(SeasoningTB mb)
- {
- SeasoningTB tempMB = new SeasoningTB()
- {
- Id = Guid.NewGuid().ToString(),
- Name = mb.Name,
- Description = mb.Description,
- Loc = mb.Loc,
- };
- if (Db.Queryable<SeasoningTB>().Any(p => p.Name == mb.Name)) return false;
- return Db.Insertable(tempMB).ExecuteCommand() > 0;
- }
-
- /// <summary>
- /// 编辑调料
- /// </summary>
- /// <param name="req"></param>
- /// <returns></returns>
- public bool EditSeasoning(SeasoningTB req)
- {
- SeasoningTB tempMB = Db.Queryable<SeasoningTB>().First(p => p.Id == req.Id);
- if (tempMB == null) return false;
- tempMB.Name = req.Name;
- tempMB.Loc = req.Loc;
- tempMB.Description = req.Description;
- return Db.Updateable(tempMB).ExecuteCommand() > 0;
- }
-
- /// <summary>
- /// 删除调料
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelSeasoning(string id)
- {
- return Db.Ado.ExecuteCommand($"DELETE From [SeasoningTB] WHERE Id='{id}'") > 0;
- }
-
- /// <summary>
- /// 获取所有调料
- /// </summary>
- /// <returns></returns>
- public List<SeasoningTB> GetSeasoning()
- {
- return Db.Queryable<SeasoningTB>().ToList();
- }
-
- /// <summary>
- /// 获取指定的调料信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public SeasoningTB GetSeasoningInfo(string id)
- {
- return Db.Queryable<SeasoningTB>().First(p => p.Id == id);
- }
-
- /// <summary>
- /// 查询指定位置是否占用。
- /// </summary>
- /// <param name="loc"></param>
- /// <returns></returns>
- public bool GetSeasoningInfoByLoc(int loc)
- {
- return Db.Queryable<SeasoningTB>().Any(p => p.Loc == loc);
- }
-
- #endregion
-
-
-
-
- }
- }
|