Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (tbCod.Text == "")
            {
                errorProvider1.SetError(tbCod, "Introduceti Codul!");
            }
            else if (tbNume.Text == "")
            {
                errorProvider1.SetError(tbNume, "Introduceti Numele!");
            }
            else if (tbAdresa.Text == "")
            {
                errorProvider1.SetError(tbAdresa, "Introduceti Adresa!");
            }
            else if (!rbPF.Checked && !rbPJ.Checked)
            {
                errorProvider1.SetError(groupBox1, "Introduceti tipul de persoana(PF/PJ)");
            }
            else if (tbSuma.Text == "")
            {
                errorProvider1.SetError(tbSuma, "Introduceti suma!");
            }
            else if (tbPlati.Text == "")
            {
                errorProvider1.SetError(tbPlati, "Introduceti datele platilor lunare");
            }
            else
            {
                try
                {
                    int    c = Convert.ToInt32(tbCod.Text);
                    string n = tbNume.Text;
                    string a = tbAdresa.Text;
                    string t = "";
                    if (rbPF.Checked)
                    {
                        t = "PF";
                    }
                    else if (rbPJ.Checked)
                    {
                        t = "PJ";
                    }
                    double   s      = Convert.ToDouble(tbSuma.Text);
                    string[] vector = tbPlati.Text.Split(',');
                    int[]    plati  = new int[vector.Length];
                    for (int i = 0; i < vector.Length; i++)
                    {
                        plati[i] = Convert.ToInt32(vector[i]);
                    }

                    ClientRauPlatnic cli = new ClientRauPlatnic(c, n, a, t, s, plati);
                    client.Add(cli);
                    client.Sort();
                    MessageBox.Show(cli.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    tbCod.Clear();
                    tbNume.Clear();
                    tbAdresa.Clear();
                    rbPF.Checked = false;
                    rbPJ.Checked = false;
                    tbSuma.Clear();
                    tbPlati.Clear();
                    errorProvider1.Clear();
                }
            }
        }