sqllite接入,sqlsugar应用
parent
9c1bf77cef
commit
dd93c62d1d
|
|
@ -11,6 +11,7 @@ using HeBianGu.Service.Mvp;
|
|||
using HeBianGu.Systems.Identity;
|
||||
using HeBianGu.Systems.Setting;
|
||||
using Hopetry.Services;
|
||||
using SqlSugar;
|
||||
using SystemSetting = FileUploader.Models.SystemSetting;
|
||||
|
||||
namespace HeBianGu.App.Disk
|
||||
|
|
@ -89,6 +90,7 @@ namespace HeBianGu.App.Disk
|
|||
|
||||
#endregion
|
||||
|
||||
|
||||
#region - WindowCaption -
|
||||
|
||||
//以下各种功能按钮
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@
|
|||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="5.4.0" />
|
||||
<PackageReference Include="Polly" Version="8.5.2" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.187" />
|
||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
|
||||
<PackageReference Include="WindowsAPICodePack" Version="8.0.6" />
|
||||
<PackageReference Include="WPF-UI" Version="4.0.2" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hopetry.Models
|
||||
{
|
||||
[SugarTable("f_upload")]
|
||||
public class FUpload
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string FilePath { get; set; }
|
||||
|
||||
public string FileName { get; set; }
|
||||
|
||||
public long FileSize { get; set; }
|
||||
|
||||
public string FileType { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
public DateTime CompleteTime { get; set; }
|
||||
public bool IsComplete { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hopetry.Provider
|
||||
{
|
||||
public class SqlSugarConfig
|
||||
{
|
||||
public static SqlSugarScope GetSqlSugarScope()
|
||||
{
|
||||
return new SqlSugarScope(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = $"Data Source={GetDbPath()};Version=3;", // 数据库路径
|
||||
DbType = DbType.Sqlite, // 数据库类型
|
||||
IsAutoCloseConnection = true, // 自动释放
|
||||
InitKeyType = InitKeyType.Attribute // 从实体特性中读取主键信息
|
||||
},
|
||||
db =>
|
||||
{
|
||||
// 配置AOP
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql); // 输出SQL
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private static string GetDbPath()
|
||||
{
|
||||
// 这里假设数据库放在应用程序根目录下
|
||||
// 对于WPF项目,可以使用AppDomain.CurrentDomain.BaseDirectory获取基目录
|
||||
var basePath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
return Path.Combine(basePath, "minio.db");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
using Hopetry.Models;
|
||||
using Hopetry.Provider;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hopetry.Services
|
||||
{
|
||||
public class FileUploadService
|
||||
{
|
||||
private readonly SqlSugarScope _db;
|
||||
|
||||
public FileUploadService()
|
||||
{
|
||||
_db = SqlSugarConfig.GetSqlSugarScope();
|
||||
}
|
||||
|
||||
// 示例:查询所有文件信息
|
||||
public List<FUpload> GetAllFiles()
|
||||
{
|
||||
return _db.Queryable<FUpload>().ToList();
|
||||
}
|
||||
|
||||
// 示例:添加文件信息
|
||||
public bool AddFile(FUpload file)
|
||||
{
|
||||
return _db.Insertable(file).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
// 示例:更新文件信息
|
||||
public bool UpdateFile(FUpload file)
|
||||
{
|
||||
return _db.Updateable(file).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
// 示例:删除文件信息
|
||||
public bool DeleteFile(int id)
|
||||
{
|
||||
return _db.Deleteable<FUpload>().Where(f => f.Id == id).ExecuteCommand() > 0;
|
||||
}
|
||||
|
||||
// 检查数据库是否存在,不存在则创建
|
||||
public void InitDatabase()
|
||||
{
|
||||
_db.DbMaintenance.CreateDatabase(); // SQLite不需要创建数据库,但可以用于检查
|
||||
|
||||
// 如果表不存在则创建
|
||||
if (!_db.DbMaintenance.IsAnyTable("f_upload", false))
|
||||
{
|
||||
_db.CodeFirst.InitTables(typeof(FUpload));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ namespace HeBianGu.App.Disk
|
|||
internal class LoyoutViewModel : MvcViewModelBase
|
||||
{
|
||||
private string _path;
|
||||
private readonly FileUploadService _uploadService;
|
||||
/// <summary> 说明 </summary>
|
||||
public string Path
|
||||
{
|
||||
|
|
@ -368,9 +369,9 @@ namespace HeBianGu.App.Disk
|
|||
public LoyoutViewModel(SendViewModel sendViewModel)
|
||||
{
|
||||
_sendViewModel = sendViewModel;
|
||||
_uploadService = new FileUploadService();
|
||||
UploadCommand = new AsyncRelayCommand(async () => await UploadFile());
|
||||
UploadCommand1 = new AsyncRelayCommand(async () => await UploadFile1());
|
||||
|
||||
// 初始化Timer
|
||||
_progressTimer = new System.Timers.Timer(1000);
|
||||
_progressTimer.Elapsed += UpdateProgress;
|
||||
|
|
|
|||
Loading…
Reference in New Issue