📄 codetemplate.cs
字号:
namespace Codematic
{
using LTP.CodeBuild;
using LTP.CodeHelper;
using LTP.IDBO;
using LTP.TextEditor;
using LTP.Utility;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
public class CodeTemplate : Form
{
private Button btn_Run;
private Button btn_SelAll;
private Button btn_SelClear;
private Button btn_SelI;
private Button btn_SetKey;
private IContainer components;
private string dbname;
private IDbObject dbobj;
private GroupBox groupBox1;
private GroupBox groupBox2;
private ImageList imglistView;
private ListBox list_KeyField;
private ListView listView1;
private MainForm mainfrm;
private Panel panel1;
private string servername;
private Splitter splitter1;
private ToolStripStatusLabel StatusLabel1;
private StatusStrip statusStrip1;
private TabControl tabControl1;
private string tablename;
private TabPage tabPage1;
private TabPage tabPage2;
private Thread thread;
private TextEditorControl txtCode;
private TextEditorControl txtTemplate;
public CodeTemplate()
{
this.InitializeComponent();
}
public CodeTemplate(Form mdiParentForm)
{
this.InitializeComponent();
this.mainfrm = (MainForm) mdiParentForm;
this.CreatView();
this.mainfrm.toolBtn_Run.Visible = true;
if (((DbView) Application.OpenForms["DbView"]) != null)
{
try
{
this.thread = new Thread(new ThreadStart(this.Showlistview));
this.thread.Start();
}
catch
{
}
}
}
private void BindlistViewCol(string Dbname, string TableName)
{
List<LTP.CodeHelper.ColumnInfo> columnInfoList = this.dbobj.GetColumnInfoList(Dbname, TableName);
if ((columnInfoList != null) && (columnInfoList.Count > 0))
{
this.listView1.Items.Clear();
this.list_KeyField.Items.Clear();
foreach (LTP.CodeHelper.ColumnInfo info in columnInfoList)
{
string colorder = info.Colorder;
string columnName = info.ColumnName;
string typeName = info.TypeName;
string length = info.Length;
string preci = info.Preci;
string scale = info.Scale;
string defaultVal = info.DefaultVal;
string deText = info.DeText;
string text = info.IsIdentity ? "√" : "";
string str8 = info.IsPK ? "√" : "";
string str9 = info.cisNull ? "√" : "";
ListViewItem item = new ListViewItem(colorder, 0);
item.ImageIndex = 4;
item.SubItems.Add(columnName);
item.SubItems.Add(typeName);
item.SubItems.Add(length);
item.SubItems.Add(scale);
item.SubItems.Add(text);
if ((str8 == "√") && (str9.Trim() == ""))
{
this.list_KeyField.Items.Add(columnName + "(" + typeName + ")");
}
else
{
str8 = "";
}
item.SubItems.Add(str8);
item.SubItems.Add(str9);
item.SubItems.Add(defaultVal);
this.listView1.Items.AddRange(new ListViewItem[] { item });
}
}
this.btn_SelAll_Click(null, null);
}
private void btn_Run_Click(object sender, EventArgs e)
{
try
{
this.Run();
}
catch
{
}
}
private void btn_SelAll_Click(object sender, EventArgs e)
{
foreach (ListViewItem item in this.listView1.Items)
{
if (!item.Checked)
{
item.Checked = true;
}
}
}
private void btn_SelClear_Click(object sender, EventArgs e)
{
foreach (ListViewItem item in this.listView1.Items)
{
item.Checked = false;
}
}
private void btn_SelI_Click(object sender, EventArgs e)
{
foreach (ListViewItem item in this.listView1.Items)
{
item.Checked = !item.Checked;
}
}
private void btn_SetKey_Click(object sender, EventArgs e)
{
this.list_KeyField.Items.Clear();
foreach (ListViewItem item in this.listView1.Items)
{
if (item.Checked)
{
this.list_KeyField.Items.Add(item.SubItems[1].Text + "(" + item.SubItems[2].Text + ")");
}
}
}
private void CreatView()
{
this.listView1.Columns.Clear();
this.listView1.Items.Clear();
this.listView1.LargeImageList = this.imglistView;
this.listView1.SmallImageList = this.imglistView;
this.listView1.View = View.Details;
this.listView1.GridLines = true;
this.listView1.CheckBoxes = true;
this.listView1.FullRowSelect = true;
this.listView1.Columns.Add("序号", 60, HorizontalAlignment.Center);
this.listView1.Columns.Add("列名", 110, HorizontalAlignment.Left);
this.listView1.Columns.Add("数据类型", 80, HorizontalAlignment.Left);
this.listView1.Columns.Add("长度", 40, HorizontalAlignment.Left);
this.listView1.Columns.Add("小数", 40, HorizontalAlignment.Left);
this.listView1.Columns.Add("标识", 40, HorizontalAlignment.Center);
this.listView1.Columns.Add("主键", 40, HorizontalAlignment.Center);
this.listView1.Columns.Add("允许空", 60, HorizontalAlignment.Center);
this.listView1.Columns.Add("默认值", 100, HorizontalAlignment.Left);
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private List<LTP.CodeHelper.ColumnInfo> GetFieldlist()
{
DataRow[] rowArray;
DataTable columnInfoDt = CodeCommon.GetColumnInfoDt(this.dbobj.GetColumnInfoList(this.dbname, this.tablename));
StringPlus plus = new StringPlus();
foreach (ListViewItem item in this.listView1.Items)
{
if (item.Checked)
{
plus.Append("'" + item.SubItems[1].Text + "',");
}
}
plus.DelLastComma();
if (columnInfoDt == null)
{
return null;
}
if (plus.Value.Length > 0)
{
rowArray = columnInfoDt.Select("ColumnName in (" + plus.Value + ")", "colorder asc");
}
else
{
rowArray = columnInfoDt.Select();
}
List<LTP.CodeHelper.ColumnInfo> list2 = new List<LTP.CodeHelper.ColumnInfo>();
foreach (DataRow row in rowArray)
{
string str = row["Colorder"].ToString();
string str2 = row["ColumnName"].ToString();
string str3 = row["TypeName"].ToString();
string str4 = row["IsIdentity"].ToString();
string str5 = row["IsPK"].ToString();
string str6 = row["Length"].ToString();
string str7 = row["Preci"].ToString();
string str8 = row["Scale"].ToString();
string str9 = row["cisNull"].ToString();
string str10 = row["DefaultVal"].ToString();
string str11 = row["DeText"].ToString();
LTP.CodeHelper.ColumnInfo info = new LTP.CodeHelper.ColumnInfo();
info.Colorder = str;
info.ColumnName = str2;
info.TypeName = str3;
info.IsIdentity = str4 == "√";
info.IsPK = str5 == "√";
info.Length = str6;
info.Preci = str7;
info.Scale = str8;
info.cisNull = str9 == "√";
info.DefaultVal = str10;
info.DeText = str11;
list2.Add(info);
}
return list2;
}
private List<LTP.CodeHelper.ColumnInfo> GetKeyFields()
{
DataRow[] rowArray;
DataTable columnInfoDt = CodeCommon.GetColumnInfoDt(this.dbobj.GetColumnInfoList(this.dbname, this.tablename));
StringPlus plus = new StringPlus();
foreach (object obj2 in this.list_KeyField.Items)
{
plus.Append("'" + obj2.ToString() + "',");
}
plus.DelLastComma();
if (columnInfoDt == null)
{
return null;
}
if (plus.Value.Length > 0)
{
rowArray = columnInfoDt.Select("ColumnName in (" + plus.Value + ")", "colorder asc");
}
else
{
rowArray = columnInfoDt.Select();
}
List<LTP.CodeHelper.ColumnInfo> list2 = new List<LTP.CodeHelper.ColumnInfo>();
foreach (DataRow row in rowArray)
{
string str = row["Colorder"].ToString();
string str2 = row["ColumnName"].ToString();
string str3 = row["TypeName"].ToString();
string str4 = row["IsIdentity"].ToString();
string str5 = row["IsPK"].ToString();
string str6 = row["Length"].ToString();
string str7 = row["Preci"].ToString();
string str8 = row["Scale"].ToString();
string str9 = row["cisNull"].ToString();
string str10 = row["DefaultVal"].ToString();
string str11 = row["DeText"].ToString();
LTP.CodeHelper.ColumnInfo item = new LTP.CodeHelper.ColumnInfo();
item.Colorder = str;
item.ColumnName = str2;
item.TypeName = str3;
item.IsIdentity = str4 == "√";
item.IsPK = str5 == "√";
item.Length = str6;
item.Preci = str7;
item.Scale = str8;
item.cisNull = str9 == "√";
item.DefaultVal = str10;
item.DeText = str11;
list2.Add(item);
}
return list2;
}
private void InitializeComponent()
{
this.components = new Container();
ComponentResourceManager manager = new ComponentResourceManager(typeof(CodeTemplate));
this.statusStrip1 = new StatusStrip();
this.StatusLabel1 = new ToolStripStatusLabel();
this.tabControl1 = new TabControl();
this.tabPage1 = new TabPage();
this.panel1 = new Panel();
this.groupBox1 = new GroupBox();
this.txtTemplate = new TextEditorControl();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -