private void Button1_Click(object sender, EventArgs e)
        {
            citanje_iz_fajla_automobili();
            int praznaPolja  = 0;
            int pogresanUnos = 0;


            if (txtID.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtGodiste.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtMarka.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtModel.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtKubikaza.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtPogon.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtMenjac.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtKaroserija.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtGorivo.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (txtBrVrata.Text.Trim().Length == 0)
            {
                praznaPolja++;
            }

            if (praznaPolja != 0)
            {
                MessageBox.Show("Popunite sva polja");
            }

            if (praznaPolja == 0)
            {
                if (int.TryParse(txtID.Text, out int broj) == false)
                {
                    MessageBox.Show("Za ID unesite samo cifre");
                    pogresanUnos++;
                }


                if (int.TryParse(txtGodiste.Text, out broj) == false)
                {
                    MessageBox.Show("Za godiste unesite samo cifre");
                    pogresanUnos++;
                }

                if (int.TryParse(txtKubikaza.Text, out broj) == false)
                {
                    MessageBox.Show("Za kubikazu unesite samo cifre");
                    pogresanUnos++;
                }

                for (int i = 0; i < txtBrVrata.Text.Length; i++)
                {
                    bool jeste_cifra = txtBrVrata.Text.All(char.IsDigit);
                    if (jeste_cifra == false)
                    {
                        MessageBox.Show("Za broj vrata unesite samo cifre");
                        pogresanUnos++;
                        break;
                    }
                }
            }

            int greska = 0;

            if (praznaPolja == 0 && pogresanUnos == 0)
            {
                for (int i = 0; i < automobili.Count; i++)
                {
                    if (automobili[i].id == int.Parse(txtID.Text))
                    {
                        MessageBox.Show("Uneli ste postojeci ID.");
                        greska++;
                    }
                }
            }

            if (greska == 0 && praznaPolja == 0 && pogresanUnos == 0)
            {
                Automobil a = new Automobil(int.Parse(txtID.Text), int.Parse(txtGodiste.Text), int.Parse(txtKubikaza.Text),
                                            txtMarka.Text, txtModel.Text, txtPogon.Text, txtMenjac.Text,
                                            txtGorivo.Text, txtBrVrata.Text, txtKaroserija.Text);
                automobili.Add(a);
                upis_u_fajl_automobil();
                listAutaSvi.Items.Clear();
                IncijalizujListu();
                MessageBox.Show("Uspesno unet automobil.");

                listboxAutaPonuda.Items.Clear();
                inicijalizacija_spiska_auta();  /*listbox auta u odeljku ponuda*/

                txtID.Clear();
                txtMarka.Clear();
                txtModel.Clear();
                txtGodiste.Clear();
                txtBrVrata.Clear();
                txtKubikaza.Clear();
                txtKaroserija.Clear();
                txtPogon.Clear();
                txtMenjac.Clear();
                txtGorivo.Clear();
            }
        }
        private void BtnIzmeni_Click(object sender, EventArgs e)
        {
            citanje_iz_fajla_automobili();
            int selektovan;
            int greska = 0;

            if (listAutaSvi.SelectedItem == null)
            {
                MessageBox.Show("Niste selektovali automobil.");
                greska++;
            }

            if (greska == 0)
            {
                if (listAutaSvi.SelectedItem != listAutaSvi.Items[0])
                {
                    if (txtID.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtGodiste.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtMarka.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtModel.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtKubikaza.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtPogon.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtMenjac.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtKaroserija.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtGorivo.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (txtBrVrata.Text.Trim().Length == 0)
                    {
                        greska++;
                    }

                    if (greska != 0)
                    {
                        MessageBox.Show("Popunite sva polja");
                    }
                    else
                    {
                        if (int.TryParse(txtID.Text, out int broj) == false)
                        {
                            MessageBox.Show("Za ID unesite samo cifre");
                            greska++;
                        }


                        if (int.TryParse(txtGodiste.Text, out broj) == false)
                        {
                            MessageBox.Show("Za godiste unesite samo cifre");
                            greska++;
                        }

                        if (int.TryParse(txtKubikaza.Text, out broj) == false)
                        {
                            MessageBox.Show("Za kubikazu unesite samo cifre");
                            greska++;
                        }

                        for (int i = 0; i < txtBrVrata.Text.Length; i++)
                        {
                            bool jeste_cifra = txtBrVrata.Text.All(char.IsDigit);
                            if (jeste_cifra == false)
                            {
                                MessageBox.Show("Za broj vrata unesite samo cifre");
                                greska++;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Niste selektovali automobil.");
                    greska++;
                }

                if (greska == 0)
                {
                    for (selektovan = 0; selektovan < automobili.Count; selektovan++)
                    {
                        if (automobili[selektovan].id == id_selektovanog_auta)
                        {
                            for (int i = 0; i < automobili.Count; i++)
                            {
                                if (selektovan != i)
                                {
                                    if (automobili[i].id == int.Parse(txtID.Text))
                                    {
                                        MessageBox.Show("Unesli ste postojeci ID.");
                                        greska++;
                                    }
                                }
                            }

                            if (greska == 0)
                            {
                                Automobil a = new Automobil(int.Parse(txtID.Text), int.Parse(txtGodiste.Text), int.Parse(txtKubikaza.Text),
                                                            txtMarka.Text, txtModel.Text, txtPogon.Text, txtMenjac.Text,
                                                            txtGorivo.Text, txtBrVrata.Text, txtKaroserija.Text);
                                automobili[selektovan] = a;
                                upis_u_fajl_automobil();
                                listAutaSvi.Items.Clear();
                                IncijalizujListu();
                                MessageBox.Show("Uspesno izmenjeni podaci o automobilu.");

                                listboxAutaPonuda.Items.Clear();
                                inicijalizacija_spiska_auta();  /*listbox auta u odeljku ponuda*/

                                txtID.Clear();
                                txtMarka.Clear();
                                txtModel.Clear();
                                txtGodiste.Clear();
                                txtBrVrata.Clear();
                                txtKubikaza.Clear();
                                txtKaroserija.Clear();
                                txtPogon.Clear();
                                txtMenjac.Clear();
                                txtGorivo.Clear();
                            }
                        }
                    }
                }
            }
        }