📄 mainform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.IO;
namespace CEQuery
{
public partial class MainForm : Form
{
//private int childFormNumber = 0;
public string ConnectionString { get; set; }
public MainForm()
{
InitializeComponent();
}
private void ShowNewForm(object sender, EventArgs e)
{
OpenDB dbOpen = new OpenDB();
if (dbOpen.ShowDialog() == DialogResult.OK)
{
ConnectionString = dbOpen.ConnectionString;
using (SqlCeConnection connection = new SqlCeConnection(ConnectionString))
{
try
{
connection.Open();
//MessageBox.Show("DB Selected");
this.toolStripStatusLabel.Text = "DB selected successfully.";
//foreach (Form childForm in MdiChildren)
//{
// childForm.Close();
//}
FormQuery frmQuery = new FormQuery();
frmQuery.MdiParent = this;
frmQuery.ConnectionString = this.ConnectionString;
//frm.Text = openFileDialogue.FileName;
frmQuery.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
}
}
}
private void selectEngagementDBToolStripMenuItem_Click(object sender, EventArgs e)
{
ShowNewForm(this, e);
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
if (((System.Windows.Forms.Form[])this.MdiChildren).Length > 0 && this.ActiveMdiChild.GetType() == typeof(FormQuery))
{
if (((FormQuery)this.ActiveMdiChild).SaveActiveQuery())
{
this.toolStripStatusLabel.Text = "Query has been saved successfully.";
}
}
else
{
MessageBox.Show("Open a DB first.");
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void toolStripRunCommand_Click(object sender, EventArgs e)
{
if (((System.Windows.Forms.Form[])this.MdiChildren).Length > 0 && this.ActiveMdiChild.GetType() == typeof(FormQuery))
{
((FormQuery)this.ActiveMdiChild).RunActiveQuery();
}
else
{
MessageBox.Show("Open a DB first.");
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
CEAboutBox frm = new CEAboutBox();
frm.ShowDialog();
}
private void createDBToolStripMenuItem_Click(object sender, EventArgs e)
{
CreateDB dbCreate = new CreateDB();
if (dbCreate.ShowDialog() == DialogResult.OK)
{
//foreach (Form childForm in MdiChildren)
//{
// childForm.Close();
//}
this.toolStripStatusLabel.Text = "DB has been created successfully.";
}
}
private void newQueryToolStripButton_Click(object sender, EventArgs e)
{
if (((System.Windows.Forms.Form[])this.MdiChildren).Length > 0 && this.ActiveMdiChild.GetType() == typeof(FormQuery))
{
((FormQuery)this.ActiveMdiChild).AddQueryTab();
this.toolStripStatusLabel.Text = "A new query tab has been added.";
}
else
{
MessageBox.Show("Open a DB first.");
}
}
private void toolStripButtonScriptGenerator_Click(object sender, EventArgs e)
{
if (((System.Windows.Forms.Form[])this.MdiChildren).Length > 0 && this.ActiveMdiChild.GetType() == typeof(FormQuery))
{
ScriptGenerator frmScript = new ScriptGenerator();
//frmScript.ConnectionString = this.ConnectionString;
frmScript.ConnectionString = ((FormQuery)this.ActiveMdiChild).ConnectionString;
if (frmScript.ShowDialog() == DialogResult.OK)
{
this.toolStripStatusLabel.Text = "Script has been generated successfully.";
}
}
else
{
MessageBox.Show("Open a DB first.");
}
}
private void exportSqlToolStripMenuItem_Click(object sender, EventArgs e)
{
ExportSqlServer sqlExport = new ExportSqlServer();
sqlExport.ShowDialog();
}
private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
{
ChangePasswordDB chanePwd = new ChangePasswordDB();
if (chanePwd.ShowDialog() == DialogResult.OK)
{
if (chanePwd.OldConnectionString != string.Empty && chanePwd.NewConnectionString != string.Empty)
{
foreach (Form frm in this.MdiChildren)
{
if (frm.GetType() == typeof(FormQuery) && ((FormQuery)frm).ConnectionString == chanePwd.OldConnectionString)
{
((FormQuery)frm).ConnectionString = chanePwd.NewConnectionString;
}
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -