Esempio n. 1
0
        public void loadListAuto()
        {
            tbAverage.Clear();
            tbExpensive.Clear();
            tbEconomic.Clear();
            foreach (Automobile automobile in lbAutomobiles.Items)
            {
                auto.Add(automobile);
            }
            float sumOfPotroshuvacka = 0;

            if (auto != null)
            {
                Automobile najekonomicen = auto[0];
                Automobile maxAuto       = auto[0];

                foreach (Automobile automobile in auto)
                {
                    if (maxAuto.Cena < automobile.Cena)
                    {
                        maxAuto = automobile;
                    }
                    if (najekonomicen.Potroshuvacka > automobile.Potroshuvacka)
                    {
                        najekonomicen = automobile;
                    }
                    sumOfPotroshuvacka += (float)automobile.Potroshuvacka;
                }
                tbAverage.Text     = string.Format("{0:#.0}", sumOfPotroshuvacka / lbAutomobiles.Items.Count);
                tbExpensive.Text   = maxAuto.ToString();
                tbEconomic.Text    = najekonomicen.ToString();
                sumOfPotroshuvacka = 0;
            }
        }
Esempio n. 2
0
 private void calculateTotal()
 {
     if (lstCars.Items.Count > 0)
     {/* mora da se proveri dali ima elementi vo listata, ako ne proveri programata kje padne
       * i kje frli exception deka ne postojat elementi, so ovaa proverka toj problem se odbegnuva */
         float      avg           = 0;
         float      sum           = 0;
         Automobile najekonomicen = lstCars.Items[0] as Automobile;
         Automobile najskap       = lstCars.Items[0] as Automobile;
         foreach (object obj in lstCars.Items)
         {
             Automobile c = obj as Automobile;
             sum += c.Spending;
             if (najekonomicen.Spending > c.Spending)
             {
                 najekonomicen = c;
             }
             if (najskap.Price < c.Price)
             {
                 najskap = c;
             }
         }
         avg = sum / lstCars.Items.Count;
         tbProsecnaPotrosuvacka.Text = string.Format("{0:0.0} L", avg.ToString());
         tbNajekonomicen.Text        = najekonomicen.ToString();
         tbNajskap.Text = najskap.ToString();
     }
     else
     {//svojstvoto Text go vrakja vo default vrednost ako gorniot uslov ne e ispolnet
         tbProsecnaPotrosuvacka.Text = null;
         tbNajekonomicen.Text        = null;
         tbNajskap.Text = null;
     }
 }
Esempio n. 3
0
        private void btnAddAutomobile_Click(object sender, EventArgs e)
        {
            if (cbMarka.Text.Trim().Length == 0)
            {
                MessageBox.Show("Изберете марка", "Error", MessageBoxButtons.OK);
            }
            else if (tbModel.Text.Trim().Length == 0)
            {
                MessageBox.Show("Внесете модел", "Error", MessageBoxButtons.OK);
            }
            else
            {
                automobile = new Automobile(tbModel.Text.Trim(), (int)nudPotrosuvacka.Value, (int)nudCena.Value);
                automobile.addMarka(cbMarka.SelectedItem as Marka);
                lbAutomobiles.Items.Add(automobile);
                loadListAuto();
                tbModel.Clear();

                nudPotrosuvacka.Value = 0;
                nudPotrosuvacka.ResetText();


                nudCena.Value = 0;
                nudCena.ResetText();

                cbMarka.Text = null;
                cbMarka.ResetText();
            }
        }
Esempio n. 4
0
 private void btnAddCar_Click(object sender, EventArgs e)
 {
     if (cbBrands.SelectedIndex == -1)
     {
         MessageBox.Show("Изберете марка!", "Информација!", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
     }
     else if (string.IsNullOrWhiteSpace(tbModel.Text))
     {
         MessageBox.Show("Внесете модел!", "Информација!", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
     }
     else
     {
         Brand      brand = cbBrands.SelectedItem as Brand;
         Automobile m     = new Automobile(brand, tbModel.Text, (float)numPotrosuvacka.Value, Convert.ToInt32(numPrice.Value));
         lstCars.Items.Add(m);
         calculateTotal();
         tbModel.Text           = null;
         numPotrosuvacka.Value  = 0;
         numPrice.Value         = 0;
         cbBrands.SelectedIndex = -1;
     }
 }