终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

291 строка
8.7 KiB

  1. using BPASmartClient.MorkCL.Model.DB;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace BPASmartClient.MorkCL.Server
  11. {
  12. internal class SqliteHelper : ISqlite
  13. {
  14. private volatile static SqliteHelper _Instance;
  15. public static SqliteHelper GetInstance => _Instance ?? (_Instance = new SqliteHelper());
  16. private SqliteHelper() { }
  17. static string path
  18. {
  19. get
  20. {
  21. Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory);
  22. return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\DB\\Material.db");
  23. }
  24. }
  25. public SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
  26. {
  27. ConnectionString = $"Data Source={path}",
  28. DbType = DbType.Sqlite,
  29. IsAutoCloseConnection = true,//设置自动关闭连接
  30. });
  31. /// <summary>
  32. /// 初始化
  33. /// </summary>
  34. public void Init()
  35. {
  36. try
  37. {
  38. if (!File.Exists(path))
  39. {
  40. //创建数据库
  41. Db.DbMaintenance.CreateDatabase();
  42. //创建数据表
  43. string spnaName = "BPASmartClient.MorkCL.Model.DB";//实体类的命名空间
  44. Type[] ass = Assembly.LoadFrom(AppContext.BaseDirectory + "BPASmartClient.MorkCL.dll").GetTypes().Where(p => p.Namespace == spnaName).ToArray();
  45. Db.CodeFirst.SetStringDefaultLength(200).InitTables(ass);
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. MessageLog.GetInstance.ShowEx(ex.ToString());
  51. }
  52. }
  53. #region 主料数据操作
  54. /// <summary>
  55. /// 添加主料
  56. /// </summary>
  57. /// <param name="mb"></param>
  58. /// <returns></returns>
  59. public bool AddIngredients(IngredientsTB mb)
  60. {
  61. IngredientsTB tempMB = new IngredientsTB()
  62. {
  63. Id = Guid.NewGuid().ToString(),
  64. Name = mb.Name,
  65. Description = mb.Description,
  66. Loc = mb.Loc,
  67. };
  68. if (Db.Queryable<IngredientsTB>().Any(p => p.Name == mb.Name)) return false;
  69. return Db.Insertable(tempMB).ExecuteCommand() > 0;
  70. }
  71. /// <summary>
  72. /// 编辑主料
  73. /// </summary>
  74. /// <param name="req"></param>
  75. /// <returns></returns>
  76. public bool EditIngredients(IngredientsTB req)
  77. {
  78. IngredientsTB tempMB = Db.Queryable<IngredientsTB>().First(p => p.Id == req.Id);
  79. if (tempMB == null) return false;
  80. tempMB.Name = req.Name;
  81. tempMB.Loc = req.Loc;
  82. tempMB.Description = req.Description;
  83. return Db.Updateable(tempMB).ExecuteCommand() > 0;
  84. }
  85. /// <summary>
  86. /// 删除主料
  87. /// </summary>
  88. /// <param name="id"></param>
  89. /// <returns></returns>
  90. public bool DelIngredients(string id)
  91. {
  92. return Db.Ado.ExecuteCommand($"DELETE From [IngredientsTB] WHERE Id='{id}'") > 0;
  93. }
  94. /// <summary>
  95. /// 获取所有主料
  96. /// </summary>
  97. /// <returns></returns>
  98. public List<IngredientsTB> GetIngredients()
  99. {
  100. return Db.Queryable<IngredientsTB>().ToList();
  101. }
  102. /// <summary>
  103. /// 获取指定主料信息
  104. /// </summary>
  105. /// <param name="id"></param>
  106. /// <returns></returns>
  107. public IngredientsTB GetIngredientsInfo(string id)
  108. {
  109. return Db.Queryable<IngredientsTB>().First(p => p.Id == id);
  110. }
  111. /// <summary>
  112. /// 查询指定位置是否占用。
  113. /// </summary>
  114. /// <param name="loc"></param>
  115. /// <returns></returns>
  116. public bool GetIngredientsInfoByLoc(int loc)
  117. {
  118. return Db.Queryable<IngredientsTB>().Any(p => p.Loc == loc);
  119. }
  120. #endregion
  121. #region 辅料数据操作
  122. /// <summary>
  123. /// 添加辅料
  124. /// </summary>
  125. /// <param name="mb"></param>
  126. /// <returns></returns>
  127. public bool AddAccessories(AccessoriesTB mb)
  128. {
  129. AccessoriesTB tempMB = new AccessoriesTB()
  130. {
  131. Id = Guid.NewGuid().ToString(),
  132. Name = mb.Name,
  133. Description = mb.Description,
  134. Loc = mb.Loc,
  135. };
  136. if (Db.Queryable<AccessoriesTB>().Any(p => p.Name == mb.Name)) return false;
  137. return Db.Insertable(tempMB).ExecuteCommand() > 0;
  138. }
  139. /// <summary>
  140. /// 编辑辅料
  141. /// </summary>
  142. /// <param name="req"></param>
  143. /// <returns></returns>
  144. public bool EditAccessories(AccessoriesTB req)
  145. {
  146. AccessoriesTB tempMB = Db.Queryable<AccessoriesTB>().First(p => p.Id == req.Id);
  147. if (tempMB == null) return false;
  148. tempMB.Name = req.Name;
  149. tempMB.Loc = req.Loc;
  150. tempMB.Description = req.Description;
  151. return Db.Updateable(tempMB).ExecuteCommand() > 0;
  152. }
  153. /// <summary>
  154. /// 删除辅料
  155. /// </summary>
  156. /// <param name="id"></param>
  157. /// <returns></returns>
  158. public bool DelAccessories(string id)
  159. {
  160. return Db.Ado.ExecuteCommand($"DELETE From [AccessoriesTB] WHERE Id='{id}'") > 0;
  161. }
  162. /// <summary>
  163. /// 获取所有辅料
  164. /// </summary>
  165. /// <returns></returns>
  166. public List<AccessoriesTB> GetAccessories()
  167. {
  168. return Db.Queryable<AccessoriesTB>().ToList();
  169. }
  170. /// <summary>
  171. /// 获取指定的辅料
  172. /// </summary>
  173. /// <param name="id"></param>
  174. /// <returns></returns>
  175. public AccessoriesTB GetAccessoriesInfo(string id)
  176. {
  177. return Db.Queryable<AccessoriesTB>().First(p => p.Id == id);
  178. }
  179. /// <summary>
  180. /// 查询指定位置是否占用。
  181. /// </summary>
  182. /// <param name="loc"></param>
  183. /// <returns></returns>
  184. public bool GetAccessoriesInfoByLoc(int loc)
  185. {
  186. return Db.Queryable<AccessoriesTB>().Any(p => p.Loc == loc);
  187. }
  188. #endregion
  189. #region 调料数据操作
  190. /// <summary>
  191. /// 添加调料
  192. /// </summary>
  193. /// <param name="mb"></param>
  194. /// <returns></returns>
  195. public bool AddSeasoning(SeasoningTB mb)
  196. {
  197. SeasoningTB tempMB = new SeasoningTB()
  198. {
  199. Id = Guid.NewGuid().ToString(),
  200. Name = mb.Name,
  201. Description = mb.Description,
  202. Loc = mb.Loc,
  203. };
  204. if (Db.Queryable<SeasoningTB>().Any(p => p.Name == mb.Name)) return false;
  205. return Db.Insertable(tempMB).ExecuteCommand() > 0;
  206. }
  207. /// <summary>
  208. /// 编辑调料
  209. /// </summary>
  210. /// <param name="req"></param>
  211. /// <returns></returns>
  212. public bool EditSeasoning(SeasoningTB req)
  213. {
  214. SeasoningTB tempMB = Db.Queryable<SeasoningTB>().First(p => p.Id == req.Id);
  215. if (tempMB == null) return false;
  216. tempMB.Name = req.Name;
  217. tempMB.Loc = req.Loc;
  218. tempMB.Description = req.Description;
  219. return Db.Updateable(tempMB).ExecuteCommand() > 0;
  220. }
  221. /// <summary>
  222. /// 删除调料
  223. /// </summary>
  224. /// <param name="id"></param>
  225. /// <returns></returns>
  226. public bool DelSeasoning(string id)
  227. {
  228. return Db.Ado.ExecuteCommand($"DELETE From [SeasoningTB] WHERE Id='{id}'") > 0;
  229. }
  230. /// <summary>
  231. /// 获取所有调料
  232. /// </summary>
  233. /// <returns></returns>
  234. public List<SeasoningTB> GetSeasoning()
  235. {
  236. return Db.Queryable<SeasoningTB>().ToList();
  237. }
  238. /// <summary>
  239. /// 获取指定的调料信息
  240. /// </summary>
  241. /// <param name="id"></param>
  242. /// <returns></returns>
  243. public SeasoningTB GetSeasoningInfo(string id)
  244. {
  245. return Db.Queryable<SeasoningTB>().First(p => p.Id == id);
  246. }
  247. /// <summary>
  248. /// 查询指定位置是否占用。
  249. /// </summary>
  250. /// <param name="loc"></param>
  251. /// <returns></returns>
  252. public bool GetSeasoningInfoByLoc(int loc)
  253. {
  254. return Db.Queryable<SeasoningTB>().Any(p => p.Loc == loc);
  255. }
  256. #endregion
  257. }
  258. }