📄 dbtoscript.cs
字号:
namespace Codematic
{
using Codematic.Properties;
using LTP.IDBO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
using WiB.Pinkie.Controls;
public class DbToScript : Form
{
private Button btn_Add;
private Button btn_Addlist;
private ButtonXP btn_Cancle;
private ButtonXP btn_Creat;
private Button btn_Del;
private Button btn_Dellist;
private ButtonXP btn_TargetFold;
private ComboBox cmbDB;
private Container components;
private string DbName;
private IDbObject dbobj;
private IDbScriptBuilder dsb;
private GroupBox groupBox1;
private GroupBox groupBox2;
private GroupBox groupBox3;
private Label label1;
private Label label2;
private Label label3;
private Label labelNum;
private Label lblServer;
private ListBox listTable1;
private ListBox listTable2;
private Thread mythread;
private PictureBox pictureBox1;
private ProgressBar progressBar1;
private ProgressBar progressBar2;
private TextBox txtTargetFolder;
public DbToScript(string longservername)
{
this.DbName = "master";
this.InitializeComponent();
this.dsb = ObjHelper.CreatDsb(longservername);
this.dbobj = ObjHelper.CreatDbObj(longservername);
int index = longservername.IndexOf("(");
string str = longservername.Substring(0, index);
this.lblServer.Text = str;
List<string> dBList = this.dbobj.GetDBList();
if ((dBList != null) && (dBList.Count > 0))
{
foreach (string str2 in dBList)
{
this.cmbDB.Items.Add(str2);
}
}
this.btn_Creat.Enabled = false;
if (this.cmbDB.Items.Count > 0)
{
this.cmbDB.SelectedIndex = 0;
}
}
public DbToScript(string longservername, string dbname)
{
this.DbName = "master";
this.InitializeComponent();
this.DbName = dbname;
this.dsb = ObjHelper.CreatDsb(longservername);
this.dbobj = ObjHelper.CreatDbObj(longservername);
this.lblServer.Text = longservername;
List<string> dBList = this.dbobj.GetDBList();
if ((dBList != null) && (dBList.Count > 0))
{
foreach (string str in dBList)
{
this.cmbDB.Items.Add(str);
}
}
this.btn_Creat.Enabled = false;
this.cmbDB.Text = this.DbName;
}
private void btn_Add_Click(object sender, EventArgs e)
{
int count = this.listTable1.SelectedItems.Count;
ListBox.SelectedObjectCollection selectedItems = this.listTable1.SelectedItems;
for (int i = 0; i < count; i++)
{
this.listTable2.Items.Add(this.listTable1.SelectedItems[i]);
}
for (int j = 0; j < count; j++)
{
if (this.listTable1.SelectedItems.Count > 0)
{
this.listTable1.Items.Remove(this.listTable1.SelectedItems[0]);
}
}
this.IsHasItem();
}
private void btn_Addlist_Click(object sender, EventArgs e)
{
int count = this.listTable1.Items.Count;
for (int i = 0; i < count; i++)
{
this.listTable2.Items.Add(this.listTable1.Items[i]);
}
this.listTable1.Items.Clear();
this.IsHasItem();
}
private void btn_Cancle_Click(object sender, EventArgs e)
{
if ((this.mythread != null) && this.mythread.IsAlive)
{
this.mythread.Abort();
}
base.Close();
}
private void btn_Creat_Click(object sender, EventArgs e)
{
try
{
if (this.txtTargetFolder.Text == "")
{
MessageBox.Show("请选择保存文件路径!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
this.DbName = this.cmbDB.Text;
this.pictureBox1.Visible = true;
this.mythread = new Thread(new ThreadStart(this.ThreadWork));
this.mythread.Start();
}
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
MessageBox.Show(exception.Message, "完成", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
private void btn_Del_Click(object sender, EventArgs e)
{
int count = this.listTable2.SelectedItems.Count;
ListBox.SelectedObjectCollection selectedItems = this.listTable2.SelectedItems;
for (int i = 0; i < count; i++)
{
this.listTable1.Items.Add(this.listTable2.SelectedItems[i]);
}
for (int j = 0; j < count; j++)
{
if (this.listTable2.SelectedItems.Count > 0)
{
this.listTable2.Items.Remove(this.listTable2.SelectedItems[0]);
}
}
this.IsHasItem();
}
private void btn_Dellist_Click(object sender, EventArgs e)
{
int count = this.listTable2.Items.Count;
for (int i = 0; i < count; i++)
{
this.listTable1.Items.Add(this.listTable2.Items[i]);
}
this.listTable2.Items.Clear();
this.IsHasItem();
}
private void btn_TargetFold_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "保存当前脚本";
dialog.Filter = "sql files (*.sql)|*.sql|All files (*.*)|*.*";
if (dialog.ShowDialog(this) == DialogResult.OK)
{
this.txtTargetFolder.Text = dialog.FileName;
}
}
private void cmbDB_SelectedIndexChanged(object sender, EventArgs e)
{
this.DbName = this.cmbDB.Text;
List<string> tables = this.dbobj.GetTables(this.DbName);
this.listTable1.Items.Clear();
this.listTable2.Items.Clear();
if (tables.Count > 0)
{
foreach (string str in tables)
{
this.listTable1.Items.Add(str);
}
}
this.IsHasItem();
}
private void DbToWord_Load(object sender, EventArgs e)
{
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
ComponentResourceManager manager = new ComponentResourceManager(typeof(DbToScript));
this.groupBox1 = new GroupBox();
this.cmbDB = new ComboBox();
this.lblServer = new Label();
this.label1 = new Label();
this.label3 = new Label();
this.groupBox2 = new GroupBox();
this.progressBar2 = new ProgressBar();
this.progressBar1 = new ProgressBar();
this.labelNum = new Label();
this.btn_Addlist = new Button();
this.btn_Add = new Button();
this.btn_Del = new Button();
this.btn_Dellist = new Button();
this.listTable2 = new ListBox();
this.listTable1 = new ListBox();
this.btn_Creat = new ButtonXP();
this.btn_Cancle = new ButtonXP();
this.groupBox3 = new GroupBox();
this.txtTargetFolder = new TextBox();
this.btn_TargetFold = new ButtonXP();
this.label2 = new Label();
this.pictureBox1 = new PictureBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
((ISupportInitialize) this.pictureBox1).BeginInit();
base.SuspendLayout();
this.groupBox1.Controls.Add(this.cmbDB);
this.groupBox1.Controls.Add(this.lblServer);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Location = new Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new Size(0x1f7, 0x38);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "选择数据库";
this.cmbDB.DropDownStyle = ComboBoxStyle.DropDownList;
this.cmbDB.Location = new Point(0x146, 0x18);
this.cmbDB.Name = "cmbDB";
this.cmbDB.Size = new Size(160, 20);
this.cmbDB.TabIndex = 2;
this.cmbDB.SelectedIndexChanged += new EventHandler(this.cmbDB_SelectedIndexChanged);
this.lblServer.AutoSize = true;
this.lblServer.Location = new Point(0x57, 0x1a);
this.lblServer.Name = "lblServer";
this.lblServer.Size = new Size(0x29, 12);
this.lblServer.TabIndex = 1;
this.lblServer.Text = "label2";
this.label1.AutoSize = true;
this.label1.Location = new Point(9, 0x1a);
this.label1.Name = "label1";
this.label1.Size = new Size(0x4d, 12);
this.label1.TabIndex = 0;
this.label1.Text = "当前服务器:";
this.label3.AutoSize = true;
this.label3.Location = new Point(0xf6, 0x1a);
this.label3.Name = "label3";
this.label3.Size = new Size(0x4d, 12);
this.label3.TabIndex = 0;
this.label3.Text = "选择数据库:";
this.groupBox2.Controls.Add(this.pictureBox1);
this.groupBox2.Controls.Add(this.progressBar2);
this.groupBox2.Controls.Add(this.progressBar1);
this.groupBox2.Controls.Add(this.labelNum);
this.groupBox2.Controls.Add(this.btn_Addlist);
this.groupBox2.Controls.Add(this.btn_Add);
this.groupBox2.Controls.Add(this.btn_Del);
this.groupBox2.Controls.Add(this.btn_Dellist);
this.groupBox2.Controls.Add(this.listTable2);
this.groupBox2.Controls.Add(this.listTable1);
this.groupBox2.Location = new Point(8, 0x70);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new Size(0x1f7, 0xe0);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "选择表";
this.progressBar2.Location = new Point(0x10, 0xb2);
this.progressBar2.Name = "progressBar2";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -