コード例 #1
0
ファイル: sqlsharpgtk.cs プロジェクト: emtees/old-code
		void QuitApplication () 
		{
			// FIXME: sometimes gtk+ error happens, such as, opening file and then quitting
			//        fix the proper way of quiting this app

			for(int i = 0; i < dataSources.Count; i++) {
				DataSourceConnection c = dataSources[i];
				if (c.Connection.State == ConnectionState.Open) 
					c.Connection.Close ();
					c.Dispose ();
			}
			dataSources.Clear ();
			dataSources = null;
			dataSource = null;
			conn = null;

			SqlWindowCount --;
			if (SqlWindowCount == 0)
				Application.Quit ();
			else
				win.Destroy ();
		}
コード例 #2
0
ファイル: sqlsharpgtk.cs プロジェクト: emtees/old-code
		void OnDataSourceChanged (object o, EventArgs args) 
		{
			ComboBox combo = o as ComboBox;
			if (o == null)
				return;

			TreeIter iter;

			if (combo.GetActiveIter (out iter)) {
				if (!combo.Model.GetValue (iter, 0).Equals(NotConnected)) {
					string datasourceName = combo.Model.GetValue (iter, 0).ToString();
					dataSource = dataSources[datasourceName];
					provider = dataSource.Provider;
					conn = dataSource.Connection;
					connectionString = dataSource.ConnectionString.GetConnectionString ();
				}
			}
			SetFocusToEditor ();
		}
コード例 #3
0
ファイル: sqlsharpgtk.cs プロジェクト: emtees/old-code
		void OnMenu_SessionDisconnectAll (object o, EventArgs args) 
		{
			AppendText ("Disconnecting All...");
			try {
				for(int i = 0; i < dataSources.Count; i++) {
					DataSourceConnection c = dataSources[i];
					c.Connection.Close ();
				}
				dataSources.Clear ();
				conn = null;
				dataSource = null;
				provider = null;
				((ListStore) combo.Model).Clear ();
				combo.AppendText (NotConnected);
				combo.Active = 0;
				tree.Clear ();
			}
			catch (Exception e) {
				Error ("Error: Unable to disconnect." + e.Message);
				conn = null;
				return;
			}
			AppendText ("Disconnected.");
		}
コード例 #4
0
ファイル: sqlsharpgtk.cs プロジェクト: emtees/old-code
		public bool OpenDataSource (Provider theProvider, string theConnectionString, string connectionName) 
		{
			provider = theProvider;
			connectionString = theConnectionString;

			string msg;
			msg = "Attempt to open connection...";
			AppendText (msg);

			conn = null;

			try {
				switch (provider.Name) {
				case "System.Data.SqlClient":
					conn = new SqlConnection ();
					break;
				case "System.Data.Odbc":
					conn = new OdbcConnection ();
					break;
				case "System.Data.OleDb":
					conn = new OleDbConnection ();
					break;
				default:
					conn = provider.CreateConnection ();
					break;
				}
			} catch (Exception e) {
				msg = "Error: Unable to create Connection object. \n" + 
					"Check to make sure the provider is setup correctly in your config file. \n" + 
					e.Message;
				Error (msg);
				return false;
			}

			ConnectionString conString = new ConnectionString (connectionString);
			conn.ConnectionString = connectionString;
			
			try {
				conn.Open ();
				if( conn.State == ConnectionState.Open)
					AppendText ("Open was successfull.");
				else {
					AppendText ("Error: Open failed.");
					return false;
				}
			} catch (Exception e) {
				msg = "Error: Could not open data source: " + e.Message;
				Error (msg);
				conn = null;
				return false;
			}

			// database connected - do other things
			//SetStatusBarText ("Connected.");
			lastConnection++;
			string dataSourceName = "";
			if (connectionName.Equals(""))
				dataSourceName = lastConnection.ToString () + ":" + provider.Name;
			else
				dataSourceName = lastConnection.ToString () + ":" + connectionName;

			dataSource = new DataSourceConnection (dataSourceName, connectionName, provider, conString, conn);
			dataSources.Add (dataSource);
			
			combo.AppendText (dataSourceName);
			ComboHelper.SetActiveText (combo, dataSourceName);

			TreeIter iterDataSource = tree.Store.AppendValues (tree.RootIter, dataSourceName, "");
			tree.Store.SetValue(iterDataSource, 1, "");
			//string sz = tree.Store.GetValue(iterDataSource, 1).ToString();
			//AppendText("sz: " + sz);

			// TODO: only load meta data when the user expands a tree node
			//       or Refreshes
			SetStatusBarText ("Getting Meta Data...");
			while (Application.EventsPending ()) 
				Application.RunIteration ();
			
			PopulateTables (iterDataSource, provider, conn, true);
			//PopulateViews (iterDataSource, provider, conn);
			//PopulateProcedures (iterDataSource, provider, conn);
			
			SetStatusBarText ("Connected.");

			SetFocusToEditor ();

			return true;
		}
コード例 #5
0
ファイル: sqlsharpgtk.cs プロジェクト: emtees/old-code
		void OnMenu_SessionDisconnect (object o, EventArgs args) 
		{
			AppendText ("Disconnecting...");
			try {

				if (combo.Active < 0)
					return;

				ListStore comboStore = (ListStore) combo.Model;
				TreeIter comboIter;
				comboStore.IterNthChild(out comboIter, combo.Active);
				string dataSourceRemove  = comboStore.GetValue (comboIter, 0).ToString();

				if (dataSourceRemove.Equals(NotConnected))
					return;

				if (dataSourceRemove.Equals(""))
					return;

				TreeIter iter, iterParent;
				string tvalue = "";
				conn.Close ();
				conn = null;
				dataSources.Remove (dataSources[dataSourceRemove]);
				dataSource = null;
				provider = null;
				comboStore.Remove (ref comboIter);

				if (dataSources.Count > 0) {
					dataSource = dataSources[0];
					provider = dataSource.Provider;
					conn = dataSource.Connection;
					connectionString = dataSource.ConnectionString.GetConnectionString ();
					ComboHelper.SetActiveText (combo, dataSource.Name);
					
					// remove the selected connected data source from the left tree view
					tree.Store.IterChildren (out iterParent);
					tree.Store.IterChildren (out iter, iterParent);
					GLib.Value v = GLib.Value.Empty;
					tree.Store.GetValue (iter, 0, ref v);
					tvalue = (string) v.Val;
					if (tvalue.Equals (dataSourceRemove)) 
						tree.Store.Remove (ref iter);
					else {
						bool found = tree.Store.IterNext (ref iter);
						while (found == true) {
							v = GLib.Value.Empty;
							tree.Store.GetValue (iter, 0, ref v);
							tvalue = (string) v.Val;
							if (tvalue.Equals (dataSourceRemove)) {
								tree.Store.Remove (ref iter);
								found = false;
							}
							else
								found = tree.Store.IterNext (ref iter);
						}
					}
				}
				else {
					// removed last connected data source from tree view
					comboStore.Clear ();
					combo.AppendText (NotConnected);
					combo.Active = 0;

					tree.Store.IterChildren (out iterParent);
					tree.Store.IterChildren (out iter, iterParent);
					tree.Store.Remove (ref iter);						
				}			
			}
			catch (Exception e) {
				Error ("Error: Unable to disconnect." + e.Message);
				conn = null;
				return;
			}
			AppendText ("Disconnected.");
		}