save label in db;
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace DataAccessLibrary {
|
||||
public class Class1 {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.8" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Data.Sqlite;
|
||||
|
||||
namespace DataAccessLibrary.Service {
|
||||
public class LabelService {
|
||||
public static void InitializeDatabase() {
|
||||
using (SqliteConnection db =
|
||||
new SqliteConnection("Filename=awesomefilemanager.db")) {
|
||||
db.Open();
|
||||
|
||||
String tableCommand = "CREATE TABLE IF NOT " +
|
||||
"EXISTS Labels (id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
"Path NVARCHAR(2048) NOT NULL, LABEL NVARCHAR(2048) NOT NULL)";
|
||||
|
||||
SqliteCommand createTable = new SqliteCommand(tableCommand, db);
|
||||
|
||||
createTable.ExecuteReader();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddLabel(string path, string label) {
|
||||
using (SqliteConnection db =
|
||||
new SqliteConnection("Filename=awesomefilemanager.db")) {
|
||||
db.Open();
|
||||
|
||||
SqliteCommand insertCommand = new SqliteCommand();
|
||||
insertCommand.Connection = db;
|
||||
|
||||
// Use parameterized query to prevent SQL injection attacks
|
||||
insertCommand.CommandText = "INSERT INTO Labels (Path, LABEL) VALUES (@Path, @Label);";
|
||||
insertCommand.Parameters.AddWithValue("@Path", path);
|
||||
insertCommand.Parameters.AddWithValue("@Label", label);
|
||||
|
||||
insertCommand.ExecuteReader();
|
||||
|
||||
db.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> GetLabels(string path) {
|
||||
List<String> entries = new List<string>();
|
||||
|
||||
using (SqliteConnection db =
|
||||
new SqliteConnection("Filename=awesomefilemanager.db")) {
|
||||
db.Open();
|
||||
|
||||
SqliteCommand selectCommand = new SqliteCommand
|
||||
("SELECT LABEL from Labels where path=@Path", db);
|
||||
selectCommand.Parameters.AddWithValue("@Path", path);
|
||||
|
||||
SqliteDataReader query = selectCommand.ExecuteReader();
|
||||
|
||||
while (query.Read()) {
|
||||
entries.Add(query.GetString(0));
|
||||
}
|
||||
db.Close();
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
public static void RemoveLabel(string path, string label) {
|
||||
List<String> entries = new List<string>();
|
||||
|
||||
using (SqliteConnection db =
|
||||
new SqliteConnection("Filename=awesomefilemanager.db")) {
|
||||
db.Open();
|
||||
|
||||
SqliteCommand removeCommand = new SqliteCommand
|
||||
("DELETE from Labels where path=@Path and label=@Label", db);
|
||||
removeCommand.Parameters.AddWithValue("@Path", path);
|
||||
removeCommand.Parameters.AddWithValue("@Label", label);
|
||||
|
||||
SqliteDataReader query = removeCommand.ExecuteReader();
|
||||
|
||||
db.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
-2
@@ -1,22 +1,30 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.489
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28803.202
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileManager_UWP", "FileManager_UWP\FileManager_UWP.csproj", "{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D} = {FAA7FCD7-5380-436C-A615-8612D798224D}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccessLibrary", "DataAccessLibrary\DataAccessLibrary.csproj", "{FAA7FCD7-5380-436C-A615-8612D798224D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|ARM = Debug|ARM
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|ARM = Release|ARM
|
||||
Release|ARM64 = Release|ARM64
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||
@@ -29,6 +37,7 @@ Global
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|x86.Build.0 = Debug|x86
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|ARM.Build.0 = Release|ARM
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|ARM.Deploy.0 = Release|ARM
|
||||
@@ -41,6 +50,26 @@ Global
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|x86.ActiveCfg = Release|x86
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|x86.Build.0 = Release|x86
|
||||
{2157CE8F-BEE7-4469-8FBD-63F8E50BE6D6}.Release|x86.Deploy.0 = Release|x86
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|x64.Build.0 = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FAA7FCD7-5380-436C-A615-8612D798224D}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -235,7 +235,12 @@
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataAccessLibrary\DataAccessLibrary.csproj">
|
||||
<Project>{faa7fcd7-5380-436c-a615-8612d798224d}</Project>
|
||||
<Name>DataAccessLibrary</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DataAccessLibrary.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -14,10 +15,12 @@ namespace FileManager_UWP.Model
|
||||
public class DisplayableDisk: Displayable {
|
||||
private readonly DriveInfo _drive;
|
||||
private readonly BitmapImage _icon = new BitmapImage();
|
||||
private readonly List<LabelItem> _labels = new List<LabelItem>();
|
||||
private readonly List<LabelItem> _labels;
|
||||
|
||||
private DisplayableDisk(DriveInfo d) {
|
||||
_drive = d;
|
||||
_labels = LabelService.GetLabels(d.Name).Select((x) => new LabelItem(x)).ToList();
|
||||
|
||||
}
|
||||
|
||||
public static async Task<DisplayableDisk> GetInstance(DriveInfo d) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DataAccessLibrary.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -17,7 +18,7 @@ namespace FileManager_UWP.Model
|
||||
private DisplayableFile(StorageFile f) {
|
||||
_file = f;
|
||||
_icon = new BitmapImage();
|
||||
_labels = new List<LabelItem> { new LabelItem("喵喵喵") };
|
||||
_labels = LabelService.GetLabels(f.Path).Select((x) => new LabelItem(x)).ToList();
|
||||
}
|
||||
|
||||
public static async Task<DisplayableFile> GetInstanceAsync(StorageFile f) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DataAccessLibrary.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -17,7 +18,7 @@ namespace FileManager_UWP.Model
|
||||
private DisplayableFolder(StorageFolder f) {
|
||||
_folder = f;
|
||||
_icon = new BitmapImage();
|
||||
_labels = new List<LabelItem>();
|
||||
_labels = LabelService.GetLabels(f.Path).Select((x) => new LabelItem(x)).ToList();
|
||||
}
|
||||
|
||||
public static async Task<DisplayableFolder> GetInstanceAsync(StorageFolder f)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DataAccessLibrary.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -14,7 +15,7 @@ namespace FileManager_UWP.Model
|
||||
Path = path;
|
||||
Type = type;
|
||||
Icon = icon;
|
||||
Labels = new List<LabelItem>();
|
||||
Labels = LabelService.GetLabels(Path).Select((x) => new LabelItem(x)).ToList();
|
||||
}
|
||||
public override string Name { get; }
|
||||
public override string Path { get; }
|
||||
|
||||
@@ -10,7 +10,9 @@ using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using DataAccessLibrary;
|
||||
using Type = FileManager_UWP.Model.Type;
|
||||
using DataAccessLibrary.Service;
|
||||
|
||||
namespace FileManager_UWP.ViewModel {
|
||||
public class FileListViewModel: ViewModelBase {
|
||||
@@ -18,15 +20,6 @@ namespace FileManager_UWP.ViewModel {
|
||||
public FileListViewModel() {
|
||||
SimpleIoc.Default.Register<FileService>();
|
||||
}
|
||||
public ObservableCollection<LabelItem> Labels =
|
||||
new ObservableCollection<LabelItem>{
|
||||
new LabelItem("照片"),
|
||||
new LabelItem("土耳其摔跤"),
|
||||
new LabelItem("李若明"),
|
||||
new LabelItem("鸢晓曼"),
|
||||
new LabelItem("才明洋与吴岳江进行土耳其摔跤"),
|
||||
new LabelItem("真正的瑜伽大师")
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 当前路径
|
||||
@@ -101,6 +94,8 @@ namespace FileManager_UWP.ViewModel {
|
||||
_doubleTappedCommand ?? (_doubleTappedCommand = new RelayCommand(
|
||||
() => {
|
||||
StackPanel sp = ListSelectedItem as StackPanel;
|
||||
if (sp == null)
|
||||
return;
|
||||
Displayable i = sp.GetValue(StackPanel.TagProperty) as Displayable;
|
||||
//Displayable i = ListSelectedItem as Displayable;
|
||||
Debug.WriteLine("Double tapped");
|
||||
@@ -116,6 +111,8 @@ namespace FileManager_UWP.ViewModel {
|
||||
() => {
|
||||
PreviewViewModel pvm = SimpleIoc.Default.GetInstance<PreviewViewModel>();
|
||||
StackPanel sp = ListSelectedItem as StackPanel;
|
||||
if (sp == null)
|
||||
return;
|
||||
Displayable i = sp.GetValue(StackPanel.TagProperty) as Displayable;
|
||||
// pvm.Path = i.Path;
|
||||
pvm.ShowPreviewCommand.Execute(i.Path);
|
||||
@@ -129,6 +126,7 @@ namespace FileManager_UWP.ViewModel {
|
||||
string path = e.LabelListControl.GetValue(LabelListControl.TagProperty) as string;
|
||||
LabelItem label = e.label;
|
||||
Debug.WriteLine("remove " + path + " " + label.tag);
|
||||
LabelService.RemoveLabel(path, label.tag);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -140,6 +138,8 @@ namespace FileManager_UWP.ViewModel {
|
||||
string path = e.LabelListControl.GetValue(LabelListControl.TagProperty) as string;
|
||||
LabelItem label = e.label;
|
||||
Debug.WriteLine("add " + path + " " + label.tag);
|
||||
if (path != "" && label.tag != "")
|
||||
LabelService.AddLabel(path, label.tag);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CommonServiceLocator;
|
||||
using DataAccessLibrary.Service;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,10 +12,13 @@ namespace FileManager_UWP.ViewModel {
|
||||
public FileListViewModel FileListViewModel => ServiceLocator.Current.GetInstance<FileListViewModel>();
|
||||
public MainPageViewModel MainPageViewModel => ServiceLocator.Current.GetInstance<MainPageViewModel>();
|
||||
public PreviewViewModel PreviewViewModel => ServiceLocator.Current.GetInstance<PreviewViewModel>();
|
||||
// public LabelService LabelService => ServiceLocator.Current.GetInstance<LabelService>();
|
||||
|
||||
public ViewModelLocator() {
|
||||
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
|
||||
|
||||
LabelService.InitializeDatabase();
|
||||
|
||||
SimpleIoc.Default.Register<FileListViewModel>();
|
||||
SimpleIoc.Default.Register<MainPageViewModel>();
|
||||
SimpleIoc.Default.Register<PreviewViewModel>();
|
||||
|
||||
Reference in New Issue
Block a user