📄 dbtoword.cs
字号:
namespace Codematic
{
using Codematic.Properties;
using LTP.CmConfig;
using LTP.CodeHelper;
using LTP.DBFactory;
using LTP.IDBO;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
using WiB.Pinkie.Controls;
public class DbToWord : 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 ComboBox cmbDB;
private Container components;
private string dbname = "";
private IDbObject dbobj;
private DbSettings dbset;
private GroupBox groupBox1;
private GroupBox groupBox2;
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private Label labelNum;
private Label lblServer;
private ListBox listTable1;
private ListBox listTable2;
private Loading load = new Loading();
private Thread mythread;
private Thread mythreadload;
private PictureBox pictureBox1;
private ProgressBar progressBar1;
private Microsoft.Office.Interop.Word.Application WordApp = new ApplicationClass();
public DbToWord(string longservername)
{
this.InitializeComponent();
this.dbset = DbConfig.GetSetting(longservername);
this.dbobj = DBOMaker.CreateDbObj(this.dbset.DbType);
this.dbobj.DbConnectStr = this.dbset.ConnectStr;
this.lblServer.Text = this.dbset.Server;
}
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)
{
try
{
object saveChanges = Missing.Value;
this.WordApp.Quit(ref saveChanges, ref saveChanges, ref saveChanges);
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
}
base.Close();
}
private void btn_Creat_Click(object sender, EventArgs e)
{
try
{
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 cmbDB_SelectedIndexChanged(object sender, EventArgs e)
{
string text = this.cmbDB.Text;
List<string> tables = this.dbobj.GetTables(text);
this.listTable1.Items.Clear();
this.listTable2.Items.Clear();
if (tables.Count > 0)
{
foreach (string str2 in tables)
{
this.listTable1.Items.Add(str2);
}
}
this.IsHasItem();
}
private void DbToWord_Load(object sender, EventArgs e)
{
this.btn_Creat.Enabled = false;
this.ThreadWorkLoad();
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
public void GoToTheEnd()
{
object extend = Missing.Value;
object wdStory = WdUnits.wdStory;
this.WordApp.Selection.EndKey(ref wdStory, ref extend);
}
private void InitializeComponent()
{
ComponentResourceManager manager = new ComponentResourceManager(typeof(DbToWord));
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.pictureBox1 = new PictureBox();
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.label2 = new Label();
this.label4 = new Label();
this.groupBox1.SuspendLayout();
this.groupBox2.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(0x1d0, 0x40);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "选择数据库";
this.cmbDB.DropDownStyle = ComboBoxStyle.DropDownList;
this.cmbDB.Location = new Point(0x128, 0x18);
this.cmbDB.Name = "cmbDB";
this.cmbDB.Size = new Size(0x98, 20);
this.cmbDB.TabIndex = 2;
this.cmbDB.SelectedIndexChanged += new EventHandler(this.cmbDB_SelectedIndexChanged);
this.lblServer.AutoSize = true;
this.lblServer.Location = new Point(0x68, 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(0x10, 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(0xd8, 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.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, 80);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new Size(0x1d0, 0xd0);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "选择表";
this.pictureBox1.Image = Resources.Control;
this.pictureBox1.Location = new Point(0xd5, 0x94);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new Size(0x1c, 0x1c);
this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0x35;
this.pictureBox1.TabStop = false;
this.pictureBox1.Visible = false;
this.progressBar1.Location = new Point(0x40, 0xb6);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new Size(0x178, 20);
this.progressBar1.TabIndex = 10;
this.labelNum.Location = new Point(0x10, 180);
this.labelNum.Name = "labelNum";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -