Commit 37fd764b authored by tr's avatar tr

1、XML生成器:从PDM迁移并优化

parent 16d4ed76
......@@ -178,6 +178,12 @@
<Compile Include="UI\wSysChecker.Designer.cs">
<DependentUpon>wSysChecker.cs</DependentUpon>
</Compile>
<Compile Include="UI\wXmlGenerator.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\wXmlGenerator.Designer.cs">
<DependentUpon>wXmlGenerator.cs</DependentUpon>
</Compile>
<Compile Include="wExtend.cs" />
<Compile Include="wMain.cs">
<SubType>Form</SubType>
......@@ -246,6 +252,9 @@
<EmbeddedResource Include="UI\wSysChecker.resx">
<DependentUpon>wSysChecker.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\wXmlGenerator.resx">
<DependentUpon>wXmlGenerator.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="wMain.resx">
<DependentUpon>wMain.cs</DependentUpon>
<SubType>Designer</SubType>
......
namespace Tools.UI
{
partial class wXmlGenerator
{
/// <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.panelHeader = new System.Windows.Forms.Panel();
this.lbLinkString = new System.Windows.Forms.Label();
this.btnConfig = new System.Windows.Forms.Button();
this.txtTableName = new System.Windows.Forms.TextBox();
this.labProduct = new System.Windows.Forms.Label();
this.btnGetColumns = new System.Windows.Forms.Button();
this.tabCtrSelf = new System.Windows.Forms.TabControl();
this.tabXmSetting = new System.Windows.Forms.TabPage();
this.dgvDetail = new System.Windows.Forms.DataGridView();
this.tabXmlText = new System.Windows.Forms.TabPage();
this.txtXml = new System.Windows.Forms.TextBox();
this.btnBuildXml = new System.Windows.Forms.Button();
this.panelFooter = new System.Windows.Forms.Panel();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column4 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.Column5 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column8 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.Column9 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.Column10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column11 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.Column12 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.Column13 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.panelHeader.SuspendLayout();
this.tabCtrSelf.SuspendLayout();
this.tabXmSetting.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvDetail)).BeginInit();
this.tabXmlText.SuspendLayout();
this.panelFooter.SuspendLayout();
this.SuspendLayout();
//
// panelHeader
//
this.panelHeader.Controls.Add(this.lbLinkString);
this.panelHeader.Controls.Add(this.btnConfig);
this.panelHeader.Controls.Add(this.txtTableName);
this.panelHeader.Controls.Add(this.labProduct);
this.panelHeader.Controls.Add(this.btnGetColumns);
this.panelHeader.Dock = System.Windows.Forms.DockStyle.Top;
this.panelHeader.Location = new System.Drawing.Point(0, 0);
this.panelHeader.Name = "panelHeader";
this.panelHeader.Size = new System.Drawing.Size(800, 47);
this.panelHeader.TabIndex = 8;
//
// lbLinkString
//
this.lbLinkString.ForeColor = System.Drawing.Color.Green;
this.lbLinkString.Location = new System.Drawing.Point(613, 12);
this.lbLinkString.Name = "lbLinkString";
this.lbLinkString.Size = new System.Drawing.Size(174, 23);
this.lbLinkString.TabIndex = 356;
this.lbLinkString.Text = "请先配置数据库链接";
this.lbLinkString.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// btnConfig
//
this.btnConfig.Location = new System.Drawing.Point(518, 12);
this.btnConfig.Name = "btnConfig";
this.btnConfig.Size = new System.Drawing.Size(89, 23);
this.btnConfig.TabIndex = 355;
this.btnConfig.Text = "配置数据库";
this.btnConfig.UseVisualStyleBackColor = true;
//
// txtTableName
//
this.txtTableName.Location = new System.Drawing.Point(78, 14);
this.txtTableName.Name = "txtTableName";
this.txtTableName.Size = new System.Drawing.Size(192, 21);
this.txtTableName.TabIndex = 354;
//
// labProduct
//
this.labProduct.Location = new System.Drawing.Point(12, 14);
this.labProduct.Name = "labProduct";
this.labProduct.Size = new System.Drawing.Size(60, 18);
this.labProduct.TabIndex = 338;
this.labProduct.Text = "XML名称:";
this.labProduct.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnGetColumns
//
this.btnGetColumns.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnGetColumns.ForeColor = System.Drawing.Color.Black;
this.btnGetColumns.Location = new System.Drawing.Point(323, 12);
this.btnGetColumns.Name = "btnGetColumns";
this.btnGetColumns.Size = new System.Drawing.Size(140, 23);
this.btnGetColumns.TabIndex = 6;
this.btnGetColumns.Text = "获取表的列配置信息";
this.btnGetColumns.UseVisualStyleBackColor = true;
//
// tabCtrSelf
//
this.tabCtrSelf.Controls.Add(this.tabXmSetting);
this.tabCtrSelf.Controls.Add(this.tabXmlText);
this.tabCtrSelf.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabCtrSelf.Location = new System.Drawing.Point(0, 47);
this.tabCtrSelf.Name = "tabCtrSelf";
this.tabCtrSelf.SelectedIndex = 0;
this.tabCtrSelf.Size = new System.Drawing.Size(800, 421);
this.tabCtrSelf.TabIndex = 9;
//
// tabXmSetting
//
this.tabXmSetting.Controls.Add(this.dgvDetail);
this.tabXmSetting.Location = new System.Drawing.Point(4, 22);
this.tabXmSetting.Name = "tabXmSetting";
this.tabXmSetting.Size = new System.Drawing.Size(792, 395);
this.tabXmSetting.TabIndex = 0;
this.tabXmSetting.Text = "数据配置";
//
// dgvDetail
//
this.dgvDetail.BackgroundColor = System.Drawing.SystemColors.Window;
this.dgvDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column2,
this.Column3,
this.Column4,
this.Column5,
this.Column6,
this.Column7,
this.Column8,
this.Column9,
this.Column10,
this.Column11,
this.Column12,
this.Column13});
this.dgvDetail.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgvDetail.GridColor = System.Drawing.SystemColors.AppWorkspace;
this.dgvDetail.Location = new System.Drawing.Point(0, 0);
this.dgvDetail.Name = "dgvDetail";
this.dgvDetail.RowTemplate.Height = 23;
this.dgvDetail.Size = new System.Drawing.Size(792, 395);
this.dgvDetail.TabIndex = 12;
//
// tabXmlText
//
this.tabXmlText.Controls.Add(this.txtXml);
this.tabXmlText.Location = new System.Drawing.Point(4, 22);
this.tabXmlText.Name = "tabXmlText";
this.tabXmlText.Size = new System.Drawing.Size(792, 395);
this.tabXmlText.TabIndex = 1;
this.tabXmlText.Text = "XML文本";
this.tabXmlText.UseVisualStyleBackColor = true;
//
// txtXml
//
this.txtXml.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtXml.Location = new System.Drawing.Point(0, 0);
this.txtXml.MaxLength = 32767000;
this.txtXml.Multiline = true;
this.txtXml.Name = "txtXml";
this.txtXml.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtXml.Size = new System.Drawing.Size(792, 395);
this.txtXml.TabIndex = 0;
//
// btnBuildXml
//
this.btnBuildXml.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnBuildXml.ForeColor = System.Drawing.Color.Black;
this.btnBuildXml.Location = new System.Drawing.Point(357, 9);
this.btnBuildXml.Name = "btnBuildXml";
this.btnBuildXml.Size = new System.Drawing.Size(100, 23);
this.btnBuildXml.TabIndex = 12;
this.btnBuildXml.Text = "生成XML文本";
this.btnBuildXml.UseVisualStyleBackColor = true;
//
// panelFooter
//
this.panelFooter.Controls.Add(this.btnBuildXml);
this.panelFooter.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelFooter.Location = new System.Drawing.Point(0, 468);
this.panelFooter.Name = "panelFooter";
this.panelFooter.Size = new System.Drawing.Size(800, 41);
this.panelFooter.TabIndex = 13;
//
// Column1
//
this.Column1.DataPropertyName = "Name";
this.Column1.HeaderText = "列名";
this.Column1.Name = "Column1";
//
// Column2
//
this.Column2.DataPropertyName = "Description";
this.Column2.HeaderText = "显示名称";
this.Column2.Name = "Column2";
//
// Column3
//
this.Column3.DataPropertyName = "DataType";
this.Column3.HeaderText = "数据类型";
this.Column3.Name = "Column3";
//
// Column4
//
this.Column4.DataPropertyName = "IsNull";
this.Column4.HeaderText = "是否为空";
this.Column4.Name = "Column4";
this.Column4.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.Column4.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
//
// Column5
//
this.Column5.DataPropertyName = "IsKey";
this.Column5.HeaderText = "是否主键";
this.Column5.Name = "Column5";
this.Column5.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.Column5.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
//
// Column6
//
this.Column6.DataPropertyName = "MaxLength";
this.Column6.HeaderText = "最大长度";
this.Column6.Name = "Column6";
//
// Column7
//
this.Column7.DataPropertyName = "ShowWidth";
this.Column7.HeaderText = "显示宽度";
this.Column7.Name = "Column7";
//
// Column8
//
this.Column8.DataPropertyName = "IsVisible";
this.Column8.HeaderText = "是否显示";
this.Column8.Name = "Column8";
this.Column8.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.Column8.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
//
// Column9
//
this.Column9.DataPropertyName = "IsEditHide";
this.Column9.HeaderText = "编辑可见";
this.Column9.Name = "Column9";
this.Column9.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.Column9.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
//
// Column10
//
this.Column10.DataPropertyName = "OrderIndex";
this.Column10.HeaderText = "排序号";
this.Column10.Name = "Column10";
//
// Column11
//
this.Column11.DataPropertyName = "CanEdit";
this.Column11.HeaderText = "是否编辑";
this.Column11.Name = "Column11";
this.Column11.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.Column11.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
//
// Column12
//
this.Column12.DataPropertyName = "CanSort";
this.Column12.HeaderText = "排序字段";
this.Column12.Name = "Column12";
this.Column12.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.Column12.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
//
// Column13
//
this.Column13.DataPropertyName = "SummaryItem";
this.Column13.HeaderText = "合计字段";
this.Column13.Name = "Column13";
this.Column13.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.Column13.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
//
// wXmlGenerator
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 509);
this.Controls.Add(this.tabCtrSelf);
this.Controls.Add(this.panelHeader);
this.Controls.Add(this.panelFooter);
this.Name = "wXmlGenerator";
this.Text = "wXmlGenerator";
this.Load += new System.EventHandler(this.wXmlGenerator_Load);
this.panelHeader.ResumeLayout(false);
this.panelHeader.PerformLayout();
this.tabCtrSelf.ResumeLayout(false);
this.tabXmSetting.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgvDetail)).EndInit();
this.tabXmlText.ResumeLayout(false);
this.tabXmlText.PerformLayout();
this.panelFooter.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panelHeader;
private System.Windows.Forms.TextBox txtTableName;
private System.Windows.Forms.Label labProduct;
private System.Windows.Forms.Button btnGetColumns;
private System.Windows.Forms.TabControl tabCtrSelf;
private System.Windows.Forms.TabPage tabXmSetting;
private System.Windows.Forms.TabPage tabXmlText;
private System.Windows.Forms.TextBox txtXml;
private System.Windows.Forms.Button btnBuildXml;
private System.Windows.Forms.Panel panelFooter;
private System.Windows.Forms.DataGridView dgvDetail;
private System.Windows.Forms.Button btnConfig;
private System.Windows.Forms.Label lbLinkString;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column4;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column5;
private System.Windows.Forms.DataGridViewTextBoxColumn Column6;
private System.Windows.Forms.DataGridViewTextBoxColumn Column7;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column8;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column9;
private System.Windows.Forms.DataGridViewTextBoxColumn Column10;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column11;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column12;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column13;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
//
using Tools.MyCommon;
using Tools.MyUtils;
namespace Tools.UI
{
public partial class wXmlGenerator : wEditBasic
{
/// <summary>
/// 存放xml信息的表
/// </summary>
private DataSet _dsXmlSetting;
/// <summary>
/// 存放xml表名称
/// </summary>
private string _tableName => txtTableName.Text.Trim();
public wXmlGenerator()
{
InitializeComponent();
}
private void wXmlGenerator_Load(object sender, EventArgs e)
{
this.InitUI();
}
public override void InitUI()
{
base.InitUI();
//数据表格初始化
this.dgvDetail.AllowUserToAddRows = false;
this.dgvDetail.AutoGenerateColumns = false;
//添加按钮事件
this.btnConfig.Click += BtnConfig_Click;
this.btnGetColumns.Click += BtnGetColumns_Click; ;
this.btnBuildXml.Click += BtnBuildXml_Click;
}
/// <summary>
/// 按钮事件:配置数据库
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnConfig_Click(object sender, EventArgs e)
{
var frm = new wDbSetting(this.lbLinkString);
if (frm.ShowDialog() == DialogResult.OK)
{
this.InitDBHelper(frm.LinkModel);
}
}
/// <summary>
/// 按钮事件:获取列信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnGetColumns_Click(object sender, EventArgs e)
{
if (this.CheckDbSetting())
return;
//根据表名获取对应的表结构
this._ds = this.GetTableSchema(this._tableName);
if (this._ds == null)
return;
//初始化配置信息表
this._dsXmlSetting = this.InitColumnInfo(this._ds);
//绑定数据源
this.dgvDetail.DataSource = this._dsXmlSetting.Tables[0].DefaultView;
}
/// <summary>
/// 按钮事件:生成MXL文本
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnBuildXml_Click(object sender, EventArgs e)
{
if (this.CheckDbSetting())
return;
//生成Xml对象
var xml = this.GenXmlDocument();
//生成Xml文本
txtXml.Text = ConvertXmlToString(xml);
//选中<Xml文本>选项卡
tabCtrSelf.SelectedTab = tabXmlText;
}
/// <summary>
/// 获取表结构
/// </summary>
/// <param name="tableName"></param>
/// <returns></returns>
private DataSet GetTableSchema(string tableName)
{
DataSet result = null;
try
{
string sql = $"Select * From {tableName} p Where 1=2";
result = this._db.GetData(sql, tableName);
}
catch (Exception ex)
{
Utils.Tip($"xml名称:有误!: {ex.Message}");
}
return result;
}
/// <summary>
/// 初始化配置信息
/// </summary>
/// <param name="tableName"></param>
private DataSet InitColumnInfo(DataSet ds)
{
DataSet result = new DataSet();
#region 初始化XML配置表结构
result.Tables.Add(new DataTable()
{
Columns = {
{ "Name", typeof(string) },
{ "Description", typeof(string) },
{ "DataType", typeof(string) },
{ "IsNull", typeof(bool) },
{ "IsKey", typeof(bool) },
{ "MaxLength", typeof(int) },
{ "ShowWidth", typeof(int) },
{ "IsVisible", typeof(bool)},
{ "IsEditHide", typeof(bool)},
{ "OrderIndex", typeof(int)},
{ "CanEdit", typeof(bool)},
{ "CanSort", typeof(bool)},
{ "SummaryItem", typeof(bool)},
},
});
#endregion
//初始化列属性
ds.Tables[0].Columns.Cast<DataColumn>().ToList()
.ForEach(col => {
bool isKey = ds.Tables[0].PrimaryKey.Contains(col);
var dr = result.Tables[0].NewRow();
dr["Name"] = col.ColumnName;
dr["DataType"] = col.DataType.FullName;
dr["IsNull"] = col.AllowDBNull;
dr["IsKey"] = isKey;
dr["MaxLength"] = col.MaxLength < 0 ? 10 : col.MaxLength;
dr["ShowWidth"] = 100;
dr["IsVisible"] = !isKey;
dr["CanEdit"] = !isKey;
dr["SummaryItem"] = false; //是否合计
dr.EndEdit();
result.Tables[0].Rows.Add(dr);
});
return result;
}
/// <summary>
/// 将XmlDocument转化为string
/// </summary>
/// <param name="xmlDoc"></param>
/// <returns></returns>
public string ConvertXmlToString(XmlDocument xmlDoc)
{
string result = "";
using (MemoryStream ms = new MemoryStream())
{
//生成缩进格式
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8);
writer.Formatting = Formatting.Indented; //缩进
xmlDoc.Save(writer);
//读取缩进后内容
StreamReader sr = new StreamReader(ms, Encoding.UTF8);
ms.Position = 0; //重置流位置
result = sr.ReadToEnd();
//关闭流对象
sr.Close();
writer.Close();
}
return result;
}
/// <summary>
/// 创建XML文本
/// </summary>
/// <param name="IsSaveToXml"></param>
private XmlDocument GenXmlDocument()
{
#region 生成XML配置文件
//创建xml文档对象
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "utf-8", ""));
//添加根节点
XmlNode root = xmlDoc.CreateElement("Entity");
xmlDoc.AppendChild(root);
//基本信息
this.AddChild(xmlDoc, root, "EntityTypeName", this._tableName); //实体表
this.AddChild(xmlDoc, root, "TableKeyName", "ID"); //数据库表
this.AddChild(xmlDoc, root, "TableName", this._tableName); //表名
this.AddChild(xmlDoc, root, "LinkFilterCtl", "U.WinCtl.Design.ucAutoDateFilter,U.WinCtl.DLL"); //查询
this.AddChild(xmlDoc, root, "FormEditConfigure", "U.WinClientDoc.EditCtlconfigureHelper,U.WinClientDoc.DL"); //配置窗体
this.AddChild(xmlDoc, root, "RefreshOnStringEmpty", "true"); //刷新
this.AddChild(xmlDoc, root, "DetailMerge", " "); //合并
this.AddChild(xmlDoc, root, "TableAlias", "a"); //查询别名
//图像浏览窗口必须配置的相关信息
var viewImgElement = xmlDoc.CreateElement("ViewImageList");
this.AddChild(xmlDoc, viewImgElement, "KeyFieldName", " ");
this.AddChild(xmlDoc, viewImgElement, "RemarkFieldName", " ");
this.AddChild(xmlDoc, viewImgElement, "RemarkFieldCaption", " ");
this.AddChild(xmlDoc, viewImgElement, "ImageFieldName", " ");
root.AppendChild(viewImgElement);
//网格编辑列需要配置的信息
this.AddChild(xmlDoc, root, "EditUI", " ");
//列信息配置
var columnsNode = xmlDoc.CreateElement("Columns");
foreach (DataRow row in this._dsXmlSetting.Tables[0].Rows)
{
XmlNode col = xmlDoc.CreateNode(XmlNodeType.Element, "Column", "");
foreach (DataColumn dc in this._dsXmlSetting.Tables[0].Columns)
{
object value = row[dc.ColumnName];
if (dc.ColumnName == "Columns_Id" || value.ToString() == "")
continue;
XmlAttribute attr = xmlDoc.CreateAttribute(dc.ColumnName);
attr.InnerText = dc.DataType.ToString() == "System.Boolean" ? value.ToString().ToLower() : value.ToString();
col.Attributes.Append(attr);
}
columnsNode.AppendChild(col);
}
root.AppendChild(columnsNode);
//配置通用增删改查SQL语句
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();
#region SelectObject
//SQL配置基本设置
XmlNode sqlNode = this.CreateSqlNode(xmlDoc, sqlsNode, "SelectObject");
//生成SQL
var str = $" <![CDATA[ Select a.{string.Join(", a.", columnList)} From {this._tableName} as a where {keyWhere}; ]]>";
this.AddSqlStringNode(xmlDoc, sqlNode, str);
//生成参数
this.AddParamNode(xmlDoc, sqlNode, strKey);
#endregion
#region AddObject
//SQL基本信息
sqlNode = this.CreateSqlNode(xmlDoc, sqlsNode, "AddObject");
//生成SQL
str = $" <![CDATA[ INSERT INTO {this._tableName}( {string.Join(", ", columnList)} ) VALUES( @{string.Join(", @", columnList)} ) ]]>";
this.AddSqlStringNode(xmlDoc, sqlNode, str);
//生成参数
foreach (DataColumn dc in _ds.Tables[0].Columns)
{
this.AddParamNode(xmlDoc, sqlNode, dc.ColumnName);
}
#endregion
#region UpdateObject
//SQL基本信息
sqlNode = this.CreateSqlNode(xmlDoc, sqlsNode, "UpdateObject");
//生成SQL
var pairlist = columnList.Select(s => $"{s}=@{s}").ToList();
str = $" <![CDATA[ UPDATE {this._tableName} SET {string.Join(", ", pairlist)} Where {keyWhere}; ]]>";
this.AddSqlStringNode(xmlDoc, sqlNode, str);
//生成参数
foreach (DataColumn dc in _ds.Tables[0].Columns)
{
this.AddParamNode(xmlDoc, sqlNode, dc.ColumnName);
}
#endregion
#region DeleteObject
//SQL基本信息
sqlNode = this.CreateSqlNode(xmlDoc, sqlsNode, "DeleteObject");
//生成DeleteObject语句
str = $"<![CDATA[ DELETE FROM {this._tableName} Where {keyWhere}; ]]>";
this.AddSqlStringNode(xmlDoc, sqlNode, str);
//生成参数
this.AddParamNode(xmlDoc, sqlNode, strKey);
#endregion
root.AppendChild(sqlsNode);
return xmlDoc;
#endregion
}
/// <summary>
/// XmlNode添加子节点
/// </summary>
/// <param name="xml"></param>
/// <param name="parent"></param>
/// <param name="name"></param>
/// <param name="InnerText"></param>
private void AddChild(XmlDocument xml, XmlNode parent, string name, string InnerText)
{
var child = xml.CreateElement(name);
child.InnerText = InnerText;
parent.AppendChild(child);
}
/// <summary>
/// 创建SQL节点
/// </summary>
/// <param name="xml"></param>
/// <param name="parent"></param>
/// <param name="value"></param>
private XmlNode CreateSqlNode(XmlDocument xml, XmlNode parent, string value)
{
//创建SQL节点
var node = xml.CreateNode(XmlNodeType.Element, "Sql", "");
//添加Name属性
var attr = xml.CreateAttribute("Name");
attr.Value = value;
node.Attributes.Prepend(attr);
//添加到父节点
parent.AppendChild(node);
return node;
}
/// <summary>
/// 添加String节点
/// </summary>
/// <param name="xml"></param>
/// <param name="parent"></param>
/// <param name="sqlString"></param>
private void AddSqlStringNode(XmlDocument xml, XmlNode parent, string sqlString)
{
//创建String节点
var node = xml.CreateNode(XmlNodeType.Element, "String", "");
node.InnerText = sqlString;
node.InnerXml = sqlString;
//添加到父节点
parent.AppendChild(node);
}
/// <summary>
/// 添加参数节点
/// </summary>
/// <param name="xml"></param>
/// <param name="parent"></param>
/// <param name="name"></param>
private void AddParamNode(XmlDocument xml, XmlNode parent, string name)
{
//创建参数节点
var node = xml.CreateNode(XmlNodeType.Element, "Param", "");
//设置Column属性
var attr = xml.CreateAttribute("Column");
attr.Value = name;
node.Attributes.Prepend(attr);
parent.AppendChild(node);
//设置Name属性
attr = xml.CreateAttribute("Name");
attr.Value = $"@{name}";
node.Attributes.Prepend(attr);
//绑定父节点
parent.AppendChild(node);
}
/// <summary>
/// 检查数据库配置
/// </summary>
/// <returns></returns>
public bool CheckDbSetting()
{
bool result = false;
if (this._db == null)
{
Utils.Tip("请先配置数据库链接!");
result = true;
}
return result;
}
}
}
<?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>
<metadata name="Column1.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="Column5.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="Column7.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column8.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column9.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column10.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column11.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column12.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column13.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>
\ No newline at end of file
......@@ -31,6 +31,7 @@ namespace Tools
this.CreateModule(typeof(UI.wAutoClass), "类生成工具"),
this.CreateModule(typeof(UI.wAuditDemo), "审批示例", "tr"),
this.CreateModule(typeof(UI.wImageSearch), "图片搜索", "tr"),
this.CreateModule(typeof(UI.wXmlGenerator), "XML生成器", "tr"),
};
}
......
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