Added the ability to select a database from a menu.
This commit is contained in:
parent
8c6c81b951
commit
fee20b4f16
@ -86,10 +86,58 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
throw new ApplicationException("Database.cs Could not find connection " + ConnectionName);
|
||||
}
|
||||
return _VEPROMS_Connection = cs.ConnectionString;
|
||||
string constr = cs.ConnectionString;
|
||||
if (constr.Contains("{MENU}"))
|
||||
{
|
||||
constr = ChooseDatabase(constr);
|
||||
}
|
||||
return _VEPROMS_Connection = constr;
|
||||
}
|
||||
set { _VEPROMS_Connection = value; }
|
||||
}
|
||||
private static string _SelectedDatabase;
|
||||
|
||||
public static string SelectedDatabase
|
||||
{
|
||||
get { return Database._SelectedDatabase; }
|
||||
set { Database._SelectedDatabase = value; }
|
||||
}
|
||||
private static string ChooseDatabase(string constr)
|
||||
{
|
||||
string tmp = constr.Replace("{MENU}", "master");
|
||||
SqlConnection cn = new SqlConnection(tmp);
|
||||
cn.Open();
|
||||
SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases where name like 'VEP%' order by name", cn);
|
||||
DataSet ds = new DataSet();
|
||||
da.Fill(ds);
|
||||
cn.Close();
|
||||
System.Windows.Forms.ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip();
|
||||
cms.Items.Add("Choose Database");
|
||||
System.Windows.Forms.ToolStripMenuItem tsmi = cms.Items[0] as System.Windows.Forms.ToolStripMenuItem;
|
||||
tsmi.BackColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaption);// System.Drawing.Color.Pink;
|
||||
tsmi.ForeColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaptionText);
|
||||
tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold);
|
||||
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click));
|
||||
}
|
||||
while (_SelectedDatabase == null)
|
||||
{
|
||||
cms.Show(new System.Drawing.Point((System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - cms.Width) / 2, (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - cms.Height) / 2));
|
||||
System.Windows.Forms.Application.DoEvents();
|
||||
}
|
||||
return constr.Replace("{MENU}", _SelectedDatabase);
|
||||
}
|
||||
|
||||
static void Database_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Windows.Forms.ToolStripMenuItem tsmi = sender as System.Windows.Forms.ToolStripMenuItem;
|
||||
if (tsmi != null)
|
||||
{
|
||||
_SelectedDatabase = tsmi.Text;
|
||||
}
|
||||
}
|
||||
|
||||
public static SqlConnection VEPROMS_SqlConnection
|
||||
{
|
||||
get
|
||||
|
Loading…
x
Reference in New Issue
Block a user