Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Устанавливается новая строка подключения
            DataBaseConnect.ConnectParam Dbcp = new DataBaseConnect.ConnectParam(DataBaseConnect.AttachDBFilename);

            try
            {
                //перебивается стока в конфиге с учетом нового пути
                DataBaseConnect.ConnectionStrings(Dbcp);

                if (DataBaseConnect.IsServerConnected())
                {
                    ConnectionYes = "Connection with DB is build. ";
                    DialogResult resultYes = MessageBox.Show(
                        ConnectionYes + "Do you intend to continue saving data in the DB [yes]?"
                        + " or choose any other DB [no] ",
                        "Result of Connection",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);

                    if ((resultYes == DialogResult.Yes) || (resultYes == DialogResult.None))
                    {
                        Form1 frm1 = new Form1(); //если пользователь выбирает "yes" , загружаем основную форму
                        frm1.Show();
                        this.Hide();              // и закрываем эту
                    }
                }
                else
                {
                    ConnectionNo = "Connection with DB is failed";
                    DialogResult resultNo = MessageBox.Show(
                        ConnectionNo + " Do you want to try to connect once again? [yes] ",
                        "Result of Connection",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    if ((resultNo == DialogResult.No) || (resultNo == DialogResult.None))
                    {
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                if (DataBaseConnect.l_oConnection != null)
                {
                    DataBaseConnect.l_oConnection.Close();
                }

                this.Close();

                //throw new DataException("Соединение с базой отсутствует");
            }
            finally
            {}
        }
Example #2
0
 private void ConnectSetting()
 {
     try
     {
         if (DataBaseConnect.IsServerConnected())
         {
             if (backgroundWorker1.IsBusy == true)
             {
                 backgroundWorker1.CancelAsync();
             }
         }
     }
     catch (DataException exdb)
     {
         throw new DataException("Соединение с базой отсутствует");
     }
     finally
     {
     }
 }