예제 #1
0
 private void OtvoriPostavke()
 {
     try
     {
         frmPsw Psw = new frmPsw();
         Psw.ShowDialog();
         var file = Psw.SavedFileName();
         if (File.Exists(xmlFilePath))
         {
             FillServersAndSettingsFromXml();
         }
         PostaviKontrole(false);
         DodajServere();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #2
0
        private void btnSpojiSe_Click(object sender, EventArgs e)
        {
            if (cboServer.SelectedIndex == cboServer.Items.Count - 1)
            {
                if (!string.IsNullOrEmpty(Properties.Settings.Default.LastUsedAccdb))
                {
                    string password = "";
                    string connError = "";
                    string connString = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + Properties.Settings.Default.LastUsedAccdb + "; Persist Security Info = False; Mode = Share Deny None";
                    System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
                    conn.ConnectionString = connString;
                    try
                    {
                        conn.Open();
                    }
                    catch (Exception ex)
                    {
                        connError = ex.Message;
                    }
                    finally
                    {
                        if (connError == "Not a valid password.")
                        {
                            frmPsw pass = new frmPsw(true);
                            pass.ShowDialog();
                            password = pass.EnteredPassword();
                            connString = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + Properties.Settings.Default.LastUsedAccdb + "; Persist Security Info = False; Mode = Share Deny None;Jet OLEDB:Database Password = "******"";
                        conn.Open();
                        MessageBox.Show("Connection succesfull!");
                        LoginClass.ConnString = connString;
                        btnPrijava.Enabled = true;
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }

                    Properties.Settings.Default.LastConnBase = "";
                    Properties.Settings.Default.LastConnServer = cboBaza.SelectedText;
                    Properties.Settings.Default.LastUsedAccdb = txtChosenDatabaseFile.Text;
                    //Properties.Settings.Default.AccessConnectionString = connString;
                    Properties.Settings.Default.Save();

                    //PRIMJER!!!!!!!!!!!!!!!!!!!
                    //try
                    //{
                    //    conn.Open();
                    //    var conop = conn.State;
                    //    string sql = "select * from [tblEmployees]";
                    //    System.Data.DataSet ds = new System.Data.DataSet();
                    //    DataGridView dataGridView1 = new DataGridView();
                    //    using (System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(sql, conn))
                    //    {
                    //        adapter.Fill(ds);
                    //        dataGridView1.DataSource = ds;
                    //        // Of course, before addint the datagrid to the hosting form you need to
                    //        // set position, location and other useful properties.
                    //        // Why don't you create the DataGrid with the designer and use that instance instead?
                    //        this.Controls.Add(dataGridView1);
                    //    }
                    //}
                    //catch (Exception ex)
                    //{
                    //    MessageBox.Show(ex.Message);
                    //    //MessageBox.Show("Failed to connect to data source");
                    //}
                    //finally
                    //{
                    //    conn.Close();
                    //}
                }
                else
                {
                    MessageBox.Show("Datoteka nije odabrana.", "Greška", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                if (cboServer.Text == string.Empty)
                {
                    MessageBox.Show("Izaberite server na koji se spajate!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (ProvjeriPostavke(cboServer.Text) == false)
                {
                    MessageBox.Show("U postavkama nije upisan korisnik!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                try
                {
                    DodajBaze(cboServer.Text);
                    cboServer.Enabled = false;
                    btnSpojiSe.Enabled = false;
                    btnOdspoji.Enabled = true;

                    cboBaza.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }