From 7357c86238c56c93db65d9d8a1e22b9ad58d246d Mon Sep 17 00:00:00 2001 From: Falcon <12919280+falconfly@user.noreply.gitee.com> Date: Thu, 13 Aug 2026 11:23:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=A1=E6=81=AF=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrivateBox/DataContext/CrytionItem.cs | 10 ++- PrivateBox/Forms/InputDlgBox.resx | 12 ++++ PrivateBox/Forms/MainForm.Designer.cs | 72 +++++++++++++++++++--- PrivateBox/Forms/MainForm.cs | 88 ++++++++++++++++++++++++++- 4 files changed, 171 insertions(+), 11 deletions(-) diff --git a/PrivateBox/DataContext/CrytionItem.cs b/PrivateBox/DataContext/CrytionItem.cs index e9d2a23..30612ff 100644 --- a/PrivateBox/DataContext/CrytionItem.cs +++ b/PrivateBox/DataContext/CrytionItem.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using SqlSugar; +using System.ComponentModel.DataAnnotations; namespace PrivateBox.DataContext { @@ -16,7 +17,12 @@ namespace PrivateBox.DataContext /// /// 加密项值 /// - [SqlSugar.SugarColumn(ColumnDataType = "text")] + [SugarColumn(ColumnDataType = "text")] public string? ItemValue { get; set; } + /// + /// 数据分组 + /// + [MaxLength(20)] + public string? Group { get; set; } = "未分组"; } } diff --git a/PrivateBox/Forms/InputDlgBox.resx b/PrivateBox/Forms/InputDlgBox.resx index a395bff..8e50c91 100644 --- a/PrivateBox/Forms/InputDlgBox.resx +++ b/PrivateBox/Forms/InputDlgBox.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/PrivateBox/Forms/MainForm.Designer.cs b/PrivateBox/Forms/MainForm.Designer.cs index 92bec9c..3a4ce13 100644 --- a/PrivateBox/Forms/MainForm.Designer.cs +++ b/PrivateBox/Forms/MainForm.Designer.cs @@ -29,21 +29,29 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); toolStripContainer1 = new ToolStripContainer(); splitContainer1 = new SplitContainer(); + splitContainer3 = new SplitContainer(); + clb_group = new CheckedListBox(); lbKeyList = new ListBox(); menuKeyList = new ContextMenuStrip(components); KeyListAddNew = new ToolStripMenuItem(); KeyListRemove = new ToolStripMenuItem(); + KeyListGroup = new ToolStripMenuItem(); splitContainer2 = new SplitContainer(); toolStrip1 = new ToolStrip(); btSave = new ToolStripButton(); btCancel = new ToolStripButton(); tbMessage = new RichTextBox(); + toolStripMenuItem1 = new ToolStripSeparator(); toolStripContainer1.ContentPanel.SuspendLayout(); toolStripContainer1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); splitContainer1.Panel1.SuspendLayout(); splitContainer1.Panel2.SuspendLayout(); splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)splitContainer3).BeginInit(); + splitContainer3.Panel1.SuspendLayout(); + splitContainer3.Panel2.SuspendLayout(); + splitContainer3.SuspendLayout(); menuKeyList.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)splitContainer2).BeginInit(); splitContainer2.Panel1.SuspendLayout(); @@ -74,7 +82,7 @@ // // splitContainer1.Panel1 // - splitContainer1.Panel1.Controls.Add(lbKeyList); + splitContainer1.Panel1.Controls.Add(splitContainer3); // // splitContainer1.Panel2 // @@ -83,6 +91,35 @@ splitContainer1.SplitterDistance = 285; splitContainer1.TabIndex = 0; // + // splitContainer3 + // + splitContainer3.Dock = DockStyle.Fill; + splitContainer3.Location = new Point(0,0); + splitContainer3.Name = "splitContainer3"; + splitContainer3.Orientation = Orientation.Horizontal; + // + // splitContainer3.Panel1 + // + splitContainer3.Panel1.Controls.Add(clb_group); + // + // splitContainer3.Panel2 + // + splitContainer3.Panel2.Controls.Add(lbKeyList); + splitContainer3.Size = new Size(285,379); + splitContainer3.SplitterDistance = 117; + splitContainer3.TabIndex = 2; + // + // clb_group + // + clb_group.Dock = DockStyle.Fill; + clb_group.FormattingEnabled = true; + clb_group.HorizontalScrollbar = true; + clb_group.Items.AddRange(new object[] { "未分组" }); + clb_group.Location = new Point(0,0); + clb_group.Name = "clb_group"; + clb_group.Size = new Size(285,117); + clb_group.TabIndex = 1; + // // lbKeyList // lbKeyList.ContextMenuStrip = menuKeyList; @@ -91,29 +128,36 @@ lbKeyList.ItemHeight = 17; lbKeyList.Location = new Point(0,0); lbKeyList.Name = "lbKeyList"; - lbKeyList.Size = new Size(285,379); + lbKeyList.Size = new Size(285,258); lbKeyList.TabIndex = 0; // // menuKeyList // - menuKeyList.Items.AddRange(new ToolStripItem[] { KeyListAddNew,KeyListRemove }); + menuKeyList.Items.AddRange(new ToolStripItem[] { KeyListAddNew,KeyListRemove,toolStripMenuItem1,KeyListGroup }); menuKeyList.Name = "menuKeyList"; - menuKeyList.Size = new Size(101,48); + menuKeyList.Size = new Size(181,98); // // KeyListAddNew // KeyListAddNew.Name = "KeyListAddNew"; - KeyListAddNew.Size = new Size(100,22); + KeyListAddNew.Size = new Size(180,22); KeyListAddNew.Text = "新增"; KeyListAddNew.Click += KeyListAddNew_Click; // // KeyListRemove // KeyListRemove.Name = "KeyListRemove"; - KeyListRemove.Size = new Size(100,22); + KeyListRemove.Size = new Size(180,22); KeyListRemove.Text = "删除"; KeyListRemove.Click += KeyListRemove_Click; // + // KeyListGroup + // + KeyListGroup.Name = "KeyListGroup"; + KeyListGroup.Size = new Size(180,22); + KeyListGroup.Text = "分组"; + KeyListGroup.Click += KeyListGroup_Click; + // // splitContainer2 // splitContainer2.Dock = DockStyle.Fill; @@ -172,6 +216,11 @@ tbMessage.TabIndex = 0; tbMessage.Text = "tbMessage"; // + // toolStripMenuItem1 + // + toolStripMenuItem1.Name = "toolStripMenuItem1"; + toolStripMenuItem1.Size = new Size(177,6); + // // MainForm // AutoScaleDimensions = new SizeF(7F,17F); @@ -179,7 +228,7 @@ ClientSize = new Size(756,404); Controls.Add(toolStripContainer1); Name = "MainForm"; - Text = "密码管理"; + Text = "凭据管理"; toolStripContainer1.ContentPanel.ResumeLayout(false); toolStripContainer1.ResumeLayout(false); toolStripContainer1.PerformLayout(); @@ -187,6 +236,10 @@ splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); splitContainer1.ResumeLayout(false); + splitContainer3.Panel1.ResumeLayout(false); + splitContainer3.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer3).EndInit(); + splitContainer3.ResumeLayout(false); menuKeyList.ResumeLayout(false); splitContainer2.Panel1.ResumeLayout(false); splitContainer2.Panel1.PerformLayout(); @@ -211,5 +264,10 @@ private ContextMenuStrip menuKeyList; private ToolStripMenuItem KeyListAddNew; private ToolStripMenuItem KeyListRemove; + private CheckedListBox clb_group; + private SplitContainer splitContainer3; + private ToolStripMenuItem toolStripMenuItem2; + private ToolStripMenuItem KeyListGroup; + private ToolStripSeparator toolStripMenuItem1; } } \ No newline at end of file diff --git a/PrivateBox/Forms/MainForm.cs b/PrivateBox/Forms/MainForm.cs index 426b63b..9fdda91 100644 --- a/PrivateBox/Forms/MainForm.cs +++ b/PrivateBox/Forms/MainForm.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using PrivateBox.DataContext; using PrivateBox.Encryption; +using System.Windows.Forms; namespace PrivateBox { @@ -10,6 +11,16 @@ namespace PrivateBox public DbContext Db { get; init; } public string CrytionKey { get; init; } + /// + /// 默认分组名 + /// + private const string _defaultGroupName = "未分组"; + + /// + /// 允许刷新Key列表 + /// + private bool EnableRefreshKeyList = true; + public MainForm(IServiceProvider provider) { InitializeComponent(); this.Encrytion = provider.GetRequiredService(); @@ -17,10 +28,16 @@ namespace PrivateBox this.CrytionKey = this.Db.GetCrytionKey(); this.Load += (s,d) => { + RefreshGroupList(); RefreshKeyList(); }; this.lbKeyList.SelectedIndexChanged += LbKeyList_SelectedIndexChanged; + this.clb_group.ItemCheck += (s,e) => { + this.BeginInvoke(new Action(() => { + RefreshKeyList(); + })); + }; } private void LbKeyList_SelectedIndexChanged(object? sender,EventArgs e) { @@ -38,11 +55,58 @@ namespace PrivateBox } } + /// + /// 刷新组 + /// + private void RefreshGroupList() { + var qu = this.Db.Queryable() + .Where(a => !string.IsNullOrEmpty(a.Group)) + .Select(a => a.Group) + .Distinct() + .ToList(); + var clbi = this.clb_group.Items; + foreach(var i in qu) { + if(i == null) { + continue; + } + if(!clbi.Contains(i)) { + clbi.Add(i); + } + } + if(!clbi.Contains(_defaultGroupName)) { + clbi.Add(_defaultGroupName); + } + if(clbi.Count == 1) { + this.EnableRefreshKeyList = false; + this.clb_group.SetItemChecked(0,true); + this.EnableRefreshKeyList = true; + } + RefreshKeyList(); + } + /// + /// 刷新Key列表 + /// private void RefreshKeyList() { + if(!EnableRefreshKeyList) { + return; + } this.lbKeyList.Items.Clear(); this.tbMessage.Text = ""; - var qu = this.Db.Queryable().Select(a => a.ItemName) - .ToList().OrderBy(a => a); + var groups = this.clb_group.CheckedItems.Cast(); + if(groups == null || groups.Count() == 0) { + return; + } + var qu = this.Db.Queryable() + .Where(a => groups.Contains(a.Group)) + .Select(a => a.ItemName) + .ToList(); + if(groups.Contains(_defaultGroupName)) { + var qunull = this.Db.Queryable() + .Where(a => string.IsNullOrEmpty(a.Group)) + .Select(a => a.ItemName) + .ToList(); + qu = qu.Union(qunull).ToList(); + } foreach(var i in qu) { this.lbKeyList.Items.Add(i); } @@ -94,6 +158,26 @@ namespace PrivateBox this.tbMessage.Text = tag.ItemValue; } + private void KeyListGroup_Click(object sender,EventArgs e) { + if(this.lbKeyList.SelectedItem == null) { + return; + } + var sItem = this.lbKeyList.SelectedItem.ToString(); + var qu = this.Db.Queryable().Where(a => a.ItemName == sItem).ToList(); + if(qu == null || qu.Count == 0) { + MessageBox.Show("没有找到项目!"); + return; + } + var dlg = new InputDlgBox("更新分组",qu.FirstOrDefault().Group); + if(dlg.ShowDialog() == DialogResult.OK) { + this.Db.Updateable() + .Where(a => a.ItemName == sItem) + .SetColumns(a => a.Group == dlg.Msg) + .ExecuteCommand(); + } + RefreshGroupList(); + } + private bool MessageChanged { get { var tag = this.tbMessage.Tag as CrytionItem;