Esempio n. 1
0
        private void window_Loaded(object sender, RoutedEventArgs e)
        {
            gridLoading.Visibility = Visibility.Collapsed;
            ConnectionInfo info = new NpgsqlConnectionInfo()
            {
                ServerName   = App.Hostname,
                ServerPort   = App.Port,
                DatabaseName = App.Database,
                UserName     = App.Username
            };

            if (App.HasConnectionInfo)
            {
                if (!info.FillStoredPassword(true))
                {
                    if (TryConnect(info))
                    {
                        return;
                    }
                }
            }
            else
            {
                info = NewConnectionInfoFromRegistry();
            }
            NewConnectionWindow win = new NewConnectionWindow();

            win.Owner  = this;
            win.Target = info;
            bool?ret = win.ShowDialog();

            if (!ret.HasValue || !ret.Value)
            {
                return;
            }
            info = win.Target;
            Connect(info);
            App.Connections.Merge(info);
            App.Connections.Save();
            menuItemPsql.IsEnabled   = !string.IsNullOrEmpty(GetExecutableFromPath(menuItemPsql.Tag.ToString()));
            menuItemPgdump.IsEnabled = !string.IsNullOrEmpty(GetExecutableFromPath(menuItemPgdump.Tag.ToString()));
            {
                CommandBinding cb;
                cb = new CommandBinding(DataGridCommands.CopyTable, CopyTableCommand_Executed, CopyTableCommand_CanExecute);
                CommandBindings.Add(cb);
                cb = new CommandBinding(DataGridCommands.CopyTableContent, CopyTableContentCommand_Executed, CopyTableCommand_CanExecute);
                CommandBindings.Add(cb);
                cb = new CommandBinding(DataGridCommands.CopyTableAsInsert, CopyTableAsInsertCommand_Executed, CopyTableCommand_CanExecute);
                CommandBindings.Add(cb);
                cb = new CommandBinding(DataGridCommands.CopyTableAsCopy, CopyTableAsCopyCommand_Executed, CopyTableCommand_CanExecute);
                CommandBindings.Add(cb);
            }
        }
Esempio n. 2
0
        private void MenuItemOpenDb_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi == null)
            {
                return;
            }
            ConnectionInfo info = mi.Tag as ConnectionInfo;

            if (CurrentDataSet != null)
            {
                string path = Assembly.GetExecutingAssembly().Location;
                NpgsqlConnectionInfo obj = info as NpgsqlConnectionInfo;
                if (obj != null)
                {
                    string args = string.Format("-h {0} -p {1} -d {2} -U {3}", obj.ServerName, obj.ServerPort, obj.DatabaseName, obj.UserName);
                    Process.Start(path, args);
                }
                else
                {
                    Process.Start(path);
                }
                return;
            }
            if (info == null)
            {
                info = NewConnectionInfoFromRegistry();
            }
            NewConnectionWindow win = new NewConnectionWindow();

            win.Owner  = this;
            win.Target = info;
            bool?ret = win.ShowDialog();

            if (!ret.HasValue || !ret.Value)
            {
                return;
            }
            info = win.Target;
            Connect(info);
            App.Connections.Merge(info);
            App.Connections.Save();
        }