Commit c147f962 authored by 罗显健's avatar 罗显健

【编号:24022】表开发工具优化:1.右键菜单增加:插入行、复制行、自动列宽、保存状态

2.表格增加行号 ,搜索框增加提示词
parent 65c771d2
......@@ -57,3 +57,4 @@ bin
/AppHome/WebKit/caches/default
/AppHome/config/links.xml
/AppHome/config/List`1.json
/Tools/Tools.csproj.user
......@@ -17,22 +17,25 @@ Set Quoted_Identifier On;
Go
-- =============================================
-- Author: 给表列增加说明栏信息
-- Create date: lxj
-- Description: 2016-11-29 11:21:02
-- Author: lxj
-- Create date: 2016-11-29 11:21:02
-- Description: 给表列增加说明栏信息
-- 调整字段说明内容长度 2025-10-20 11:14:46 lxj
-- =============================================
Create Proc [dbo].[sp_tools_AddTableClumnDescription]
( @TableName NVarchar(50), --表名
@ClumnName NVarchar(50), --列名
@Desctription NVarchar(300) --说明
( @TableName NVarchar(50) --表名
, @ClumnName NVarchar(50) --列名
, @Desctription NVarchar(2000) --说明
)
As
Begin
If Not Exists (Select * From::fn_listextendedproperty('MS_Description', 'Schema', 'dbo', 'table', @TableName, 'Column', @ClumnName))
Exec sp_addextendedproperty @name = 'MS_Description', @value = @Desctription, @level0type = 'Schema', @level0name = 'dbo', @level1type = N'Table', @level1name = @TableName, @level2type = N'Column', @level2name = @ClumnName;
Exec sp_addextendedproperty @name = 'MS_Description', @value = @Desctription, @level0type = 'Schema', @level0name = 'dbo', @level1type = N'Table', @level1name = @TableName
, @level2type = N'Column', @level2name = @ClumnName;
Else
Exec sp_updateextendedproperty @name = 'MS_Description', @value = @Desctription, @level0type = 'Schema', @level0name = 'dbo', @level1type = N'Table', @level1name = @TableName, @level2type = N'Column', @level2name = @ClumnName;
Exec sp_updateextendedproperty @name = 'MS_Description', @value = @Desctription, @level0type = 'Schema', @level0name = 'dbo', @level1type = N'Table', @level1name = @TableName
, @level2type = N'Column', @level2name = @ClumnName;
End;
Go
......@@ -50,8 +53,8 @@ Go
-- =============================================
Create Proc [dbo].[sp_tools_AddTableDescription]
( @TableName NVarchar(50), -- 表名
@Desctription NVarchar(300) -- 说明
( @TableName NVarchar(50) -- 表名
, @Desctription NVarchar(300) -- 说明
)
As
Begin
......
使用说明:
1、配置说明:可设置默认数据库路径和默认导出路径
2、操作说明:支持右键増行/删行,以及按键Insert与Delete
2、操作说明:支持右键添加行、删除行、插入行等,以及按键Insert与Delete。单元格内Shift+Enter可实现换行输入。
3、导出文件:以表名命名,相同类型多次导出则覆盖前面文件。默认导出路径为temp,可自定义。
4、暂存与恢复:暂存界面录入信息,可通过恢复暂存恢复。按表名暂存,每表每日只暂存一个文件。暂存路径为根目录save文件夹。
5、数据库设置:快速设置数据库链接并记录历史设置。程序启动时读取配置文件的默认数据库链接。
6、加载表信息:输入表名后:回车、点击工具栏-加载表信息、Alt+F8选择相似,都可以加载相关列信息
7、注意事项:
7、右侧搜索面板:支持搜素表名、列名或表说明、列说明。双击搜索列表行,自动加载该表信息(左侧)。
8、注意事项:
a.当表首次创建时,通过导出文件->生成SQL,会自动创建并记录描述信息
b.当表已存在时,通过导出文件->生成SQL,仅会更新描述信息
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -136,6 +136,11 @@ namespace Tools.MyCommon
/// 表设计器是否搜索描述
/// </summary>
public static string DBTableDevelop_SearchDesc => "DBTableDevelop_SearchDesc";
/// <summary>
/// 表设计器列宽度前缀
/// </summary>
public static string DBTableDevelop_ColumnWidth => "DBTableDevelop_ColumnWidth";
}
/// <summary>
/// 导出类型
......
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Tools.MyUtils
{
/// <summary>
/// TextBox Placeholder(占位符/提示文本)功能辅助类
/// 为 WinForms 的 TextBox 控件提供占位符功能
/// </summary>
public class TextBoxPlaceholder
{
private readonly TextBox _textBox;
private readonly string _placeholderText;
private readonly Color _placeholderColor;
private readonly Color _normalColor;
private bool _isPlaceholder;
/// <summary>
/// 获取当前是否显示的是占位符文本
/// </summary>
public bool IsPlaceholder => _isPlaceholder;
/// <summary>
/// 获取或设置占位符文本
/// </summary>
public string PlaceholderText => _placeholderText;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="textBox">要添加占位符功能的 TextBox 控件</param>
/// <param name="placeholderText">占位符文本内容</param>
/// <param name="placeholderColor">占位符文本颜色(可选,默认为灰色)</param>
/// <param name="normalColor">正常文本颜色(可选,默认为系统窗口文本颜色)</param>
public TextBoxPlaceholder(TextBox textBox, string placeholderText, Color? placeholderColor = null, Color? normalColor = null)
{
if (textBox == null)
throw new ArgumentNullException(nameof(textBox));
if (string.IsNullOrEmpty(placeholderText))
throw new ArgumentException("占位符文本不能为空", nameof(placeholderText));
_textBox = textBox;
_placeholderText = placeholderText;
_placeholderColor = placeholderColor ?? Color.Gray;
_normalColor = normalColor ?? SystemColors.WindowText;
_isPlaceholder = false;
// 绑定事件
_textBox.Enter += TextBox_Enter;
_textBox.Leave += TextBox_Leave;
// 初始化显示占位符
if (string.IsNullOrEmpty(_textBox.Text))
{
SetPlaceholder();
}
}
/// <summary>
/// 设置占位符显示
/// </summary>
private void SetPlaceholder()
{
if (string.IsNullOrEmpty(_textBox.Text))
{
_textBox.Text = _placeholderText;
_textBox.ForeColor = _placeholderColor;
_isPlaceholder = true;
}
}
/// <summary>
/// 清除占位符显示
/// </summary>
private void ClearPlaceholder()
{
if (_isPlaceholder)
{
_textBox.Text = string.Empty;
_textBox.ForeColor = _normalColor;
_isPlaceholder = false;
}
}
/// <summary>
/// TextBox 获得焦点事件
/// </summary>
private void TextBox_Enter(object sender, EventArgs e)
{
ClearPlaceholder();
}
/// <summary>
/// TextBox 失去焦点事件
/// </summary>
private void TextBox_Leave(object sender, EventArgs e)
{
SetPlaceholder();
}
/// <summary>
/// 获取 TextBox 的实际文本内容(排除占位符)
/// </summary>
/// <returns>实际文本内容,如果是占位符则返回空字符串</returns>
public string GetText()
{
return _isPlaceholder ? string.Empty : _textBox.Text;
}
/// <summary>
/// 设置 TextBox 的文本内容
/// </summary>
/// <param name="text">要设置的文本内容</param>
public void SetText(string text)
{
if (string.IsNullOrEmpty(text))
{
_textBox.Text = string.Empty;
_isPlaceholder = false;
SetPlaceholder();
}
else
{
_textBox.Text = text;
_textBox.ForeColor = _normalColor;
_isPlaceholder = false;
}
}
/// <summary>
/// 清空文本并恢复占位符
/// </summary>
public void Clear()
{
_textBox.Text = string.Empty;
_isPlaceholder = false;
SetPlaceholder();
}
/// <summary>
/// 解除事件绑定(在控件销毁时调用)
/// </summary>
public void Dispose()
{
_textBox.Enter -= TextBox_Enter;
_textBox.Leave -= TextBox_Leave;
}
/// <summary>
/// 静态方法:为 TextBox 添加占位符功能
/// </summary>
/// <param name="textBox">TextBox 控件</param>
/// <param name="placeholderText">占位符文本</param>
/// <param name="placeholderColor">占位符颜色(可选)</param>
/// <param name="normalColor">正常文本颜色(可选)</param>
/// <returns>TextBoxPlaceholder 实例</returns>
public static TextBoxPlaceholder AddPlaceholder(TextBox textBox, string placeholderText,
Color? placeholderColor = null, Color? normalColor = null)
{
return new TextBoxPlaceholder(textBox, placeholderText, placeholderColor, normalColor);
}
}
}
# TextBoxPlaceholder 使用说明
## 简介
`TextBoxPlaceholder` 是一个为 WinForms TextBox 控件提供占位符(Placeholder)功能的辅助类库。
## 功能特点
- ✅ 自动管理占位符文本的显示和隐藏
- ✅ 可自定义占位符颜色和正常文本颜色
- ✅ 提供实际文本内容获取方法(自动排除占位符)
- ✅ 支持编程方式设置文本和清空操作
- ✅ 事件绑定自动管理,无需手动处理
## 基本用法
### 方式一:使用构造函数(推荐)
```csharp
using Tools.MyUtils;
public partial class MyForm : Form
{
private TextBoxPlaceholder _searchPlaceholder;
private void InitUI()
{
// 创建 Placeholder 实例
_searchPlaceholder = new TextBoxPlaceholder(
this.tbSearch,
"请输入搜索内容,回车确认"
);
}
}
```
### 方式二:使用静态方法
```csharp
private TextBoxPlaceholder _namePlaceholder;
private void InitUI()
{
// 使用静态方法创建
_namePlaceholder = TextBoxPlaceholder.AddPlaceholder(
this.tbName,
"请输入姓名"
);
}
```
## 高级用法
### 自定义颜色
```csharp
_searchPlaceholder = new TextBoxPlaceholder(
this.tbSearch,
"请输入搜索内容",
Color.LightGray, // 占位符颜色
Color.Black // 正常文本颜色
);
```
### 获取实际文本内容
```csharp
// ❌ 错误方式:可能获取到占位符文本
string text = this.tbSearch.Text;
// ✅ 正确方式:自动排除占位符
string text = _searchPlaceholder.GetText();
```
### 编程方式设置文本
```csharp
// 设置文本
_searchPlaceholder.SetText("搜索内容");
// 清空文本并恢复占位符
_searchPlaceholder.Clear();
```
### 检查是否为占位符状态
```csharp
if (_searchPlaceholder.IsPlaceholder)
{
// 当前显示的是占位符
}
```
## 完整示例
```csharp
using System;
using System.Windows.Forms;
using Tools.MyUtils;
namespace YourNamespace
{
public partial class SearchForm : Form
{
private TextBoxPlaceholder _searchPlaceholder;
public SearchForm()
{
InitializeComponent();
InitUI();
}
private void InitUI()
{
// 初始化搜索框 Placeholder
_searchPlaceholder = new TextBoxPlaceholder(
this.tbSearch,
"请输入搜索关键字,按回车搜索"
);
// 绑定键盘事件
this.tbSearch.KeyDown += TbSearch_KeyDown;
}
private void TbSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
ExecuteSearch();
}
}
private void ExecuteSearch()
{
// 获取实际搜索内容(自动排除占位符)
string searchText = _searchPlaceholder.GetText().Trim();
if (string.IsNullOrEmpty(searchText))
{
MessageBox.Show("请输入搜索关键字!");
return;
}
// 执行搜索逻辑
PerformSearch(searchText);
}
private void BtnClear_Click(object sender, EventArgs e)
{
// 清空搜索框并恢复占位符
_searchPlaceholder.Clear();
}
}
}
```
## 使用场景
### 1. 搜索框
```csharp
_searchPlaceholder = new TextBoxPlaceholder(tbSearch, "请输入搜索内容,回车确认");
```
### 2. 登录表单
```csharp
_usernamePlaceholder = new TextBoxPlaceholder(tbUsername, "请输入用户名");
_passwordPlaceholder = new TextBoxPlaceholder(tbPassword, "请输入密码");
```
### 3. 筛选输入框
```csharp
_filterPlaceholder = new TextBoxPlaceholder(tbFilter, "输入关键字筛选...");
```
### 4. 配合单选按钮切换
```csharp
private void RadBtn_CheckedChanged(object sender, EventArgs e)
{
// 切换模式时清空并恢复占位符
_searchPlaceholder?.Clear();
// 更新占位符文本(需要时重新创建)
if (radBtnTable.Checked)
{
_searchPlaceholder = new TextBoxPlaceholder(tbSearch, "请输入表名");
}
else
{
_searchPlaceholder = new TextBoxPlaceholder(tbSearch, "请输入列名");
}
}
```
## 注意事项
1. **保持实例引用**:请将 `TextBoxPlaceholder` 实例保存为类成员变量,以便后续操作
2. **获取文本内容**:始终使用 `GetText()` 方法获取实际内容,而不是直接访问 `TextBox.Text`
3. **资源释放**:在窗体关闭时,可选择调用 `Dispose()` 方法解除事件绑定
```csharp
protected override void OnFormClosing(FormClosingEventArgs e)
{
_searchPlaceholder?.Dispose();
base.OnFormClosing(e);
}
```
4. **多个 TextBox**:可以为每个 TextBox 创建独立的 `TextBoxPlaceholder` 实例
```csharp
private TextBoxPlaceholder _placeholder1;
private TextBoxPlaceholder _placeholder2;
private TextBoxPlaceholder _placeholder3;
```
## API 参考
### 构造函数
```csharp
TextBoxPlaceholder(
TextBox textBox, // TextBox 控件
string placeholderText, // 占位符文本
Color? placeholderColor, // 占位符颜色(可选,默认灰色)
Color? normalColor // 正常文本颜色(可选,默认系统文本色)
)
```
### 属性
- `bool IsPlaceholder { get; }` - 当前是否显示占位符
- `string PlaceholderText { get; }` - 获取占位符文本
### 方法
- `string GetText()` - 获取实际文本内容(排除占位符)
- `void SetText(string text)` - 设置文本内容
- `void Clear()` - 清空文本并恢复占位符
- `void Dispose()` - 解除事件绑定
### 静态方法
```csharp
static TextBoxPlaceholder AddPlaceholder(
TextBox textBox,
string placeholderText,
Color? placeholderColor = null,
Color? normalColor = null
)
```
## 更新日志
### v1.0.0 (2025-10-20)
- ✅ 初始版本发布
- ✅ 支持基本的占位符显示/隐藏功能
- ✅ 提供文本内容获取和设置方法
- ✅ 支持自定义颜色配置
......@@ -1039,7 +1039,10 @@ namespace Tools.MyUtils
columnInfoList.Add(columninfo);
//创建描述
var Description = r["Description"].ToString();
descriptionList.Add($"EXEC [dbo].[sp_tools_AddTableClumnDescription] '{tableName}','{FieldName}','{Description}'");
if (!string.IsNullOrEmpty(Description)) //忽略列描述为空的行。
{
descriptionList.Add($"EXEC [dbo].[sp_tools_AddTableClumnDescription] '{tableName}','{FieldName}',N'{Description}'");
}
}
return string.Join(",\r\n", columnInfoList);
......
......@@ -27,6 +27,7 @@ namespace Tools.MyUtils
private void wMsgBox_Load(object sender, EventArgs e)
{
this.btnDefault.Click += BtnDefault_Click;
tbMessage.ReadOnly = true;
}
private void BtnDefault_Click(object sender, EventArgs e)
{
......
......@@ -129,6 +129,7 @@
<Compile Include="MyUtils\DrawHelper.cs" />
<Compile Include="MyUtils\InputtingService.cs" />
<Compile Include="MyUtils\SegPicture.cs" />
<Compile Include="MyUtils\TextBoxPlaceholder.cs" />
<Compile Include="MyUtils\TimeWatch.cs" />
<Compile Include="UI\Popups\wEditEvaluation.cs">
<SubType>Form</SubType>
......@@ -515,6 +516,7 @@
<EmbeddedResource Include="wMain.resx">
<DependentUpon>wMain.cs</DependentUpon>
</EmbeddedResource>
<None Include="MyUtils\TextBoxPlaceholder使用说明.md" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -120,27 +120,6 @@
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column6.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column3.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column4.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column7.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column5.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>127, 17</value>
</metadata>
......
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