Commit 2f02f6f2 authored by tr's avatar tr

1、模块管理:生成SQL脚本功能(待优化)

parent 002ee8ba
Tools/Resources/sql.png

1.15 KB | W: | H:

Tools/Resources/sql.png

725 Bytes | W: | H:

Tools/Resources/sql.png
Tools/Resources/sql.png
Tools/Resources/sql.png
Tools/Resources/sql.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -309,9 +309,6 @@
<ItemGroup>
<None Include="Resources\数据库.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\sql.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\类.png" />
</ItemGroup>
......@@ -361,5 +358,8 @@
<ItemGroup>
<None Include="Resources\删 除.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\SQL.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -31,11 +31,6 @@
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(wModuleManager));
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.tsbAdd = new System.Windows.Forms.ToolStripButton();
this.tsbCopy = new System.Windows.Forms.ToolStripButton();
this.tsbDel = new System.Windows.Forms.ToolStripButton();
this.tsbSave = new System.Windows.Forms.ToolStripButton();
this.tsbDbSetting = new System.Windows.Forms.ToolStripButton();
this.tslDbLinkString = new System.Windows.Forms.ToolStripLabel();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tvModules = new System.Windows.Forms.TreeView();
......@@ -47,6 +42,7 @@
this.dgvDetail = new System.Windows.Forms.DataGridView();
this.cmsDetail = new System.Windows.Forms.ContextMenuStrip(this.components);
this.tsmiAdd = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiCopy = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiDel = new System.Windows.Forms.ToolStripMenuItem();
this.tsFuncInfo = new System.Windows.Forms.ToolStrip();
this.toolStripLabel2 = new System.Windows.Forms.ToolStripLabel();
......@@ -76,7 +72,12 @@
this.ckCanPassLevelReport = new System.Windows.Forms.CheckBox();
this.tbSysCode = new System.Windows.Forms.TextBox();
this.tbPrevID = new System.Windows.Forms.TextBox();
this.tsmiCopy = new System.Windows.Forms.ToolStripMenuItem();
this.tsbAdd = new System.Windows.Forms.ToolStripButton();
this.tsbCopy = new System.Windows.Forms.ToolStripButton();
this.tsbDel = new System.Windows.Forms.ToolStripButton();
this.tsbSave = new System.Windows.Forms.ToolStripButton();
this.tsbGenSQL = new System.Windows.Forms.ToolStripButton();
this.tsbDbSetting = new System.Windows.Forms.ToolStripButton();
this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
......@@ -97,6 +98,7 @@
this.tsbCopy,
this.tsbDel,
this.tsbSave,
this.tsbGenSQL,
this.tsbDbSetting,
this.tslDbLinkString});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
......@@ -105,46 +107,6 @@
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
// tsbAdd
//
this.tsbAdd.Image = global::Tools.Properties.Resources.新增;
this.tsbAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbAdd.Name = "tsbAdd";
this.tsbAdd.Size = new System.Drawing.Size(52, 22);
this.tsbAdd.Text = "新增";
//
// tsbCopy
//
this.tsbCopy.Image = global::Tools.Properties.Resources.复制;
this.tsbCopy.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbCopy.Name = "tsbCopy";
this.tsbCopy.Size = new System.Drawing.Size(52, 22);
this.tsbCopy.Text = "复制";
//
// tsbDel
//
this.tsbDel.Image = ((System.Drawing.Image)(resources.GetObject("tsbDel.Image")));
this.tsbDel.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbDel.Name = "tsbDel";
this.tsbDel.Size = new System.Drawing.Size(52, 22);
this.tsbDel.Text = "删除";
//
// tsbSave
//
this.tsbSave.Image = global::Tools.Properties.Resources.保存;
this.tsbSave.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbSave.Name = "tsbSave";
this.tsbSave.Size = new System.Drawing.Size(52, 22);
this.tsbSave.Text = "保存";
//
// tsbDbSetting
//
this.tsbDbSetting.Image = global::Tools.Properties.Resources.数据库;
this.tsbDbSetting.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbDbSetting.Name = "tsbDbSetting";
this.tsbDbSetting.Size = new System.Drawing.Size(64, 22);
this.tsbDbSetting.Text = "数据库";
//
// tslDbLinkString
//
this.tslDbLinkString.AutoSize = false;
......@@ -302,18 +264,24 @@
this.tsmiCopy,
this.tsmiDel});
this.cmsDetail.Name = "cmsDetail";
this.cmsDetail.Size = new System.Drawing.Size(181, 92);
this.cmsDetail.Size = new System.Drawing.Size(101, 70);
//
// tsmiAdd
//
this.tsmiAdd.Name = "tsmiAdd";
this.tsmiAdd.Size = new System.Drawing.Size(180, 22);
this.tsmiAdd.Size = new System.Drawing.Size(100, 22);
this.tsmiAdd.Text = "増行";
//
// tsmiCopy
//
this.tsmiCopy.Name = "tsmiCopy";
this.tsmiCopy.Size = new System.Drawing.Size(100, 22);
this.tsmiCopy.Text = "复制";
//
// tsmiDel
//
this.tsmiDel.Name = "tsmiDel";
this.tsmiDel.Size = new System.Drawing.Size(180, 22);
this.tsmiDel.Size = new System.Drawing.Size(100, 22);
this.tsmiDel.Text = "删行";
//
// tsFuncInfo
......@@ -586,11 +554,53 @@
this.tbPrevID.Size = new System.Drawing.Size(97, 21);
this.tbPrevID.TabIndex = 28;
//
// tsmiCopy
// tsbAdd
//
this.tsmiCopy.Name = "tsmiCopy";
this.tsmiCopy.Size = new System.Drawing.Size(180, 22);
this.tsmiCopy.Text = "复制";
this.tsbAdd.Image = global::Tools.Properties.Resources.新增;
this.tsbAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbAdd.Name = "tsbAdd";
this.tsbAdd.Size = new System.Drawing.Size(52, 22);
this.tsbAdd.Text = "新增";
//
// tsbCopy
//
this.tsbCopy.Image = global::Tools.Properties.Resources.复制;
this.tsbCopy.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbCopy.Name = "tsbCopy";
this.tsbCopy.Size = new System.Drawing.Size(52, 22);
this.tsbCopy.Text = "复制";
//
// tsbDel
//
this.tsbDel.Image = global::Tools.Properties.Resources.删除;
this.tsbDel.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbDel.Name = "tsbDel";
this.tsbDel.Size = new System.Drawing.Size(52, 22);
this.tsbDel.Text = "删除";
//
// tsbSave
//
this.tsbSave.Image = global::Tools.Properties.Resources.保存;
this.tsbSave.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbSave.Name = "tsbSave";
this.tsbSave.Size = new System.Drawing.Size(52, 22);
this.tsbSave.Text = "保存";
//
// tsbGenSQL
//
this.tsbGenSQL.Image = global::Tools.Properties.Resources.sql;
this.tsbGenSQL.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbGenSQL.Name = "tsbGenSQL";
this.tsbGenSQL.Size = new System.Drawing.Size(99, 22);
this.tsbGenSQL.Text = "生成SQL脚本";
//
// tsbDbSetting
//
this.tsbDbSetting.Image = global::Tools.Properties.Resources.数据库;
this.tsbDbSetting.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbDbSetting.Name = "tsbDbSetting";
this.tsbDbSetting.Size = new System.Drawing.Size(64, 22);
this.tsbDbSetting.Text = "数据库";
//
// wModuleManager
//
......@@ -673,5 +683,6 @@
private System.Windows.Forms.ToolStripMenuItem tsmiAdd;
private System.Windows.Forms.ToolStripMenuItem tsmiDel;
private System.Windows.Forms.ToolStripMenuItem tsmiCopy;
private System.Windows.Forms.ToolStripButton tsbGenSQL;
}
}
\ No newline at end of file
......@@ -56,6 +56,7 @@ namespace Tools.UI
this.tsbCopy.Click += TsbCopy_Click;
this.tsbDel.Click += TsbDel_Click;
this.tsbSave.Click += TsbSave_Click;
this.tsbGenSQL.Click += TsbGenSQL_Click;
this.tsbDbSetting.Click += TsbDbSetting_Click;
//上下文菜单事件
this.tsmiAdd.Click += TsmiAdd_Click;
......@@ -67,7 +68,7 @@ namespace Tools.UI
{
base.InitData();
this.ModuleTableList = new List<TQuery> {
this.ModuleTableList = new List<TQuery> {
new TQuery("SysBusinessModel"),
new TQuery("SysFunction"),
};
......@@ -129,6 +130,63 @@ namespace Tools.UI
{
this.Save();
}
private void TsbGenSQL_Click(object sender, EventArgs e)
{
//模块表
DataRow drMaster = this.GetCurrentNodeRow();
var colist = this.GetTableColumns(this._dtModel);
var model = $@"
INSERT INTO {this._dtModel.TableName}
{this.GenColumns(colist)}
VALUES
{this.GenValues(drMaster, colist)}
";
//功能表
var funcColist = this.GetTableColumns(this._dtDetail);
var values = this._dtDetail.DefaultView.Cast<DataRowView>().Select(r => this.GenValues(r.Row, funcColist));
var detail = $@"
INSERT INTO {this._dtDetail.TableName}
{this.GenColumns(funcColist)}
VALUES
{string.Join(",\r\n", values)}
";
var result = $@"
IF NOT EXISTS (SELECT 1 FROM SysBusinessModel WHERE Name = '{this.tbName.Text}')
BEGIN
{model}
DECLARE @ModelID INT
SET @ModelID=SCOPE_IDENTITY();
{detail}
END";
Utils.Tip(result, 800, 600);
}
private string GenColumns(List<string> colist)
{
return $"({string.Join(", ", colist)})";
}
private string GenValues(DataRow dr, List<string> colist)
{
var valist = colist.Select(col => col.ToLower().Equals("modelid") ? "@ModelID" : $"'{dr[col].ToString()}'");
return $"({string.Join(", ", valist)})";
}
private List<string> GetTableColumns(DataTable dt)
{
var result = new List<string>();
dt.Columns.Cast<DataColumn>().ToList().ForEach(c =>
{
if (!c.AutoIncrement)
{
result.Add(c.ColumnName);
}
});
return result;
}
#endregion
#region 上下文菜单事件
......
......@@ -120,22 +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>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="tsbDel.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="imgList5.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>634, 18</value>
</metadata>
......@@ -144,7 +128,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADo
CAAAAk1TRnQBSQFMAgEBAgEAAUABAAFAAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAXABAAFwAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
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