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

📄 dbquery.cs

📁 通过数据库结构自动 生成三层结构代码,相当不错的一款软件
💻 CS
📖 第 1 页 / 共 4 页
字号:
namespace Codematic
{
    using ICSharpCode.TextEditor.Document;
    using LTP.IDBO;
    using LTP.Utility;
    using LTPTextEditor;
    using LTPTextEditor.Editor;
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Printing;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;
    using System.Xml;

    public class DbQuery : Form
    {
        private IAsyncResult _asyncResult;
        private bool _canceled;
        private Exception _currentException;
        private TimeSpan _currentExecutionTime;
        private TreeNode _dragObject;
        private int _dragPos;
        private Regex _findNextRegex;
        private int _findNextStartPos;
        private string _OrginalName;
        private static ArrayList _sqlInfoMessages = new ArrayList();
        private Hashtable Aliases = new Hashtable();
        private ArrayList AliasList = new ArrayList();
        private ContextMenu cmDragAndDrp;
        private ContextMenu cmShortcutMeny;
        private IContainer components;
        private ContextMenu contextMenu1;
        public string DatabaseName = "";
        private DataGridView dataGridView1;
        private Timer ExecutionTimer;
        private int firstPos;
        private ImageList imageList1;
        private ImageList imageList2;
        public bool IsActive;
        private int keyPressCount;
        private int lastPos;
        private string m_fileName = string.Empty;
        private bool m_resetText = true;
        private MainForm mainfrm;
        public Form MdiParentForm;
        private MenuItem menuItemGroupBy;
        private MenuItem menuItemJoin;
        private MenuItem menuItemLeftOuterJoin;
        private MenuItem menuItemObjectName;
        private MenuItem menuItemOrderBy;
        private MenuItem menuItemRightOuterJoin;
        private MenuItem menuItemSelect1;
        private MenuItem menuItemSelect2;
        private MenuItem menuItemSplitter;
        private MenuItem menuItemWhere;
        private PageSetupDialog pageSetupDialog;
        private PrintDialog printDialog;
        private PrintDocument printDocument;
        private PrintPreviewDialog printPreviewDialog;
        private ArrayList ReservedWords = new ArrayList();
        private Splitter splitter1;
        private XmlDocument sqlReservedWords = new XmlDocument();
        private StatusStrip statusStrip1;
        public SyntaxReader syntaxReader;
        public TabControl tabControl1;
        private TabPage tabPage1;
        private TabPage tabPage2;
        private ToolStripStatusLabel toolStripStatusLabel1;
        private ToolStripStatusLabel toolStripStatusLabel2;
        private ToolTip toolTip1;
        private ToolTip ttParamenterInfo;
        public TextEditorControlWrapper txtContent;
        private RichTextBox txtInfo;

        public DbQuery(Form mdiParentForm, string strSQL)
        {
            this.InitializeComponent();
            this.MdiParentForm = mdiParentForm;
            this.tabControl1.Visible = false;
            this.txtContent.ActiveTextAreaControl.TextArea.MouseUp += new MouseEventHandler(this.qcTextEditor_MouseUp);
            this.txtContent.ActiveTextAreaControl.TextArea.DragDrop += new DragEventHandler(this.TextArea_DragDrop);
            this.txtContent.ActiveTextAreaControl.TextArea.DragEnter += new DragEventHandler(this.TextArea_DragEnter);
            this.txtContent.ActiveTextAreaControl.TextArea.Click += new EventHandler(this.TextArea_Click);
            this.txtContent.ActiveTextAreaControl.TextArea.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextArea_KeyPress);
            this.txtContent.ActiveTextAreaControl.TextArea.KeyUp += new KeyEventHandler(this.TextArea_KeyUp);
            this.mainfrm = (MainForm) mdiParentForm;
            this.mainfrm.toolBtn_SQLExe.Visible = true;
            this.mainfrm.查询QToolStripMenuItem.Visible = true;
            this.txtContent.Text = strSQL;
        }

        public void AddRevisionCommentSection()
        {
            if (this.txtContent.Text.IndexOf("</member>", 0) >= 1)
            {
                int length = this.txtContent.Text.LastIndexOf("</revision>") + 11;
                this.txtContent.Text = this.txtContent.Text.Substring(0, length) + "\n\t<revision author='" + SystemInformation.UserName.ToString() + "' date='" + DateTime.Now.ToString() + "'>Altered</revision>" + this.txtContent.Text.Substring(length);
                this.txtContent.Refresh();
            }
        }

        public void AddToRecentObjects(string objectName)
        {
        }

        public void ComplementHeader()
        {
        }

        public void Copy()
        {
            this.txtContent.Copy();
        }

        public void CreateInsertStatement()
        {
        }

        public void CreateInsertStatement(string SQLstring)
        {
        }

        public void CreateUpdateStatement()
        {
        }

        public void CreateUpdateStatement(string SQLstring)
        {
        }

        public void Cut()
        {
            this.txtContent.Cut();
        }

        private void DbQuery_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

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

        public void ExecuteSql()
        {
            MainForm mdiParentForm = (MainForm) this.MdiParentForm;
            DataSet set = new DataSet();
            try
            {
                string longServername = ((DbView) Application.OpenForms["DbView"]).GetLongServername();
                if (longServername.Length < 1)
                {
                    this.toolStripStatusLabel1.Text = "没有选择任何服务器!";
                    return;
                }
                string text = mdiParentForm.toolComboBox_DB.Text;
                if (text.Length < 1)
                {
                    this.toolStripStatusLabel1.Text = "没有选择可执行的数据库!";
                    return;
                }
                this.toolStripStatusLabel1.Text = "正在进行批查询......";
                string sQLString = this.txtContent.Text;
                if (this.txtContent.SelectedText.Length > 1)
                {
                    sQLString = this.txtContent.SelectedText;
                }
                else
                {
                    sQLString = this.txtContent.Text;
                }
                if (sQLString.Trim() == "")
                {
                    this.toolStripStatusLabel1.Text = "查询语句为空!";
                    return;
                }
                IDbObject obj2 = ObjHelper.CreatDbObj(longServername);
                this.txtInfo.Text = "";
                StringBuilder builder = new StringBuilder();
                if (!sQLString.Trim().StartsWith("select") && !sQLString.Trim().StartsWith("SELECT"))
                {
                    if (sQLString.IndexOf("GO\r\n") > 0)
                    {
                        foreach (string str4 in sQLString.Split(new string[] { "GO\r\n" }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (str4.Trim() != "")
                            {
                                obj2.ExecuteSql(text, str4.Trim());
                                builder.Append("命令成功完成!\r\n");
                            }
                        }
                    }
                    else
                    {
                        builder.Append("命令成功完成(所影响的行数为 " + obj2.ExecuteSql(text, sQLString).ToString() + " 行)");
                    }
                    this.tabControl1.SelectedIndex = 1;
                }
                else
                {
                    set = obj2.Query(text, sQLString);
                    if (set.Tables.Count > 0)
                    {
                        foreach (DataTable table in set.Tables)
                        {
                            builder.Append("(所影响的行数为 " + table.Rows.Count.ToString() + " 行)\r\n");
                        }
                    }
                    this.tabControl1.SelectedIndex = 0;
                }
                this.txtInfo.Text = builder.ToString();
                this.toolStripStatusLabel1.Text = "命令已成功完成。";
            }
            catch (Exception exception)
            {
                LogInfo.WriteLog(exception);
                this.toolStripStatusLabel1.Text = "命令执行失败!";
                this.txtInfo.Text = exception.Message;
                this.tabControl1.SelectedIndex = 1;
            }
            this.tabControl1.Visible = true;
            this.dataGridView1.BackColor = Color.FromArgb(0x94, 0xb6, 0xed);
            if (set.Tables.Count > 1)
            {
                this.dataGridView1.DataSource = set;
            }
            else if (set.Tables.Count == 1)
            {
                this.dataGridView1.DataSource = set.Tables[0];
            }
        }

        private void ExecutionTimer_Tick(object sender, EventArgs e)
        {
        }

        public int Find(Regex regex, int startPos)
        {
            string input = this.txtContent.Text.Substring(startPos);
            Match match = regex.Match(input);
            if (!match.Success)
            {
                MessageBox.Show("没有找到指定文本.", "Codematic", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return 0;
            }
            int lineNumberForOffset = this.txtContent.Document.GetLineNumberForOffset(match.Index + startPos);
            this.txtContent.ActiveTextAreaControl.TextArea.ScrollTo(lineNumberForOffset);
            this.txtContent.Select(match.Index + startPos, match.Length);
            this._findNextRegex = regex;
            this._findNextStartPos = match.Index + startPos;
            this.txtContent.SetPosition((match.Index + match.Length) + startPos);
            return ((match.Index + match.Length) + startPos);
        }

        public void FindNext()
        {
            if (this._findNextRegex != null)
            {
                this.Find(this._findNextRegex, this._findNextStartPos + 1);
            }
        }

        public string GetAliasTableName(string alias)
        {
            return null;
        }

        public void GetCreateTablesScriptFromXMLFile()
        {
        }

        public string GetCurrentWord()
        {
            return this.txtContent.GetCurrentWord();
        }

        public void GetInsertScriptFromXMLFile()
        {
        }

        public void GetXmlDocFile()
        {
        }

        public void GoToDefenition()
        {
        }

        public void GoToLine()
        {
            int currentPosition = this.txtContent.GetLineFromCharIndex(this.txtContent.SelectionStart) + 1;
            new FrmGotoLine(this, currentPosition, this.txtContent.Document.LineSegmentCollection.Count).Show();
        }

        public void GoToLine(int line)
        {
            int offset = this.txtContent.Document.GetLineSegment(line - 1).Offset;
            int length = this.txtContent.Document.GetLineSegment(line - 1).Length;
            this.txtContent.ActiveTextAreaControl.TextArea.ScrollTo(line - 1);

⌨️ 快捷键说明

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