Add LastDatabase property

This eliminates the need to look at all of the databases on the server, and thus speeds-up startup
Get and Save DefaultDB Setting
Added DefaultDB Setting
This commit is contained in:
Rich
2012-03-07 15:58:34 +00:00
parent 6c125d8997
commit af59ad1538
4 changed files with 47 additions and 10 deletions

View File

@@ -96,18 +96,41 @@ namespace VEPROMS.CSLA.Library
set { _VEPROMS_Connection = value; }
}
private static string _SelectedDatabase;
public static string SelectedDatabase
{
get { return Database._SelectedDatabase; }
set { Database._SelectedDatabase = value; }
}
private static string _LastDatabase="NoDefault";
public static string LastDatabase
{
get { return Database._LastDatabase; }
set { Database._LastDatabase = value; }
}
private static string ChooseDatabase(string constr)
{
if (LastDatabase != "NoDefault" && LastDatabase != "")
{
if (System.Windows.Forms.MessageBox.Show("Open " + LastDatabase, "Reopen Last Database", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
SelectedDatabase = LastDatabase;
return constr.Replace("{MENU}", _SelectedDatabase);
}
}
System.Windows.Forms.ContextMenuStrip cms = BuildDatabaseMenu(constr);
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);
}
private static System.Windows.Forms.ContextMenuStrip BuildDatabaseMenu(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);
// SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases where name like 'VEP%' order by name", cn);
SqlDataAdapter da = new SqlDataAdapter("select name, case when object_id(name + '..Items') is null then 'Not PROMS' when object_id(name + '..Revisions') is not null then 'Approval' when object_id(name + '..ContentAudits') is not null then 'Change Manager' else 'Original' end functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn);
DataSet ds = new DataSet();
da.Fill(ds);
@@ -120,15 +143,10 @@ namespace VEPROMS.CSLA.Library
tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold);
foreach (DataRow dr in ds.Tables[0].Rows)
{
if(dr["functionality"].ToString() == "Approval")
if (dr["functionality"].ToString() == "Approval")
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);
return cms;
}
static void Database_Click(object sender, EventArgs e)