⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataexport.cs

📁 通过数据库结构自动 生成三层结构代码,相当不错的一款软件
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Codematic
{
    using LTP.CmConfig;
    using LTP.CodeBuild;
    using LTP.DBFactory;
    using LTP.IDBO;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Resources;
    using System.Threading;
    using System.Windows.Forms;
    using WiB.Pinkie.Controls;

    public class DataExport : 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 CodeBuilders cb;
        private ComboBox cmbDB;
        private Container components;
        private string DbName = "master";
        private IDbObject dbobj;
        private DbSettings dbset;
        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 ProgressBar progressBar1;
        private ProgressBar progressBar2;
        private TextBox txtTargetFolder;

        public DataExport(string longservername, string dbname)
        {
            this.InitializeComponent();
            this.DbName = dbname;
            this.dbset = DbConfig.GetSetting(longservername);
            this.dbobj = DBOMaker.CreateDbObj(this.dbset.DbType);
            this.dbobj.DbConnectStr = this.dbset.ConnectStr;
            this.cb = new CodeBuilders(this.dbobj);
            this.dsb = DBOMaker.CreateScript(this.dbset.DbType);
            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)
        {
            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.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)
        {
            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)
        {
            string dbName = "master";
            string dbType = this.dbobj.DbType;
            if (dbType != null)
            {
                if (!(dbType == "SQL2000") && !(dbType == "SQL2005"))
                {
                    if ((dbType == "Oracle") || (dbType == "OleDb"))
                    {
                        dbName = this.dbset.DbName;
                    }
                    else if (dbType == "MySQL")
                    {
                        dbName = "mysql";
                    }
                }
                else
                {
                    dbName = "master";
                }
            }
            if ((this.dbset.DbName == "") || (this.dbset.DbName == dbName))
            {
                List<string> dBList = this.dbobj.GetDBList();
                if ((dBList != null) && (dBList.Count > 0))
                {
                    foreach (string str2 in dBList)
                    {
                        this.cmbDB.Items.Add(str2);
                    }
                }
            }
            else
            {
                this.cmbDB.Items.Add(this.DbName);
            }
            this.btn_Creat.Enabled = false;
            this.cmbDB.Text = this.DbName;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ResourceManager manager = new ResourceManager(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.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.progressBar2 = new ProgressBar();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            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, 0x38);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "选择数据库";
            this.cmbDB.DropDownStyle = ComboBoxStyle.DropDownList;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -