Esempio n. 1
0
 private void rbnBtnDBConnect_Click(object sender, EventArgs e)
 {
     try
     {
         if (rbnCboDBs.Text != "Select or Add Database")
         {
             if (DBC.IsConnected)
             {
                 if (!DBC.Disconnect())
                 {
                     MessageBox.Show(
                         "Cannot disconnect current connection.\nPlease try again later !",
                         "Can not disconnect", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
                     return;
                 }
                 else
                 {
                     rbnMain.StatusBar.Text = rbnMain.StatusBar.Text.Replace("connected", "disconnected");
                 }
             }
             DBC.ConnectionString =
                 new System.Data.SqlClient.SqlConnection(rbnCboDBs.Text.Trim('*'));
             if (!DBC.Connect())
             {
                 MessageBox.Show(
                     "Cannot connect to DB.\nPlease try again later !",
                     "Can not connect", MessageBoxButtons.OK,
                     MessageBoxIcon.Error);
                 return;
             }
             else
             {
                 rbnMain.StatusBar.Text = rbnMain.StatusBar.Text.Replace("disconnected", "connected");
             }
         }
         else
         {
             MessageBox.Show(
                 "Please select a connection to connect to !",
                 "No connection specified", MessageBoxButtons.OK,
                 MessageBoxIcon.Error);
             return;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(
             ex.Message,
             "Connecting to DB Error", MessageBoxButtons.OK,
             MessageBoxIcon.Error);
     }
 }
Esempio n. 2
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            try
            {
                SC = new systemController(Application.StartupPath);
                int status = SC.Initialize();

                if (status == -1)
                {
                    Exception ex = new Exception("System failed to load some or all of its components !");
                }

                //Filling the lists of history and DB connections :
                fillHistoryList(SC.HistoryList);
                fillDBConnList(SC.DBConnectionList);

                //Connect to default connection
                DBC = new databaseController(
                    new System.Data.SqlClient.SqlConnection(SC.DefaultConnectionString));

                if (!DBC.Connect())
                {
                    Exception ex = new Exception("The default database connection is not valid !\nPlease select or add another connection string");
                }
                if (DBC.IsConnected)
                {
                    rbnMain.StatusBar.Text = rbnMain.StatusBar.Text + "connected.";
                    picLstResults.Items.Clear();
                    viewAllImages();
                }
                else
                {
                    rbnMain.StatusBar.Text = rbnMain.StatusBar.Text + "disconnected.";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Loading The System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (DBC.IsConnected)
                {
                    rbnMain.StatusBar.Text = rbnMain.StatusBar.Text + "connected.";
                    picLstResults.Items.Clear();
                    viewAllImages();
                }
                else
                {
                    rbnMain.StatusBar.Text = rbnMain.StatusBar.Text + "disconnected.";
                }
            }
        }