|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.Academy.Model
- {
- public class Sqlite
- {
- private static Sqlite instance;
- public static Sqlite GetInstance { get; set; } = instance ??= new Sqlite();
- private Sqlite() { }
- public List<SaveData> saveDatas { get; set; } = new List<SaveData>();
- static string path
- {
- get
- {
- Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory);
- return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\DB\\data.db");
- }
- }
- public SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
- {
- ConnectionString = $"Data Source = {path}",
- DbType = DbType.Sqlite,
- IsAutoCloseConnection = true,
-
- });
-
- public void Init()
- {
- try
- {
- if (!File.Exists(path))
- {
- Db.DbMaintenance.CreateDatabase();
- Db.CodeFirst.SetStringDefaultLength(100).InitTables<SaveData>();
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog("创建失败");
- }
- }
- catch (Exception)
- {
-
- throw;
- }
- }
- public bool AddData(SaveData dfb)
- {
- try
- {
- return Db.Insertable(dfb).ExecuteCommand() > 0;
- }
- catch (Exception)
- {
- return false;
- }
- }
- public List<SaveData> SelectId(string id)
- {
- try
- {
- return Db.Queryable<SaveData>().Where(o => o.Id == id).ToList();
- }
- catch (Exception)
- {
- return null;
- }
- }
- public List<String> SelectAllName()
- {
- return Db.Queryable<SaveData>()
- .Select(x => x.Name)
- .Distinct()
- .ToList();
- }
-
- }
- }
|