Commit 65c771d2 authored by 罗显健's avatar 罗显健

【编号:24022】1.表开发工具优化:增加搜索面板 2.工具主界面菜单增加可折叠功能。

本次更新90%+的代码由AI生成。
parent fd287c75
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -34,7 +34,7 @@ namespace Tools.MyCommon
/// <summary>
/// 用户信息
/// </summary>
public static class LoginInfo
public static class LoginInfo
{
/// <summary>
/// 用户名
......@@ -121,6 +121,21 @@ namespace Tools.MyCommon
/// 默认Excel/Word文件导出路径
/// </summary>
public static string DocExportPath => "DocExportPath";
/// <summary>
/// 表设计器右侧面板展开状态
/// </summary>
public static string DBTableDevelop_RightPanelExpanded => "DBTableDevelop_RightPanelExpanded";
/// <summary>
/// 表设计器搜索类型(表/列)
/// </summary>
public static string DBTableDevelop_SearchType => "DBTableDevelop_SearchType";
/// <summary>
/// 表设计器是否搜索描述
/// </summary>
public static string DBTableDevelop_SearchDesc => "DBTableDevelop_SearchDesc";
}
/// <summary>
/// 导出类型
......
......@@ -57,7 +57,7 @@ namespace Tools.MyUtils
/// <summary>
/// 打包工具、更新包生成目录
/// </summary>
public static string PackagePath => $@"{Application.StartupPath}\Package";
public static string PackagePath => $@"{Application.StartupPath}\Package";
#endregion
#region 常用日期
......@@ -188,6 +188,83 @@ namespace Tools.MyUtils
}
#endregion
#region 读写系统配置文件(XML)
/// <summary>
/// 读取系统配置表(AppSetting)
/// </summary>
/// <returns>配置数据表</returns>
public static DataTable ReadSysConfig()
{
var dtSetting = new DataTable("AppSetting");
if (File.Exists(SysConfigFilePath))
{
dtSetting.ReadXml(SysConfigFilePath);
}
return dtSetting;
}
/// <summary>
/// 保存系统配置表(AppSetting)
/// </summary>
/// <param name="dtSetting">配置数据表</param>
public static void SaveSysConfig(DataTable dtSetting)
{
if (dtSetting != null)
{
dtSetting.WriteXml(SysConfigFilePath, XmlWriteMode.WriteSchema);
}
}
/// <summary>
/// 从配置表中获取指定配置值
/// </summary>
/// <param name="dt">配置数据表</param>
/// <param name="name">配置名称</param>
/// <returns>配置值</returns>
public static string GetConfigValue(DataTable dt, string name)
{
if (dt == null) return string.Empty;
var rows = dt.Select($"Name='{name}'");
return rows.Length > 0 ? rows[0]["Value"].ToString() : string.Empty;
}
/// <summary>
/// 在配置表中设置指定配置值(存在则更新,不存在则新增)
/// </summary>
/// <param name="dt">配置数据表</param>
/// <param name="name">配置名称</param>
/// <param name="value">配置值</param>
public static void SetConfigValue(DataTable dt, string name, string value)
{
if (dt == null) return;
var rows = dt.Select($"Name='{name}'");
if (rows.Length > 0)
{
rows[0]["Value"] = value;
rows[0].EndEdit();
}
else
{
var newRow = dt.NewRow();
newRow["Name"] = name;
newRow["Value"] = value;
dt.Rows.Add(newRow);
}
}
/// <summary>
/// 读取系统配置并转换为字典
/// </summary>
/// <returns>配置字典</returns>
public static Dictionary<string, string> ReadSysConfigAsDictionary()
{
var dtSetting = ReadSysConfig();
return dtSetting.Rows.Cast<DataRow>()
.ToDictionary(x => x["Name"].ToString(), x => x["Value"].ToString());
}
#endregion
#region 读写json配置文件
......@@ -244,6 +321,7 @@ namespace Tools.MyUtils
}
#endregion
#region 选择文件/路径
/// <summary>
......@@ -289,6 +367,18 @@ namespace Tools.MyUtils
return result;
}
/// <summary>
/// 创建目录
/// </summary>
/// <param name="path"></param>
public static void CreatePathIfNotExists(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
#endregion
#region 检查文件大小
......@@ -332,7 +422,8 @@ namespace Tools.MyUtils
//EntryName用以指定压缩层级
string EntryName = path.Substring($@"{rootPath}\".Length); //这里取根目录的相对路径
//创建新入口
ZipEntry entry = new ZipEntry(EntryName) {
ZipEntry entry = new ZipEntry(EntryName)
{
DateTime = DateTime.Now
};
zip.PutNextEntry(entry);
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//
using Tools.MyCommon;
using Tools.MyData;
using Tools.MyUtils;
namespace Tools.MyUtils
{
......@@ -40,15 +32,14 @@ namespace Tools.MyUtils
private void wSysSetting_Load(object sender, EventArgs e)
{
//读取设置信息
dtSetting = new DataTable("AppSetting");
dtSetting.ReadXml(Utils.SysConfigFilePath);
dtSetting = Utils.ReadSysConfig();
//填充界面
var linkString = this.GetValue(dtSetting, ConfigType.DefaultLink);
var linkString = Utils.GetConfigValue(dtSetting, ConfigType.DefaultLink);
this.LinkModel = Utils.GetDbItemModel(linkString);
this.tbDefaultLink.Text = this.LinkModel.ToString();
this.tbModelExportPath.Text = this.GetValue(dtSetting, ConfigType.ModelExportPath);
this.tbSqlExportPath.Text = this.GetValue(dtSetting, ConfigType.SqlExportPath);
this.tbDocExportPath.Text = this.GetValue(dtSetting, ConfigType.DocExportPath);
this.tbModelExportPath.Text = Utils.GetConfigValue(dtSetting, ConfigType.ModelExportPath);
this.tbSqlExportPath.Text = Utils.GetConfigValue(dtSetting, ConfigType.SqlExportPath);
this.tbDocExportPath.Text = Utils.GetConfigValue(dtSetting, ConfigType.DocExportPath);
//绑定事件
this.btnSelectDbLink.Click += BtnSelectDbLink_Click;
this.btnSelectModelPath.Click += BtnSelectModelPath_Click;
......@@ -106,46 +97,15 @@ namespace Tools.MyUtils
private void BtnSave_Click(object sender, EventArgs e)
{
//将设置写入结构表
this.SetValue(dtSetting, ConfigType.DefaultLink, this.LinkModel.LinkString);
this.SetValue(dtSetting, ConfigType.ModelExportPath, this.tbModelExportPath.Text);
this.SetValue(dtSetting, ConfigType.SqlExportPath, this.tbSqlExportPath.Text);
this.SetValue(dtSetting, ConfigType.DocExportPath, this.tbDocExportPath.Text);
Utils.SetConfigValue(dtSetting, ConfigType.DefaultLink, this.LinkModel.LinkString);
Utils.SetConfigValue(dtSetting, ConfigType.ModelExportPath, this.tbModelExportPath.Text);
Utils.SetConfigValue(dtSetting, ConfigType.SqlExportPath, this.tbSqlExportPath.Text);
Utils.SetConfigValue(dtSetting, ConfigType.DocExportPath, this.tbDocExportPath.Text);
//保存设置
dtSetting.WriteXml(Utils.SysConfigFilePath, XmlWriteMode.WriteSchema);
Utils.SaveSysConfig(dtSetting);
this.DialogResult = DialogResult.OK;
}
/// <summary>
/// 获取指定配置值
/// </summary>
/// <param name="dt"></param>
/// <param name="name"></param>
/// <returns></returns>
private string GetValue(DataTable dt, string name)
{
var result = "";
var rows = dt.Select($"Name='{name}'");
if (rows.Length > 0)
{
result = rows[0]["Value"].ToString();
}
return result;
}
/// <summary>
/// 设置指定配置值
/// </summary>
/// <param name="dt"></param>
/// <param name="name"></param>
/// <param name="value"></param>
private void SetValue(DataTable dt, string name, string value)
{
var rows = dt.Select($"Name='{name}'");
if (rows.Length > 0)
{
rows[0]["Value"] = value;
rows[0].EndEdit();
}
}
/// <summary>
/// 选择路径并赋值到文本框
/// </summary>
......@@ -158,7 +118,5 @@ namespace Tools.MyUtils
tb.Text = frm.SelectedPath;
}
}
}
}
......@@ -99,16 +99,7 @@ namespace Tools.UI.sys
//打包所有文件
DirectoryInfo dirInfo = new DirectoryInfo(path);
var fileInfos = dirInfo.GetFiles("*.*", SearchOption.AllDirectories).ToList();
fileInfos = fileInfos.Where(
f => !f.FullName.Contains("\\AutoUpdate\\") //剔除自动更新文件
&& !f.FullName.Contains(Utils.LogPath) && !f.FullName.Contains(Utils.TempPath) //日志、临时文件目录
&& !f.FullName.Contains(Utils.SavePath) // 系统预设的用户本地文件目录,需要排除
&& !f.FullName.Contains(Utils.PackagePath) //程序更新打包目录
&& !f.Name.Equals("links.xml") //剔除链接记录文件(本地常用数据库链接记录)
&& !f.Name.Equals("sys_cfg.xml") //剔除(表开发工具-系统配置)文件
&& !f.Extension.Equals(".json") //剔除json配置信息
&& !f.Extension.Equals("") //剔除无扩展名的文件(大部分是临时文件)
).ToList(); //剔除自动更新相关目录
fileInfos = fileInfos.Where(f => !IsFileIgnore(f)).ToList(); //剔除自动更新相关目录
//构造压缩文件路径集合
List<string> FileNames = new List<string>();
FileNames.AddRange(fileInfos.Select(f => f.FullName));
......@@ -138,6 +129,26 @@ namespace Tools.UI.sys
this.AsyncUI(() => this._bar.Close());
});
}
/// <summary>
/// 是否为需要剔除的文件
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
private bool IsFileIgnore(FileInfo f)
{
return f.FullName.Contains("\\AutoUpdate\\") //剔除自动更新文件
|| f.FullName.Contains(Utils.LogPath) //日志、
|| f.FullName.Contains(Utils.TempPath) //临时文件目录
|| f.FullName.Contains(Utils.SavePath) // 系统预设的用户本地文件目录,需要排除
|| f.FullName.Contains(Utils.PackagePath) //程序更新打包目录
|| f.Name.Equals("links.xml") //剔除链接记录文件(本地常用数据库链接记录)
|| f.Name.Equals("sys_cfg.xml") //剔除(表开发工具-系统配置)文件
|| f.Extension.Equals(".json") //剔除json配置信息
|| f.FullName.Contains("\\WebKit\\")//剔除WebKit相关文件,太大了。
|| f.Extension.Equals(""); //剔除无扩展名的文件(大部分是临时文件)
}
private void btnSave_Click(object sender, EventArgs e)
{
this.Save();
......
This diff is collapsed.
This diff is collapsed.
......@@ -162,11 +162,10 @@ namespace Tools.UI
private void InitDefaultDbLink()
{
//读取配置信息
var dtSetting = new DataTable("AppSetting");
dtSetting.ReadXml(Utils.SysConfigFilePath);
var dicConfig = dtSetting.Rows.Cast<DataRow>().ToDictionary(x => x["Name"].ToString(), x => x["Value"].ToString());
var dicConfig = Utils.ReadSysConfigAsDictionary();
if (!dicConfig.ContainsKey(ConfigType.DefaultLink)) return;
//初始化数据库链接
var link = dicConfig["DefaultLink"];
var link = dicConfig[ConfigType.DefaultLink];
if (!string.IsNullOrEmpty(link))
{
this.tstbLinkString.Text = Utils.GetDbItemModel(link).ToString();
......
......@@ -148,7 +148,8 @@ namespace Tools.UI
//初始化列属性
ds.Tables[0].Columns.Cast<DataColumn>().ToList()
.ForEach(col => {
.ForEach(col =>
{
bool isKey = ds.Tables[0].PrimaryKey.Contains(col);
var dr = result.Tables[0].NewRow();
dr["Name"] = col.ColumnName;
......@@ -289,7 +290,8 @@ ORDER BY b.column_id;";
var sqlsNode = xmlDoc.CreateElement("Sqls");
string strKey = _ds.Tables[0].Columns[0].ToString(); //首列一般主键列
string keyWhere = $" {strKey}=@{strKey} ";
var columnList = this._ds.Tables[0].Columns.Cast<DataColumn>().Select(c => c.ColumnName).ToList();
var columnList = this._ds.Tables[0].Columns.Cast<DataColumn>().Where(c => !_ds.Tables[0].PrimaryKey.Contains(c)).Select(c => c.ColumnName).ToList();
#region SelectObject
//SQL配置基本设置
......@@ -311,6 +313,7 @@ ORDER BY b.column_id;";
//生成参数
foreach (DataColumn dc in _ds.Tables[0].Columns)
{
if (_ds.Tables[0].PrimaryKey.Contains(dc)) continue; //新增的时候不需要主键列
this.AddParamNode(xmlDoc, sqlNode, dc.ColumnName);
}
......
namespace Tools
namespace Tools
{
partial class wMain
{
......@@ -34,6 +34,7 @@
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.listView1 = new System.Windows.Forms.ListView();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.btnToggleMenu = new System.Windows.Forms.Button();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiSysUpload = new System.Windows.Forms.ToolStripMenuItem();
......@@ -107,6 +108,7 @@
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.listView1);
this.splitContainer1.Panel1.Controls.Add(this.btnToggleMenu);
this.splitContainer1.Panel1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
//
// splitContainer1.Panel2
......@@ -123,7 +125,7 @@
this.listView1.LargeImageList = this.imageList1;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(200, 369);
this.listView1.Size = new System.Drawing.Size(200, 349);
this.listView1.SmallImageList = this.imageList1;
this.listView1.StateImageList = this.imageList1;
this.listView1.TabIndex = 0;
......@@ -139,6 +141,23 @@
this.imageList1.Images.SetKeyName(3, "51_工作群组.png");
this.imageList1.Images.SetKeyName(4, "60_空间.png");
//
// btnToggleMenu
//
this.btnToggleMenu.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(41)))), ((int)(((byte)(101)))), ((int)(((byte)(204)))));
this.btnToggleMenu.Dock = System.Windows.Forms.DockStyle.Bottom;
this.btnToggleMenu.FlatAppearance.BorderSize = 0;
this.btnToggleMenu.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnToggleMenu.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnToggleMenu.ForeColor = System.Drawing.Color.White;
this.btnToggleMenu.Location = new System.Drawing.Point(0, 349);
this.btnToggleMenu.Margin = new System.Windows.Forms.Padding(0);
this.btnToggleMenu.Name = "btnToggleMenu";
this.btnToggleMenu.Size = new System.Drawing.Size(200, 20);
this.btnToggleMenu.TabIndex = 1;
this.btnToggleMenu.Text = "<";
this.btnToggleMenu.UseVisualStyleBackColor = false;
this.btnToggleMenu.Click += new System.EventHandler(this.btnToggleMenu_Click);
//
// menuStrip1
//
this.menuStrip1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(245)))), ((int)(((byte)(255)))));
......@@ -612,5 +631,6 @@
private System.Windows.Forms.Label lbBrief;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.ToolStripMenuItem tsmiShowFetetoWork;
private System.Windows.Forms.Button btnToggleMenu;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
//
......@@ -32,6 +30,14 @@ namespace Tools
/// 数据库访问对象
/// </summary>
DBHelper _db = null;
/// <summary>
/// 左侧菜单原始宽度
/// </summary>
private int OriginalMenuWidth = 200;
/// <summary>
/// 左侧菜单是否已折叠
/// </summary>
private bool IsMenuCollapsed = false;
public wMain()
{
......@@ -59,6 +65,8 @@ namespace Tools
}
private void WMain_Shown(object sender, EventArgs e)
{
//保存原始宽度
this.OriginalMenuWidth = this.splitContainer1.SplitterDistance;
//窗体拖拽事件
this.Header.MouseDown += Header_MouseDown;
this.Header.MouseUp += Header_MouseUp;
......@@ -425,6 +433,18 @@ namespace Tools
UserLog.Write($"关闭模块:{page.Text}"); //日志记录
this.OpenedList.Remove(page.Text); //移除列表
this.tabControl1.TabPages.Remove(page); //移除页面
//先关闭并释放窗体
if (page.Controls.Count > 0)
{
var frm = page.Controls[0] as Form;
if (frm != null)
{
frm.Close(); //触发FormClosing事件
frm.Dispose(); //释放窗体资源
}
}
page.Dispose(); //释放页面
}
}
......@@ -451,13 +471,44 @@ namespace Tools
#endregion
#region 扩展:折叠/展开左侧菜单
/// <summary>
/// 折叠/展开按钮点击事件
/// </summary>
private void btnToggleMenu_Click(object sender, EventArgs e)
{
this.ToggleMenu();
}
/// <summary>
/// 切换菜单折叠/展开状态
/// </summary>
private void ToggleMenu()
{
// 切换状态
this.IsMenuCollapsed = !this.IsMenuCollapsed;
// 使用三元运算符简化状态切换
this.splitContainer1.SplitterDistance = this.IsMenuCollapsed ? 20 : this.OriginalMenuWidth;
this.btnToggleMenu.Text = this.IsMenuCollapsed ? ">" : "<";
// 强制刷新按钮显示
this.btnToggleMenu.PerformLayout();
this.btnToggleMenu.Refresh();
}
#endregion
#region 扩展:使用内存展示
//定时器:默认开启,间隔1秒
private void timer1_Tick(object sender, EventArgs e)
{
var p = Process.GetCurrentProcess();
var MB = (p.WorkingSet64 / 1024 / 1024);
// 使用PrivateMemorySize64获取进程独占的内存,与任务管理器显示一致
// WorkingSet64 包含共享内存,通常比实际占用大
var MB = (p.PrivateMemorySize64 / 1024 / 1024);
this.AsyncUI(() => {
this.lbSysMemery.Text = $"{MB}M";
});
......
......@@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD0
EgAAAk1TRnQBSQFMAgEBBQEAARABAQEQAQEBIAEAASABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
EgAAAk1TRnQBSQFMAgEBBQEAASgBAQEoAQEBIAEAASABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABgAMAAUADAAEBAQABCAYAASAYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment