private void btnssrsbck_Click(object sender, EventArgs e)
        {
            SQLServer rd = new SQLServer();

            rd.Show();
            this.Close();
        }
        private void lblsql_Click(object sender, EventArgs e)
        {
            SQLServer app = new SQLServer();

            app.Show();
            this.Close();
        }
Example #3
0
        public void Execute(bool isNormalExecution = true)
        {
            try
            {
                bool          blnsqlderr = false;
                var           _rootpath  = Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Resources");
                string        script     = Path.Combine(_rootpath, scriptName + ".ps1");
                string        scriptText = File.ReadAllText(script);
                StringBuilder sb         = new StringBuilder();
                var           powershell = new PowerShellHelper();
                var           runspace   = powershell.CreateRunSpace(Application.ExecutablePath, scriptName);
                runspace.Open();
                Pipeline pipeline  = runspace.CreatePipeline();
                Command  myCommand = new Command(scriptText, true);

                var sqlWindowsAuthParam = new CommandParameter(null, "w");
                var sqlServerParam      = new CommandParameter(null, FormElements.Credential.SqlInstanceName);
                var sqlUserName         = new CommandParameter(null, FormElements.Credential.SqlUserName);
                var sqlPwd = new CommandParameter(null, FormElements.Credential.SqlPassword);
                if (FormElements.Credential.SqlAuthMode != "w")
                {
                    sqlWindowsAuthParam = new CommandParameter(null, "network");
                }

                myCommand.Parameters.Add(sqlWindowsAuthParam);
                myCommand.Parameters.Add(sqlServerParam);

                myCommand.Parameters.Add(sqlUserName);
                myCommand.Parameters.Add(sqlPwd);

                foreach (var item in FormElements.SQLServerDiagnostics)
                {
                    if (chklstApp.CheckedIndices.Contains(item.id))
                    {
                        var param5 = new CommandParameter(null, 1);
                        myCommand.Parameters.Add(param5);
                    }
                    else
                    {
                        var param5 = new CommandParameter(null, 0);
                        myCommand.Parameters.Add(param5);
                    }
                }

                pipeline.Commands.Add(myCommand);
                Collection <PSObject> results = pipeline.Invoke();
                var errors = pipeline.Error;
                // CSV or Error file Generation code
                var generateCSV = new Csvhelper();
                generateCSV.WriteOutput(Application.ExecutablePath, scriptName, results, pipeline, this.timeStamp, out blnsqlderr);
                // CSV or Error file Generation code
                //Profilecreation();
                if (blnsqlderr)
                {
                    //MessageBox.Show("Error Occured.for more detail kindly check Sql Diagnostics Log!!\r\n", "Error Message");
                    //return;
                }
                else
                {
                    if (isNormalExecution)
                    {
                        var profileHelper = new ProfileHelper();
                        profileHelper.SetProfileData <SQLServerDiagnosticsModel>(Application.ExecutablePath, scriptName, FormElements, chklstApp);
                    }
                }
                runspace.Close();

                //DialogResult dialogResult = MessageBox.Show("SQL Server Diagnostics scripts executed successfully.Do you want to execute next script?", "Success", MessageBoxButtons.YesNo);
                //if (dialogResult == DialogResult.Yes)
                //{
                //    //do something
                //    SQLServer objfrm = new SQLServer();
                //    objfrm.Show();
                //    this.Close();
                //}
                //else if (dialogResult == DialogResult.No)
                //{
                //    SQLServerDiagnostics objfrm = new SQLServerDiagnostics();
                //    objfrm.Show();
                //    this.Close();
                //}

                if (isNormalExecution)
                {
                    SQLServerDiagnosticslogs frmsqld = new SQLServerDiagnosticslogs();
                    DialogResult             dr      = frmsqld.ShowDialog(this);
                    if (dr == DialogResult.Cancel)
                    {
                        //frmapplog.Close();
                    }
                    else if (dr == DialogResult.OK)
                    {
                        //textBox1.Text = frm2.getText();
                        //frmapplog.Close();
                        this.Enabled = true;

                        SQLServer objfrm = new SQLServer();
                        objfrm.Show();
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Occured.for more detail kindly check SQL Server Diagnostics Log!!\r\n" + "\r\n" + ex.Message.ToString(), "Error Message");
            }
        }