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:
		@@ -1,7 +1,7 @@
 | 
				
			|||||||
//------------------------------------------------------------------------------
 | 
					//------------------------------------------------------------------------------
 | 
				
			||||||
// <auto-generated>
 | 
					// <auto-generated>
 | 
				
			||||||
//     This code was generated by a tool.
 | 
					//     This code was generated by a tool.
 | 
				
			||||||
//     Runtime Version:2.0.50727.4211
 | 
					//     Runtime Version:2.0.50727.4216
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//     Changes to this file may cause incorrect behavior and will be lost if
 | 
					//     Changes to this file may cause incorrect behavior and will be lost if
 | 
				
			||||||
//     the code is regenerated.
 | 
					//     the code is regenerated.
 | 
				
			||||||
@@ -243,5 +243,17 @@ namespace VEPROMS.Properties {
 | 
				
			|||||||
                this["QATItems"] = value;
 | 
					                this["QATItems"] = value;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        [global::System.Configuration.UserScopedSettingAttribute()]
 | 
				
			||||||
 | 
					        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 | 
				
			||||||
 | 
					        [global::System.Configuration.DefaultSettingValueAttribute("")]
 | 
				
			||||||
 | 
					        public string DefaultDB {
 | 
				
			||||||
 | 
					            get {
 | 
				
			||||||
 | 
					                return ((string)(this["DefaultDB"]));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            set {
 | 
				
			||||||
 | 
					                this["DefaultDB"] = value;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,5 +59,8 @@
 | 
				
			|||||||
    <Setting Name="QATItems" Type="System.String" Scope="User">
 | 
					    <Setting Name="QATItems" Type="System.String" Scope="User">
 | 
				
			||||||
      <Value Profile="(Default)" />
 | 
					      <Value Profile="(Default)" />
 | 
				
			||||||
    </Setting>
 | 
					    </Setting>
 | 
				
			||||||
 | 
					    <Setting Name="DefaultDB" Type="System.String" Scope="User">
 | 
				
			||||||
 | 
					      <Value Profile="(Default)" />
 | 
				
			||||||
 | 
					    </Setting>
 | 
				
			||||||
  </Settings>
 | 
					  </Settings>
 | 
				
			||||||
</SettingsFile>
 | 
					</SettingsFile>
 | 
				
			||||||
@@ -174,10 +174,14 @@ namespace VEPROMS
 | 
				
			|||||||
				if (parameter.StartsWith("/DB="))
 | 
									if (parameter.StartsWith("/DB="))
 | 
				
			||||||
					Database.SelectedDatabase = parameter.Substring(4);
 | 
										Database.SelectedDatabase = parameter.Substring(4);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								if (Properties.Settings.Default["DefaultDB"] != string.Empty)
 | 
				
			||||||
 | 
									Database.LastDatabase = Properties.Settings.Default.DefaultDB;
 | 
				
			||||||
			if (!FormatInfo.HasLatestChanges())
 | 
								if (!FormatInfo.HasLatestChanges())
 | 
				
			||||||
				throw new Exception("Inconsistent Formats");
 | 
									throw new Exception("Inconsistent Formats");
 | 
				
			||||||
			if (!ItemAuditInfo.IsChangeManagerVersion())
 | 
								if (!ItemAuditInfo.IsChangeManagerVersion())
 | 
				
			||||||
				throw new Exception("Inconsistent Data");
 | 
									throw new Exception("Inconsistent Data");
 | 
				
			||||||
 | 
								Properties.Settings.Default.DefaultDB = Database.SelectedDatabase;
 | 
				
			||||||
 | 
								Properties.Settings.Default.Save();
 | 
				
			||||||
			VETreeNode tn = VETreeNode.GetFolder(1);
 | 
								VETreeNode tn = VETreeNode.GetFolder(1);
 | 
				
			||||||
			tv.Nodes.Add(tn);
 | 
								tv.Nodes.Add(tn);
 | 
				
			||||||
			tv.NodePSI += new vlnTreeViewPSIEvent(tv_NodePSI);
 | 
								tv.NodePSI += new vlnTreeViewPSIEvent(tv_NodePSI);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -96,18 +96,41 @@ namespace VEPROMS.CSLA.Library
 | 
				
			|||||||
			set { _VEPROMS_Connection = value; }
 | 
								set { _VEPROMS_Connection = value; }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		private static string _SelectedDatabase;
 | 
							private static string _SelectedDatabase;
 | 
				
			||||||
 | 
					 | 
				
			||||||
		public static string SelectedDatabase
 | 
							public static string SelectedDatabase
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			get { return Database._SelectedDatabase; }
 | 
								get { return Database._SelectedDatabase; }
 | 
				
			||||||
			set { Database._SelectedDatabase = value; }
 | 
								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)
 | 
							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");
 | 
								string tmp = constr.Replace("{MENU}", "master");
 | 
				
			||||||
			SqlConnection cn = new SqlConnection(tmp);
 | 
								SqlConnection cn = new SqlConnection(tmp);
 | 
				
			||||||
			cn.Open();
 | 
								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);
 | 
								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();
 | 
								DataSet ds = new DataSet();
 | 
				
			||||||
			da.Fill(ds);
 | 
								da.Fill(ds);
 | 
				
			||||||
@@ -120,15 +143,10 @@ namespace VEPROMS.CSLA.Library
 | 
				
			|||||||
			tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold);
 | 
								tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold);
 | 
				
			||||||
			foreach (DataRow dr in ds.Tables[0].Rows)
 | 
								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));
 | 
										cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			while (_SelectedDatabase == null)
 | 
								return cms;
 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				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)
 | 
							static void Database_Click(object sender, EventArgs e)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user