📄 frmmain.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using ControlSQLsrv2000.WSSQLsrv20004;
namespace ControlSQLsrv2000
{
/// <summary>
/// Summary description for frmMain.
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
ConnectDB oConDb = new ConnectDB();
DataSet daView = new DataSet();
frmLogin.LoginInfo oLoginInfo;
public string sDB;
private System.Windows.Forms.ContextMenu cntMenu;
private System.Windows.Forms.MenuItem mnuRefresh;
private System.Windows.Forms.MenuItem mnuQueryAnaly;
private System.Windows.Forms.MainMenu mnuMain;
private System.Windows.Forms.MenuItem mnMainRefresh;
private System.Windows.Forms.MenuItem mnMainQueryAnal;
private System.Windows.Forms.MenuItem mnMainRelogin;
private System.Windows.Forms.MenuItem mnMainExit;
private System.Windows.Forms.MenuItem mnMainFile;
private System.Windows.Forms.TreeView trvLeftPannel;
public frmMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.trvLeftPannel = new System.Windows.Forms.TreeView();
this.cntMenu = new System.Windows.Forms.ContextMenu();
this.mnuRefresh = new System.Windows.Forms.MenuItem();
this.mnuQueryAnaly = new System.Windows.Forms.MenuItem();
this.mnuMain = new System.Windows.Forms.MainMenu();
this.mnMainFile = new System.Windows.Forms.MenuItem();
this.mnMainRefresh = new System.Windows.Forms.MenuItem();
this.mnMainQueryAnal = new System.Windows.Forms.MenuItem();
this.mnMainRelogin = new System.Windows.Forms.MenuItem();
this.mnMainExit = new System.Windows.Forms.MenuItem();
//
// trvLeftPannel
//
this.trvLeftPannel.ContextMenu = this.cntMenu;
this.trvLeftPannel.ImageIndex = -1;
this.trvLeftPannel.Location = new System.Drawing.Point(6, 6);
this.trvLeftPannel.SelectedImageIndex = -1;
this.trvLeftPannel.Size = new System.Drawing.Size(230, 260);
//
// cntMenu
//
this.cntMenu.MenuItems.Add(this.mnuRefresh);
this.cntMenu.MenuItems.Add(this.mnuQueryAnaly);
//
// mnuRefresh
//
this.mnuRefresh.Text = "Refresh";
this.mnuRefresh.Click += new System.EventHandler(this.mnuRefresh_Click);
//
// mnuQueryAnaly
//
this.mnuQueryAnaly.Text = "Query Analyser";
this.mnuQueryAnaly.Click += new System.EventHandler(this.mnuQueryAnaly_Click);
//
// mnuMain
//
this.mnuMain.MenuItems.Add(this.mnMainFile);
//
// mnMainFile
//
this.mnMainFile.MenuItems.Add(this.mnMainRefresh);
this.mnMainFile.MenuItems.Add(this.mnMainQueryAnal);
this.mnMainFile.MenuItems.Add(this.mnMainRelogin);
this.mnMainFile.MenuItems.Add(this.mnMainExit);
this.mnMainFile.Text = "File";
//
// mnMainRefresh
//
this.mnMainRefresh.Text = "Refresh";
this.mnMainRefresh.Click += new System.EventHandler(this.mnMainRefresh_Click);
//
// mnMainQueryAnal
//
this.mnMainQueryAnal.Text = "Query Analyser";
this.mnMainQueryAnal.Click += new System.EventHandler(this.mnMainQueryAnal_Click);
//
// mnMainRelogin
//
this.mnMainRelogin.Text = "Re-Login";
this.mnMainRelogin.Click += new System.EventHandler(this.mnMainRelogin_Click);
//
// mnMainExit
//
this.mnMainExit.Text = "Exit";
this.mnMainExit.Click += new System.EventHandler(this.mnMainExit_Click);
//
// frmMain
//
this.Controls.Add(this.trvLeftPannel);
this.Menu = this.mnuMain;
this.Text = "Manager";
}
#endregion
public void FillTreeView(ControlSQLsrv2000.frmLogin.LoginInfo oLogInfo)
{
try
{
oLoginInfo = oLogInfo;
TreeNode newNode = new TreeNode(oLoginInfo.sServer);
trvLeftPannel.Nodes.Add(newNode);
newNode = new TreeNode("Databases");
trvLeftPannel.SelectedNode = trvLeftPannel.Nodes[0];
trvLeftPannel.SelectedNode.Nodes.Add(newNode);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void mnuRefresh_Click(object sender, System.EventArgs e)
{
TreeNode newNode = new TreeNode();
if (trvLeftPannel.SelectedNode.Text=="Databases")
{
TreeNode selectedTreeNode = trvLeftPannel.SelectedNode;
if (selectedTreeNode.Nodes.Count > 0) //Check we have already listed the DB's. If it so then remove it and rebuild it
{
int i = 0;
int iSubNodeCount = selectedTreeNode.Nodes.Count;
foreach(TreeNode remNode in trvLeftPannel.Nodes[trvLeftPannel.SelectedNode.Index].Nodes)
{
for(i=0;i<iSubNodeCount;i=i+1)
{
remNode.Nodes[0].Remove();
}
}
}
daView = oConDb.DBList();
foreach (DataRow pRow in daView.Tables["Databases"].Rows)
{
string sNodeVal = pRow["DATABASE_NAME"].ToString();
newNode = new TreeNode(sNodeVal);
//trvLeftPannel.Nodes[0].Nodes.Add(newNode);
selectedTreeNode.Nodes.Add(newNode);
}
}
}
private void mnuQueryAnaly_Click(object sender, System.EventArgs e)
{
sDB = trvLeftPannel.SelectedNode.Text;
frmQueryAnaly oQryAna = new frmQueryAnaly();
oLoginInfo.sDatabase = sDB;
oQryAna.init(oLoginInfo);
}
private void mnMainRefresh_Click(object sender, System.EventArgs e)
{
try
{
mnuRefresh_Click(sender, e);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void mnMainQueryAnal_Click(object sender, System.EventArgs e)
{
try
{
mnuQueryAnaly_Click(sender, e);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void mnMainRelogin_Click(object sender, System.EventArgs e)
{
try
{
frmLogin oLogin = new frmLogin();
oLogin.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void mnMainExit_Click(object sender, System.EventArgs e)
{
try
{
Application.Exit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -