Commit 246bd131 authored by tr's avatar tr

1、数据库开发工具:增加系统配置

parent b9c32a0b
No preview for this file type
No preview for this file type
......@@ -21,11 +21,19 @@
</xs:element>
</xs:schema>
<AppSetting>
<Name>LinkString</Name>
<Name>DefaultLink</Name>
<Value>Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Temp;Data Source=.</Value>
</AppSetting>
<AppSetting>
<Name>ExportPath</Name>
<Value />
<Name>ModelExportPath</Name>
<Value>D:\source\Ftt_Common\AppHome\temp</Value>
</AppSetting>
<AppSetting>
<Name>SqlExportPath</Name>
<Value>D:\source\Ftt_Common\AppHome\temp</Value>
</AppSetting>
<AppSetting>
<Name>DocExportPath</Name>
<Value>D:\source\Ftt_Common\AppHome\temp</Value>
</AppSetting>
</NewDataSet>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tools.MyCommon
{
/// <summary>
/// 配置类型
/// </summary>
public class ConfigType
{
/// <summary>
/// 默认数据库链接
/// </summary>
public static string DefaultLink => "DefaultLink";
/// <summary>
/// 默认模型类导出路径
/// </summary>
public static string ModelExportPath => "ModelExportPath";
/// <summary>
/// 默认SQL文件导出路径
/// </summary>
public static string SqlExportPath => "SqlExportPath";
/// <summary>
/// 默认Excel/Word文件导出路径
/// </summary>
public static string DocExportPath => "DocExportPath";
}
/// <summary>
/// 导出类型
/// </summary>
public class ExportType
{
/// <summary>
/// 模型类
/// </summary>
public static string Model => "Model";
/// <summary>
/// SQL文件
/// </summary>
public static string Sql => "Sql";
/// <summary>
/// Excel/Word文件
/// </summary>
public static string Doc => "Doc";
}
}
......@@ -27,6 +27,10 @@ namespace Tools.MyUtils
/// </summary>
public static string ConfigPath => $@"{Application.StartupPath}\config";
/// <summary>
/// 系统配置文件路径
/// </summary>
public static string SysConfigFilePath = $@"{Utils.ConfigPath}\sys_cfg.xml";
/// <summary>
/// 日志目录
/// </summary>
public static string LogPath => $@"{Application.StartupPath}\log";
......
namespace Tools.MyUtils
{
partial class wSysSetting
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnSelectDocPath = new System.Windows.Forms.Button();
this.btnSelectSqlPath = new System.Windows.Forms.Button();
this.btnSelectModelPath = new System.Windows.Forms.Button();
this.tbDocExportPath = new System.Windows.Forms.TextBox();
this.tbSqlExportPath = new System.Windows.Forms.TextBox();
this.tbModelExportPath = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.tbDefaultLink = new System.Windows.Forms.TextBox();
this.btnSelectDbLink = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(37, 27);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(77, 12);
this.label1.TabIndex = 0;
this.label1.Text = "默认数据库:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(30, 63);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(0, 12);
this.label2.TabIndex = 1;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btnSelectDocPath);
this.groupBox1.Controls.Add(this.btnSelectSqlPath);
this.groupBox1.Controls.Add(this.btnSelectModelPath);
this.groupBox1.Controls.Add(this.tbDocExportPath);
this.groupBox1.Controls.Add(this.tbSqlExportPath);
this.groupBox1.Controls.Add(this.tbModelExportPath);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Location = new System.Drawing.Point(30, 63);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(372, 137);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "默认导出路径配置";
//
// btnSelectDocPath
//
this.btnSelectDocPath.Location = new System.Drawing.Point(342, 89);
this.btnSelectDocPath.Name = "btnSelectDocPath";
this.btnSelectDocPath.Size = new System.Drawing.Size(24, 23);
this.btnSelectDocPath.TabIndex = 8;
this.btnSelectDocPath.Text = "…";
this.btnSelectDocPath.UseVisualStyleBackColor = true;
//
// btnSelectSqlPath
//
this.btnSelectSqlPath.Location = new System.Drawing.Point(342, 61);
this.btnSelectSqlPath.Name = "btnSelectSqlPath";
this.btnSelectSqlPath.Size = new System.Drawing.Size(24, 23);
this.btnSelectSqlPath.TabIndex = 7;
this.btnSelectSqlPath.Text = "…";
this.btnSelectSqlPath.UseVisualStyleBackColor = true;
//
// btnSelectModelPath
//
this.btnSelectModelPath.Location = new System.Drawing.Point(342, 33);
this.btnSelectModelPath.Name = "btnSelectModelPath";
this.btnSelectModelPath.Size = new System.Drawing.Size(24, 23);
this.btnSelectModelPath.TabIndex = 6;
this.btnSelectModelPath.Text = "…";
this.btnSelectModelPath.UseVisualStyleBackColor = true;
//
// tbDocExportPath
//
this.tbDocExportPath.Location = new System.Drawing.Point(162, 90);
this.tbDocExportPath.Name = "tbDocExportPath";
this.tbDocExportPath.Size = new System.Drawing.Size(179, 21);
this.tbDocExportPath.TabIndex = 5;
//
// tbSqlExportPath
//
this.tbSqlExportPath.Location = new System.Drawing.Point(162, 62);
this.tbSqlExportPath.Name = "tbSqlExportPath";
this.tbSqlExportPath.Size = new System.Drawing.Size(179, 21);
this.tbSqlExportPath.TabIndex = 4;
//
// tbModelExportPath
//
this.tbModelExportPath.Location = new System.Drawing.Point(162, 34);
this.tbModelExportPath.Name = "tbModelExportPath";
this.tbModelExportPath.Size = new System.Drawing.Size(179, 21);
this.tbModelExportPath.TabIndex = 3;
//
// label5
//
this.label5.Location = new System.Drawing.Point(7, 93);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(149, 12);
this.label5.TabIndex = 2;
this.label5.Text = "Excel/Word默认导出路径:";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label4
//
this.label4.Location = new System.Drawing.Point(6, 65);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(150, 12);
this.label4.TabIndex = 1;
this.label4.Text = "SQL文件默认导出路径:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(6, 37);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(150, 12);
this.label3.TabIndex = 0;
this.label3.Text = "模型类默认导出路径:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// tbDefaultLink
//
this.tbDefaultLink.Enabled = false;
this.tbDefaultLink.Location = new System.Drawing.Point(120, 24);
this.tbDefaultLink.Name = "tbDefaultLink";
this.tbDefaultLink.ReadOnly = true;
this.tbDefaultLink.Size = new System.Drawing.Size(190, 21);
this.tbDefaultLink.TabIndex = 3;
//
// btnSelectDbLink
//
this.btnSelectDbLink.Location = new System.Drawing.Point(316, 22);
this.btnSelectDbLink.Name = "btnSelectDbLink";
this.btnSelectDbLink.Size = new System.Drawing.Size(86, 23);
this.btnSelectDbLink.TabIndex = 4;
this.btnSelectDbLink.Text = "选择数据库";
this.btnSelectDbLink.UseVisualStyleBackColor = true;
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(180, 216);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(88, 23);
this.btnSave.TabIndex = 5;
this.btnSave.Text = "保存配置";
this.btnSave.UseVisualStyleBackColor = true;
//
// wSysSetting
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(433, 256);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.btnSelectDbLink);
this.Controls.Add(this.tbDefaultLink);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "wSysSetting";
this.Text = "系统配置";
this.Load += new System.EventHandler(this.wSysSetting_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox tbDocExportPath;
private System.Windows.Forms.TextBox tbSqlExportPath;
private System.Windows.Forms.TextBox tbModelExportPath;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tbDefaultLink;
private System.Windows.Forms.Button btnSelectDbLink;
private System.Windows.Forms.Button btnSelectDocPath;
private System.Windows.Forms.Button btnSelectSqlPath;
private System.Windows.Forms.Button btnSelectModelPath;
private System.Windows.Forms.Button btnSave;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
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
{
public partial class wSysSetting : wBasic
{
DataTable dtSetting = null;
DbItemModel LinkModel = null;
public wSysSetting()
{
InitializeComponent();
//
this.DialogResult = DialogResult.None;
}
private void wSysSetting_Load(object sender, EventArgs e)
{
//读取设置信息
dtSetting = new DataTable("AppSetting");
dtSetting.ReadXml(Utils.SysConfigFilePath);
//填充界面
var linkString = this.GetValue(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.btnSelectDbLink.Click += BtnSelectDbLink_Click;
this.btnSelectModelPath.Click += BtnSelectModelPath_Click;
this.btnSelectSqlPath.Click += BtnSelectSqlPath_Click;
this.btnSelectDocPath.Click += BtnSelectDocPath_Click;
this.btnSave.Click += BtnSave_Click;
}
private void BtnSelectDbLink_Click(object sender, EventArgs e)
{
var frm = new wDbSetting();
if (frm.ShowDialog() == DialogResult.OK)
{
this.LinkModel = frm.LinkModel;
this.tbDefaultLink.Text = this.LinkModel.ToString();
}
}
private void BtnSelectModelPath_Click(object sender, EventArgs e)
{
var frm = new FolderBrowserDialog();
if (frm.ShowDialog() == DialogResult.OK)
{
this.tbModelExportPath.Text = frm.SelectedPath;
}
}
private void BtnSelectSqlPath_Click(object sender, EventArgs e)
{
var frm = new FolderBrowserDialog();
if (frm.ShowDialog() == DialogResult.OK)
{
this.tbSqlExportPath.Text = frm.SelectedPath;
}
}
private void BtnSelectDocPath_Click(object sender, EventArgs e)
{
var frm = new FolderBrowserDialog();
if (frm.ShowDialog() == DialogResult.OK)
{
this.tbDocExportPath.Text = frm.SelectedPath;
}
}
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);
//保存设置
dtSetting.WriteXml(Utils.SysConfigFilePath, XmlWriteMode.WriteSchema);
this.DialogResult = DialogResult.OK;
}
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;
}
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();
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
......@@ -199,5 +199,15 @@ namespace Tools.Properties {
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 设置 {
get {
object obj = ResourceManager.GetObject("设置", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
......@@ -160,4 +160,7 @@
<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">
<value>..\Resources\设置.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
\ No newline at end of file
......@@ -64,6 +64,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyCommon\Common.cs" />
<Compile Include="MyCommon\wBasic.cs">
<SubType>Form</SubType>
</Compile>
......@@ -86,6 +87,12 @@
<Compile Include="MyUtils\wMsgBox.Designer.cs">
<DependentUpon>wMsgBox.cs</DependentUpon>
</Compile>
<Compile Include="MyUtils\wSysSetting.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MyUtils\wSysSetting.Designer.cs">
<DependentUpon>wSysSetting.cs</DependentUpon>
</Compile>
<Compile Include="UI\wDbAnlysis.cs">
<SubType>Form</SubType>
</Compile>
......@@ -116,6 +123,9 @@
<EmbeddedResource Include="MyUtils\wMsgBox.resx">
<DependentUpon>wMsgBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MyUtils\wSysSetting.resx">
<DependentUpon>wSysSetting.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
......@@ -201,5 +211,8 @@
<ItemGroup>
<None Include="Resources\加载.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\设置.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -30,21 +30,11 @@
{
this.components = new System.ComponentModel.Container();
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.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
this.tsbLoadTable = new System.Windows.Forms.ToolStripButton();
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.tsbDbLink = new System.Windows.Forms.ToolStripButton();
this.tstbDbLink = new System.Windows.Forms.ToolStripTextBox();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.tsbHelp = new System.Windows.Forms.ToolStripButton();
this.dgvData = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
......@@ -61,6 +51,18 @@
this.label2 = new System.Windows.Forms.Label();
this.tbTableName = new System.Windows.Forms.TextBox();
this.tbTableDescription = new System.Windows.Forms.TextBox();
this.toolStripSeparator5 = 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.tsbSysSetting = new System.Windows.Forms.ToolStripButton();
this.tsbHelp = new System.Windows.Forms.ToolStripButton();
this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvData)).BeginInit();
this.contextMenuStrip1.SuspendLayout();
......@@ -79,6 +81,8 @@
this.toolStripSeparator1,
this.tsbDbLink,
this.tstbDbLink,
this.toolStripSeparator5,
this.tsbSysSetting,
this.toolStripSeparator3,
this.tsbHelp});
this.toolStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
......@@ -88,94 +92,21 @@
this.toolStrip1.TabIndex = 0;
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";
//
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(6, 23);
//
// 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 = "加载表信息";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
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
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
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
//
this.tstbDbLink.Enabled = false;
......@@ -188,14 +119,6 @@
this.toolStripSeparator3.Name = "toolStripSeparator3";
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
//
this.dgvData.BackgroundColor = System.Drawing.SystemColors.Window;
......@@ -366,6 +289,100 @@
this.tbTableDescription.Size = new System.Drawing.Size(152, 23);
this.tbTableDescription.TabIndex = 5;
//
// toolStripSeparator5
//
this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.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(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";
//
// 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 = "数据库配置";
//
// tsbSysSetting
//
this.tsbSysSetting.Image = global::Tools.Properties.Resources.设置;
this.tsbSysSetting.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbSysSetting.Name = "tsbSysSetting";
this.tsbSysSetting.Size = new System.Drawing.Size(76, 21);
this.tsbSysSetting.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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
......@@ -423,5 +440,7 @@
private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
private System.Windows.Forms.ToolStripButton tsbLoadTable;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
private System.Windows.Forms.ToolStripButton tsbSysSetting;
}
}
\ No newline at end of file
......@@ -18,8 +18,6 @@ namespace Tools.UI
{
public partial class wDBTools : wBasic
{
string ConfigPath = $@"{Utils.ConfigPath}\sys_cfg.xml";
/// <summary>
/// 数据库访问对象
/// </summary>
......@@ -67,34 +65,30 @@ namespace Tools.UI
private void InitSystem()
{
DataTable dtSetting = null;
if (File.Exists(this.ConfigPath))
{
dtSetting = new DataTable("AppSetting");
dtSetting.ReadXml(this.ConfigPath);
}
else
if(!File.Exists(Utils.SysConfigFilePath))
{
#region 结构初始化
dtSetting = new DataTable("AppSetting")
var dtSetting = new DataTable("AppSetting")
{
Columns = {
{ "Name", typeof(string) },
{ "Value", typeof(string) },
},
Rows = {
{ "LinkString", "Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Temp;Data Source=." },
{ "ExportPath", "" },
{ ConfigType.DefaultLink, "Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Temp;Data Source=." },
{ ConfigType.ModelExportPath, Utils.TempPath },
{ ConfigType.SqlExportPath, Utils.TempPath },
{ ConfigType.DocExportPath, Utils.TempPath },
},
};
dtSetting.PrimaryKey = new DataColumn[] { dtSetting.Columns[0] };
dtSetting.WriteXml(this.ConfigPath, XmlWriteMode.WriteSchema);
dtSetting.WriteXml(Utils.SysConfigFilePath, XmlWriteMode.WriteSchema);
#endregion
}
//保存到全局字典对象
dicConfig = dtSetting.Rows.Cast<DataRow>().ToDictionary(x => x["Name"].ToString(), x => x["Value"].ToString());
this.SetConfig();
}
private void InitData()
{
......@@ -131,9 +125,6 @@ namespace Tools.UI
}
private void InitUI()
{
//初始化数据库链接
this._link = dicConfig["LinkString"];
this.tstbDbLink.Text = Utils.GetDbItemModel(this._link).ToString();
//基本信息绑定
this.BindBaseInfo();
//系统路径初始化
......@@ -154,13 +145,13 @@ namespace Tools.UI
this.tsbTempSave.Click += TsbTempSave_Click;
this.tsbResume.Click += TsbResume_Click;
this.tsbDbLink.Click += TsbDbLink_Click;
this.tsbSysSetting.Click += TsbSysSetting_Click;
this.tsbHelp.Click += TsbHelp_Click;
//上下文菜单-事件
this.tsmiAddRow.Click += TsmiAddRow_Click;
this.tsmiDelRow.Click += TsmiDelRow_Click;
}
private void BindBaseInfo()
{
this.tbTableName.DataBindings.Clear();
......@@ -208,7 +199,7 @@ namespace Tools.UI
var body = Utils.GenModelBody(this._ds.Tables[infoTable]);
var tail = Utils.GenModelTail();
var model = $"{head}\r\n{body}\r\n{tail}";
var modelFileName = $@"{this.GetExportPath()}\{this.TableName}.cs";
var modelFileName = $@"{this.GetExportPath(ExportType.Model)}\{this.TableName}.cs";
using (var fs = new FileStream(modelFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
{
var bytes = Encoding.UTF8.GetBytes(model);
......@@ -242,7 +233,7 @@ namespace Tools.UI
var body = Utils.GenSqlBody(this._ds.Tables[infoTable], this.TableName, this.TableDescription, out List<string> descripionList);
var tail = Utils.GenSqlTail();
var sql = $"{head}\r\n{body}\r\n{tail}\r\n{string.Join(";\r\n", descripionList)}";
var sqlFileName = $@"{this.GetExportPath()}\{this.TableName}.sql";
var sqlFileName = $@"{this.GetExportPath(ExportType.Sql)}\{this.TableName}.sql";
using (var fs = new FileStream(sqlFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
{
var bytes = Encoding.UTF8.GetBytes(sql);
......@@ -264,7 +255,7 @@ namespace Tools.UI
{
if (!this.CheckDetail())
return;
new NPOIExcelHelper().Export(this._ds, $@"{Utils.ConfigPath}\模板.xlsx", $@"{this.GetExportPath()}\{this.TableName}.xlsx");
new NPOIExcelHelper().Export(this._ds, $@"{Utils.ConfigPath}\模板.xlsx", $@"{this.GetExportPath(ExportType.Doc)}\{this.TableName}.xlsx");
}
private void TsmiExportWord_Click(object sender, EventArgs e)
{
......@@ -279,7 +270,7 @@ namespace Tools.UI
this._ds.Tables[infoTable].Columns[fieldName].Caption = col.HeaderText;
}
//导出Word
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(ExportType.Doc)}\{this.TableName}.docx");
}
private void TsbLoadTable_Click(object sender, EventArgs e)
......@@ -334,6 +325,16 @@ namespace Tools.UI
this.tstbDbLink.Text = w.LinkModel.ToString();
}
}
private void TsbSysSetting_Click(object sender, EventArgs e)
{
var frm = new wSysSetting();
if (frm.ShowDialog() == DialogResult.OK)
{
this.SetConfig();
}
}
private void TsbHelp_Click(object sender, EventArgs e)
{
var helpFileName = $@"{Utils.ConfigPath}\help.txt";
......@@ -413,6 +414,20 @@ namespace Tools.UI
return true;
}
/// <summary>
/// 设置配置信息
/// </summary>
private void SetConfig()
{
//读取配置信息
var dtSetting = new DataTable("AppSetting");
dtSetting.ReadXml(Utils.SysConfigFilePath);
//保存到全局字典对象
this.dicConfig = dtSetting.Rows.Cast<DataRow>().ToDictionary(x => x["Name"].ToString(), x => x["Value"].ToString());
//初始化数据库链接
this._link = dicConfig["DefaultLink"];
this.tstbDbLink.Text = Utils.GetDbItemModel(this._link).ToString();
}
/// <summary>
/// 创建明细新行
/// </summary>
/// <returns></returns>
......@@ -431,12 +446,12 @@ namespace Tools.UI
/// 获取导出路径
/// </summary>
/// <returns></returns>
private string GetExportPath()
private string GetExportPath(string exType)
{
string path = "";
if (dicConfig != null)
{
path = dicConfig["ExportPath"]?.Trim();
path = dicConfig[$"{exType}ExportPath"]?.Trim();
}
if (string.IsNullOrEmpty(path))
{
......@@ -444,6 +459,7 @@ namespace Tools.UI
}
return path;
}
/// <summary>
/// 初始化SQL依赖
/// </summary>
......@@ -489,6 +505,7 @@ namespace Tools.UI
Directory.CreateDirectory(path);
}
}
/// <summary>
/// 是否存在表
/// </summary>
......@@ -561,6 +578,8 @@ namespace Tools.UI
}
}
#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