Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.CheckedItems.Count == checkedListBox1.Items.Count)
            {
                if (dosar != null)
                {
                    listaCandidati.Add(this.candidat);
                    OleDbConnection conexiune = new OleDbConnection(connString);
                    try
                    {
                        conexiune.Open();
                        OleDbCommand comanda = new OleDbCommand();
                        comanda.Connection = conexiune;

                        comanda.CommandText = "SELECT MAX(nrcrt) FROM Studenti";
                        int nrCrt = Convert.ToInt32(comanda.ExecuteScalar());

                        comanda.CommandText = "INSERT INTO Studenti VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";

                        comanda.Parameters.Add("nrcrt", OleDbType.Integer).Value           = nrCrt + 1;
                        comanda.Parameters.Add("nume", OleDbType.VarChar).Value            = candidat.nume;
                        comanda.Parameters.Add("initiala", OleDbType.Char, 5).Value        = candidat.initialaTatalui;
                        comanda.Parameters.Add("prenume", OleDbType.VarChar).Value         = candidat.prenume;
                        comanda.Parameters.Add("facultate", OleDbType.VarChar).Value       = candidat.facultateAleasa.Nume;
                        comanda.Parameters.Add("specializare", OleDbType.VarChar).Value    = candidat.optiuneFacultate;
                        comanda.Parameters.Add("medie BAC", OleDbType.Double).Value        = candidat.medii.MedieBAC;
                        comanda.Parameters.Add("medie liceu", OleDbType.Double).Value      = candidat.medii.MedieLiceu;
                        comanda.Parameters.Add("nota departajare", OleDbType.Double).Value = candidat.medii.NotaRomana;

                        comanda.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        //conexiune.Close();
                        MessageBox.Show(candidat.afisareNumeComplet() + "a fost adaugat!");
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Descarcati dosarul!");
                }
            }
            else
            {
                MessageBox.Show("Nu au fost introduse toate documentele!");
            }
        }
        //adaugare candidat
        private void button2_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.SelectedIndex == -1)
            {
                errorProvider1.SetError(checkedListBox1, "Selectati o optiune!");
            }
            else
            if (tbMedieBAC.Text == "")
            {
                errorProvider1.SetError(tbMedieBAC, "Introduceti media de BAC!");
            }
            else
            if (tbMedieLiceu.Text == "")
            {
                errorProvider1.SetError(tbMedieLiceu, "Introduceti media din liceu!");
            }
            else
            if (tbNotaRomana.Text == "")
            {
                errorProvider1.SetError(tbNotaRomana, "Introduceti nota!");
            }
            else
            {
                try
                {
                    string nume            = tbNume.Text;
                    string initialaTatalui = tbInitiala.Text;
                    string prenume         = tbPrenume.Text;
                    char   sex             = Convert.ToChar(cbSex.SelectedItem.ToString());
                    long   cnp             = Convert.ToInt64(tbCNP.Text);
                    string serie           = tbSerie.Text;
                    int    numar           = Convert.ToInt32(tbNumar.Text);
                    int    telefon         = Convert.ToInt32(tbTelefon.Text);
                    string email           = tbEmail.Text;
                    string tara            = tbTara.Text;
                    string judet           = tbJudet.Text;
                    string localitate      = tbLocalitate.Text;
                    string adresa          = tbAdresa.Text;

                    Facultate facultateAleasa = null;
                    foreach (Facultate f in listaFacultati)
                    {
                        if (lbFacultati.SelectedItem.ToString() == f.Nume)
                        {
                            facultateAleasa = f;
                        }
                    }

                    string optiuneAleasa = checkedListBox1.CheckedItems[0].ToString();

                    double medieBAC   = 0;
                    double notaRomana = 0;
                    double medieLiceu = 0;

                    if (Convert.ToDouble(tbMedieBAC.Text) > 10 || Convert.ToDouble(tbMedieLiceu.Text) > 10 ||
                        Convert.ToDouble(tbNotaRomana.Text) > 10)
                    {
                        MessageBox.Show("Nota este prea mare!");
                    }
                    else
                    {
                        medieBAC   = Convert.ToDouble(tbMedieBAC.Text);
                        medieLiceu = Convert.ToDouble(tbMedieLiceu.Text);
                        notaRomana = Convert.ToDouble(tbNotaRomana.Text);

                        Medii medii = new Medii(medieBAC, medieLiceu, notaRomana);

                        Document dosar = null;

                        Candidat c = new Candidat(nume, initialaTatalui, prenume, sex, cnp, serie, numar, telefon, email, tara, judet,
                                                  localitate, adresa, facultateAleasa, medii, optiuneAleasa, dosar);

                        MessageBox.Show("Datele pentru " + c.afisareNumeComplet() + " au fost introduse cu succes!");

                        FormDocumente form4 = new FormDocumente(listaCandidati, c);
                        form4.Show();

                        resetareFormular();
                    }
                }
                catch
                {
                    MessageBox.Show("Exista campuri completate incorect!");
                }
                finally
                {
                    errorProvider1.Clear();
                }
            }
        }