示例#1
0
        private void btCreateEndoDB_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = @"C:\Program Files";
            ofd.Filter = "psql.exe(psql.exe)|psql.exe|All Files(*.*)|*.*";
            ofd.FilterIndex = 1;
            ofd.Title = Properties.Resources.WhereIsPsql;

            string psql_path;

            if (ofd.ShowDialog() == DialogResult.OK)
            { psql_path = ofd.FileName; }
            else
            { return; }

            if (File.Exists(Application.StartupPath + @"\setup.dump"))
            {
                SetPort sp = new SetPort();
                sp.ShowDialog(this);
                if (sp.portSet)
                {
                    System.Diagnostics.Process p = new System.Diagnostics.Process(); //Create process object
                    p.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec"); //Get ComSpec(cmd.exe) path, and set to FileName property
                    p.StartInfo.UseShellExecute = false;
                    //p.StartInfo.RedirectStandardOutput = true; //Make output readable
                    //p.StartInfo.RedirectStandardInput = false;
                    p.StartInfo.CreateNoWindow = false; //Display window
                    p.StartInfo.WorkingDirectory = Application.StartupPath;
                    p.StartInfo.Arguments = "/c \"" + psql_path + "\" -h localhost -p " + sp.portNo + " -U postgres -f setup.dump"; //Set command line("/c" needed for close window after running)
                    sp.Dispose();
                    p.Start();
                    //string results = p.StandardOutput.ReadToEnd(); //Get output
                    p.WaitForExit(); //WaitForExit has to be after ReadToEnd
                    //p.Close();
                    //MessageBox.Show(results); //Show output
                    MessageBox.Show(Properties.Resources.ProcedureFinished, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    sp.Dispose();
                    MessageBox.Show(Properties.Resources.ProcedureCancelled, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("[setup.dump]" + Properties.Resources.FileNotExist, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
示例#2
0
        private void btRestore_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = @"C:\Program Files";
            ofd.Filter           = "psql.exe(psql.exe)|psql.exe|All Files(*.*)|*.*";
            ofd.FilterIndex      = 1;
            ofd.Title            = Properties.Resources.WhereIsPsql;

            string psql_path;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                psql_path = ofd.FileName;
            }
            else
            {
                return;
            }

            ofd.Filter      = "Back up file(*.sql)|*.sql|All Files(*.*)|*.*";
            ofd.FilterIndex = 1;
            ofd.Title       = Properties.Resources.WhereIsBackupFile;

            string backupPath;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                backupPath = ofd.FileName;
            }
            else
            {
                return;
            }

            if (File.Exists(backupPath))
            {
                SetPort sp = new SetPort();
                sp.ShowDialog(this);
                if (sp.portSet)
                {
                    System.Diagnostics.Process p = new System.Diagnostics.Process();             //Create process object
                    p.StartInfo.FileName        = Environment.GetEnvironmentVariable("ComSpec"); //Get ComSpec(cmd.exe) path, and set to FileName property
                    p.StartInfo.UseShellExecute = false;
                    //p.StartInfo.RedirectStandardOutput = true; //Make output readable
                    //p.StartInfo.RedirectStandardInput = false;
                    p.StartInfo.CreateNoWindow   = false;                                                                                     //Display window
                    p.StartInfo.WorkingDirectory = Application.StartupPath;
                    p.StartInfo.Arguments        = "/c \"" + psql_path + "\" -h localhost -p " + sp.portNo + " -U postgres -f " + backupPath; //Set command line("/c" needed for close window after running)
                    sp.Dispose();
                    p.Start();
                    //string results = p.StandardOutput.ReadToEnd(); //Get output
                    p.WaitForExit(); //WaitForExit has to be after ReadToEnd
                    //p.Close();
                    //MessageBox.Show(results); //Show output
                    MessageBox.Show(Properties.Resources.ProcedureFinished, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    sp.Dispose();
                    MessageBox.Show(Properties.Resources.ProcedureCancelled, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("[Back up file]" + Properties.Resources.FileNotExist, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }