Commit 26f8a48f authored by tr's avatar tr

1、数据库开发工具:增加对已存在表支持,方便相应导出操作

parent ef527f7e
...@@ -17,3 +17,4 @@ bin ...@@ -17,3 +17,4 @@ bin
/.vs/Ftt_Common /.vs/Ftt_Common
.vs .vs
/AppHome/save /AppHome/save
/AppHome/temp
No preview for this file type
No preview for this file type
...@@ -3,5 +3,8 @@ ...@@ -3,5 +3,8 @@
2、操作说明:支持右键増行/删行,以及按键Insert与Delete 2、操作说明:支持右键増行/删行,以及按键Insert与Delete
3、导出文件:以表名命名,即每表导出一个相应类型文件。默认导出路径为temp,可自定义。 3、导出文件:以表名命名,即每表导出一个相应类型文件。默认导出路径为temp,可自定义。
4、暂存与恢复:暂存时,每表每天只暂存一个文件。暂存路径根目录save文件夹。 4、暂存与恢复:暂存时,每表每天只暂存一个文件。暂存路径根目录save文件夹。
5、数据库设置:快速设置数据库链接并记录历史设置。程序启动时读取配置文件的默认数据库链接 5、数据库设置:快速设置数据库链接并记录历史设置。程序启动时读取配置文件的默认数据库链接。
6、日志功能:暂不开发 6、加载表信息:表创建后,可以输入表名,通过该按钮加载相应信息。使用该功能时,有几点需要注意:
a.加载信息后,通过导出SQL按钮,会更新数据库的描述信息,除描述信息之外的任何修改不会更新到数据库。
b.由于类型是下拉选择框,对于非本工具创建的表,存在类型风险,即无法找到匹配的下拉项。
...@@ -12,4 +12,10 @@ ...@@ -12,4 +12,10 @@
<UserId>sa</UserId> <UserId>sa</UserId>
<Pwd>sa</Pwd> <Pwd>sa</Pwd>
</links> </links>
<links>
<Link>.</Link>
<DbName>Temp</DbName>
<UserId>sa</UserId>
<Pwd>sa</Pwd>
</links>
</DocumentElement> </DocumentElement>
\ No newline at end of file
...@@ -110,6 +110,16 @@ namespace Tools.Properties { ...@@ -110,6 +110,16 @@ namespace Tools.Properties {
} }
} }
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 加载 {
get {
object obj = ResourceManager.GetObject("加载", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary> /// </summary>
......
...@@ -133,6 +133,9 @@ ...@@ -133,6 +133,9 @@
<data name="分析" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="分析" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\分析.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\分析.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="加载" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\加载.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="实体类" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="实体类" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\实体类.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\实体类.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
......
...@@ -198,5 +198,8 @@ ...@@ -198,5 +198,8 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\分析.png" /> <None Include="Resources\分析.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="Resources\加载.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
\ No newline at end of file
...@@ -30,19 +30,10 @@ ...@@ -30,19 +30,10 @@
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
this.tsmiExportModel = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiExportSql = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiExportExcel = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiExportWord = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.tsbTempSave = new System.Windows.Forms.ToolStripButton();
this.tsbResume = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.tsbDbLink = new System.Windows.Forms.ToolStripButton();
this.tstbDbLink = new System.Windows.Forms.ToolStripTextBox(); this.tstbDbLink = new System.Windows.Forms.ToolStripTextBox();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.tsbHelp = new System.Windows.Forms.ToolStripButton();
this.dgvData = new System.Windows.Forms.DataGridView(); this.dgvData = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
...@@ -59,6 +50,17 @@ ...@@ -59,6 +50,17 @@
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.tbTableName = new System.Windows.Forms.TextBox(); this.tbTableName = new System.Windows.Forms.TextBox();
this.tbTableDescription = new System.Windows.Forms.TextBox(); this.tbTableDescription = new System.Windows.Forms.TextBox();
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
this.tsmiExportModel = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiExportSql = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiExportExcel = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiExportWord = new System.Windows.Forms.ToolStripMenuItem();
this.tsbLoadTable = new System.Windows.Forms.ToolStripButton();
this.tsbTempSave = new System.Windows.Forms.ToolStripButton();
this.tsbResume = new System.Windows.Forms.ToolStripButton();
this.tsbDbLink = new System.Windows.Forms.ToolStripButton();
this.tsbHelp = new System.Windows.Forms.ToolStripButton();
this.toolStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvData)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvData)).BeginInit();
this.contextMenuStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout();
...@@ -69,6 +71,8 @@ ...@@ -69,6 +71,8 @@
// //
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripDropDownButton1, this.toolStripDropDownButton1,
this.toolStripSeparator4,
this.tsbLoadTable,
this.toolStripSeparator2, this.toolStripSeparator2,
this.tsbTempSave, this.tsbTempSave,
this.tsbResume, this.tsbResume,
...@@ -84,81 +88,16 @@ ...@@ -84,81 +88,16 @@
this.toolStrip1.TabIndex = 0; this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1"; this.toolStrip1.Text = "toolStrip1";
// //
// toolStripDropDownButton1
//
this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsmiExportModel,
this.tsmiExportSql,
this.tsmiExportExcel,
this.tsmiExportWord});
this.toolStripDropDownButton1.Image = global::Tools.Properties.Resources.导出;
this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
this.toolStripDropDownButton1.Size = new System.Drawing.Size(85, 21);
this.toolStripDropDownButton1.Text = "导出文件";
//
// tsmiExportModel
//
this.tsmiExportModel.Image = global::Tools.Properties.Resources.类;
this.tsmiExportModel.Name = "tsmiExportModel";
this.tsmiExportModel.Size = new System.Drawing.Size(123, 22);
this.tsmiExportModel.Text = "实体类";
//
// tsmiExportSql
//
this.tsmiExportSql.Image = global::Tools.Properties.Resources.sql;
this.tsmiExportSql.Name = "tsmiExportSql";
this.tsmiExportSql.Size = new System.Drawing.Size(123, 22);
this.tsmiExportSql.Text = "SQL文件";
//
// tsmiExportExcel
//
this.tsmiExportExcel.Image = global::Tools.Properties.Resources.excel;
this.tsmiExportExcel.Name = "tsmiExportExcel";
this.tsmiExportExcel.Size = new System.Drawing.Size(123, 22);
this.tsmiExportExcel.Text = "Excel";
//
// tsmiExportWord
//
this.tsmiExportWord.Image = global::Tools.Properties.Resources.word;
this.tsmiExportWord.Name = "tsmiExportWord";
this.tsmiExportWord.Size = new System.Drawing.Size(123, 22);
this.tsmiExportWord.Text = "Word";
//
// toolStripSeparator2 // toolStripSeparator2
// //
this.toolStripSeparator2.Name = "toolStripSeparator2"; this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 23); this.toolStripSeparator2.Size = new System.Drawing.Size(6, 23);
// //
// tsbTempSave
//
this.tsbTempSave.Image = global::Tools.Properties.Resources.暂存;
this.tsbTempSave.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbTempSave.Name = "tsbTempSave";
this.tsbTempSave.Size = new System.Drawing.Size(52, 21);
this.tsbTempSave.Text = "暂存";
//
// tsbResume
//
this.tsbResume.Image = global::Tools.Properties.Resources.恢复;
this.tsbResume.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbResume.Name = "tsbResume";
this.tsbResume.Size = new System.Drawing.Size(76, 21);
this.tsbResume.Text = "恢复暂存";
//
// toolStripSeparator1 // toolStripSeparator1
// //
this.toolStripSeparator1.Name = "toolStripSeparator1"; this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 23); this.toolStripSeparator1.Size = new System.Drawing.Size(6, 23);
// //
// tsbDbLink
//
this.tsbDbLink.Image = global::Tools.Properties.Resources.数据库;
this.tsbDbLink.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbDbLink.Name = "tsbDbLink";
this.tsbDbLink.Size = new System.Drawing.Size(88, 21);
this.tsbDbLink.Text = "数据库配置";
//
// tstbDbLink // tstbDbLink
// //
this.tstbDbLink.Enabled = false; this.tstbDbLink.Enabled = false;
...@@ -171,14 +110,6 @@ ...@@ -171,14 +110,6 @@
this.toolStripSeparator3.Name = "toolStripSeparator3"; this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(6, 23); this.toolStripSeparator3.Size = new System.Drawing.Size(6, 23);
// //
// tsbHelp
//
this.tsbHelp.Image = global::Tools.Properties.Resources.使用说明;
this.tsbHelp.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbHelp.Name = "tsbHelp";
this.tsbHelp.Size = new System.Drawing.Size(76, 21);
this.tsbHelp.Text = "使用说明";
//
// dgvData // dgvData
// //
this.dgvData.BackgroundColor = System.Drawing.SystemColors.Window; this.dgvData.BackgroundColor = System.Drawing.SystemColors.Window;
...@@ -217,7 +148,6 @@ ...@@ -217,7 +148,6 @@
// Column2 // Column2
// //
this.Column2.DataPropertyName = "ColumnType"; this.Column2.DataPropertyName = "ColumnType";
this.Column2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Column2.HeaderText = "类型"; this.Column2.HeaderText = "类型";
this.Column2.Items.AddRange(new object[] { this.Column2.Items.AddRange(new object[] {
"", "",
...@@ -350,6 +280,92 @@ ...@@ -350,6 +280,92 @@
this.tbTableDescription.Size = new System.Drawing.Size(152, 23); this.tbTableDescription.Size = new System.Drawing.Size(152, 23);
this.tbTableDescription.TabIndex = 5; this.tbTableDescription.TabIndex = 5;
// //
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(6, 23);
//
// toolStripDropDownButton1
//
this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsmiExportModel,
this.tsmiExportSql,
this.tsmiExportExcel,
this.tsmiExportWord});
this.toolStripDropDownButton1.Image = global::Tools.Properties.Resources.导出;
this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
this.toolStripDropDownButton1.Size = new System.Drawing.Size(85, 21);
this.toolStripDropDownButton1.Text = "导出文件";
//
// tsmiExportModel
//
this.tsmiExportModel.Image = global::Tools.Properties.Resources.类;
this.tsmiExportModel.Name = "tsmiExportModel";
this.tsmiExportModel.Size = new System.Drawing.Size(180, 22);
this.tsmiExportModel.Text = "实体类";
//
// tsmiExportSql
//
this.tsmiExportSql.Image = global::Tools.Properties.Resources.sql;
this.tsmiExportSql.Name = "tsmiExportSql";
this.tsmiExportSql.Size = new System.Drawing.Size(180, 22);
this.tsmiExportSql.Text = "SQL文件";
//
// tsmiExportExcel
//
this.tsmiExportExcel.Image = global::Tools.Properties.Resources.excel;
this.tsmiExportExcel.Name = "tsmiExportExcel";
this.tsmiExportExcel.Size = new System.Drawing.Size(180, 22);
this.tsmiExportExcel.Text = "Excel";
//
// tsmiExportWord
//
this.tsmiExportWord.Image = global::Tools.Properties.Resources.word;
this.tsmiExportWord.Name = "tsmiExportWord";
this.tsmiExportWord.Size = new System.Drawing.Size(180, 22);
this.tsmiExportWord.Text = "Word";
//
// tsbLoadTable
//
this.tsbLoadTable.Image = global::Tools.Properties.Resources.加载;
this.tsbLoadTable.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbLoadTable.Name = "tsbLoadTable";
this.tsbLoadTable.Size = new System.Drawing.Size(88, 21);
this.tsbLoadTable.Text = "加载表信息";
//
// tsbTempSave
//
this.tsbTempSave.Image = global::Tools.Properties.Resources.暂存;
this.tsbTempSave.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbTempSave.Name = "tsbTempSave";
this.tsbTempSave.Size = new System.Drawing.Size(52, 21);
this.tsbTempSave.Text = "暂存";
//
// tsbResume
//
this.tsbResume.Image = global::Tools.Properties.Resources.恢复;
this.tsbResume.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbResume.Name = "tsbResume";
this.tsbResume.Size = new System.Drawing.Size(76, 21);
this.tsbResume.Text = "恢复暂存";
//
// tsbDbLink
//
this.tsbDbLink.Image = global::Tools.Properties.Resources.数据库;
this.tsbDbLink.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbDbLink.Name = "tsbDbLink";
this.tsbDbLink.Size = new System.Drawing.Size(88, 21);
this.tsbDbLink.Text = "数据库配置";
//
// tsbHelp
//
this.tsbHelp.Image = global::Tools.Properties.Resources.使用说明;
this.tsbHelp.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbHelp.Name = "tsbHelp";
this.tsbHelp.Size = new System.Drawing.Size(76, 21);
this.tsbHelp.Text = "使用说明";
//
// wDBTools // wDBTools
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
...@@ -393,6 +409,11 @@ ...@@ -393,6 +409,11 @@
private System.Windows.Forms.TextBox tbTableDescription; private System.Windows.Forms.TextBox tbTableDescription;
private System.Windows.Forms.ToolStripMenuItem tsmiExportSql; private System.Windows.Forms.ToolStripMenuItem tsmiExportSql;
private System.Windows.Forms.ToolStripMenuItem tsmiAddRow; private System.Windows.Forms.ToolStripMenuItem tsmiAddRow;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripButton tsbHelp;
private System.Windows.Forms.ToolStripButton tsbDbLink;
private System.Windows.Forms.ToolStripTextBox tstbDbLink;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1; private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column6; private System.Windows.Forms.DataGridViewTextBoxColumn Column6;
private System.Windows.Forms.DataGridViewComboBoxColumn Column2; private System.Windows.Forms.DataGridViewComboBoxColumn Column2;
...@@ -400,10 +421,7 @@ ...@@ -400,10 +421,7 @@
private System.Windows.Forms.DataGridViewCheckBoxColumn Column4; private System.Windows.Forms.DataGridViewCheckBoxColumn Column4;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column7; private System.Windows.Forms.DataGridViewCheckBoxColumn Column7;
private System.Windows.Forms.DataGridViewTextBoxColumn Column5; private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
private System.Windows.Forms.ToolStripButton tsbHelp; private System.Windows.Forms.ToolStripButton tsbLoadTable;
private System.Windows.Forms.ToolStripButton tsbDbLink;
private System.Windows.Forms.ToolStripTextBox tstbDbLink;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
} }
} }
\ No newline at end of file
...@@ -123,18 +123,9 @@ namespace Tools.UI ...@@ -123,18 +123,9 @@ namespace Tools.UI
{ "IsAutoIncrement", typeof(bool) }, { "IsAutoIncrement", typeof(bool) },
{ "DefaultValue", typeof(string) }, { "DefaultValue", typeof(string) },
}, },
//Rows = {
// { "ID", "主键", "VARCHAR(50)", DBNull.Value, DBNull.Value, DBNull.Value, "" },
//},
}); });
//设置主键 //设置主键
this._ds.Tables[infoTable].PrimaryKey = new DataColumn[] { this._ds.Tables[infoTable].Columns[0] }; this._ds.Tables[infoTable].PrimaryKey = new DataColumn[] { this._ds.Tables[infoTable].Columns[0] };
//生成数据结构配置文件
//var cfg = $@"{Utils.ConfigPath}\data_struct_cfg.xml";
//if (!File.Exists(cfg))
//{
// this._ds.WriteXml(cfg, XmlWriteMode.WriteSchema);
//}
#endregion #endregion
} }
...@@ -159,6 +150,7 @@ namespace Tools.UI ...@@ -159,6 +150,7 @@ namespace Tools.UI
this.tsmiExportSql.Click += TsmiExportSql_Click; this.tsmiExportSql.Click += TsmiExportSql_Click;
this.tsmiExportExcel.Click += TsmiExportExcel_Click; this.tsmiExportExcel.Click += TsmiExportExcel_Click;
this.tsmiExportWord.Click += TsmiExportWord_Click; this.tsmiExportWord.Click += TsmiExportWord_Click;
this.tsbLoadTable.Click += TsbLoadTable_Click;
this.tsbTempSave.Click += TsbTempSave_Click; this.tsbTempSave.Click += TsbTempSave_Click;
this.tsbResume.Click += TsbResume_Click; this.tsbResume.Click += TsbResume_Click;
this.tsbDbLink.Click += TsbDbLink_Click; this.tsbDbLink.Click += TsbDbLink_Click;
...@@ -168,6 +160,7 @@ namespace Tools.UI ...@@ -168,6 +160,7 @@ namespace Tools.UI
this.tsmiDelRow.Click += TsmiDelRow_Click; this.tsmiDelRow.Click += TsmiDelRow_Click;
} }
private void BindBaseInfo() private void BindBaseInfo()
{ {
this.tbTableName.DataBindings.Clear(); this.tbTableName.DataBindings.Clear();
...@@ -289,6 +282,22 @@ namespace Tools.UI ...@@ -289,6 +282,22 @@ namespace Tools.UI
new NPOIWordHelper().Export(this.TableName, this.TableDescription, this._ds.Tables[infoTable], $@"{this.GetExportPath()}\{this.TableName}.docx"); new NPOIWordHelper().Export(this.TableName, this.TableDescription, this._ds.Tables[infoTable], $@"{this.GetExportPath()}\{this.TableName}.docx");
} }
private void TsbLoadTable_Click(object sender, EventArgs e)
{
if (this.TableName.Equals(""))
{
Utils.Tip("请输入表名!");
return;
}
if (!this.IsExistTable(this.TableName))
{
Utils.Tip("该表尚未创建!");
return;
}
//初始化表列信息
this.InitTableColumnInfo(this.TableName);
}
private void TsbTempSave_Click(object sender, EventArgs e) private void TsbTempSave_Click(object sender, EventArgs e)
{ {
if (!this.CheckDetail()) if (!this.CheckDetail())
...@@ -332,7 +341,7 @@ namespace Tools.UI ...@@ -332,7 +341,7 @@ namespace Tools.UI
{ {
using (var sr = new StreamReader(helpFileName)) using (var sr = new StreamReader(helpFileName))
{ {
Utils.Tip(sr.ReadToEnd(), 450, 300); Utils.Tip(sr.ReadToEnd(), 700, 300);
} }
} }
...@@ -363,12 +372,13 @@ namespace Tools.UI ...@@ -363,12 +372,13 @@ namespace Tools.UI
/// <returns></returns> /// <returns></returns>
private bool CheckDetail() private bool CheckDetail()
{ {
//检查基本信息 //检查表名
if (this.TableName.Equals("")) if (this.TableName.Equals(""))
{ {
Utils.Tip("请输入表名!"); Utils.Tip("请输入表名!");
return false; return false;
} }
//检查表描述
if (this.TableDescription.Equals("")) if (this.TableDescription.Equals(""))
{ {
Utils.Tip("请输入表的描述信息!"); Utils.Tip("请输入表的描述信息!");
...@@ -473,8 +483,78 @@ namespace Tools.UI ...@@ -473,8 +483,78 @@ namespace Tools.UI
Directory.CreateDirectory(path); Directory.CreateDirectory(path);
} }
} }
/// <summary>
/// 是否存在表
/// </summary>
/// <param name="tableName"></param>
/// <returns></returns>
private bool IsExistTable(string tableName)
{
return this._db.IsExist(this._link, $"SELECT COUNT(*) FROM sys.tables WHERE [name] = '{tableName}'");
}
/// <summary>
/// 初始化表列信息(针对已存在的表)
/// </summary>
/// <param name="tableName"></param>
private void InitTableColumnInfo(string tableName)
{
//清空当前表格
this._ds.Tables[infoTable].Rows.Clear();
var sqlist = new List<TQuery> {
//取表结构
new TQuery(tableName, $"SELECT TOP 0 * FROM {tableName}"),
//取表描述
new TQuery("TableDescInfo", $@"
SELECT
TableName=a.name,
TableDescription=b.value
FROM sysobjects a
LEFT JOIN sys.extended_properties b ON a.id = b.major_id AND b.minor_id = 0
WHERE a.name = '{tableName}'"),
//取列描述、非空、默认值
new TQuery("ColumnDescInfo", $@"
SELECT
FieldName = CONVERT(VARCHAR(100), a.name),
[Description] = CONVERT(VARCHAR (50), isnull(d.[value],'')),
IsNotNull = CASE WHEN a.isnullable=1 THEN 0 ELSE 1 END,
DefaultValue = REPLACE(REPLACE(c.text, '(', ''), ')', ''),
ColumnType = CASE WHEN CHARINDEX('varchar',e.name,0) > 0 THEN e.name+'('+CAST(a.length AS VARCHAR(50)) +')' ELSE e.name END
FROM dbo.syscolumns a
INNER JOIN dbo.sysobjects b ON b.id = a.id AND b.xtype = 'U' AND b.name <> 'dtproperties'
LEFT JOIN sys.syscomments c ON c.id = a.cdefault
LEFT JOIN sys.extended_properties d ON d.major_id = b.id AND d.minor_id = a.colid
LEFT JOIN dbo.systypes e ON e.xusertype = a.xusertype
WHERE b.name = '{tableName}'"),
};
try
{
var ds = this._db.GetData(this._link, sqlist, true);
//先添加表描述
this.tbTableDescription.Text = ds.Tables["TableDescInfo"].DefaultView[0]["TableDescription"].ToString();
//初始化列信息
foreach (DataColumn dc in ds.Tables[tableName].Columns)
{
var drNew = this._ds.Tables[infoTable].NewRow();
var rows = ds.Tables["ColumnDescInfo"].Select($"FieldName='{dc.ColumnName}'");
drNew["FieldName"] = dc.ColumnName;
drNew["Description"] = rows[0]["Description"];
drNew["ColumnType"] = rows[0]["ColumnType"].ToString().ToUpper();
drNew["IsNotNull"] = rows[0]["IsNotNull"];
drNew["IsPrimaryKey"] = ds.Tables[tableName].PrimaryKey.Contains(dc);
drNew["IsAutoIncrement"] = dc.AutoIncrement;
drNew["DefaultValue"] = rows[0]["DefaultValue"];
drNew.EndEdit();
this._ds.Tables[infoTable].Rows.Add(drNew);
}
}
catch (Exception ex)
{
Utils.Tip("初始化列信息出错!\r\n" + ex.Message);
}
}
#region 待开发:查询指定表的列与描述信息 #region 待开发:查询指定表的列与描述信息
......
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