コード例 #1
0
        private void GetCarValues(object sender, EventArgs e)
        {
            bool success = false;
            Auto newAuto = new Auto();

            if (newAuto.Id == 0)
            {
                ID_Label.Text = "ID: Not saved";
            }
            else
            {
                // newAuto.Id =;
            }

            //Price Type Check
            success = decimal.TryParse(hinta.Text, out decimal autonHinta);
            if (success)
            {
                newAuto.Hinta = autonHinta;
            }
            else
            {
                MessageBox.Show("Price can only be numbers");
            }

            //Mileage Type Check
            success = int.TryParse(mittarilukema.Text, out int setMittari);
            if (success)
            {
                newAuto.Mittarilukema = setMittari;
            }
            else
            {
                MessageBox.Show("Mileage can only be numbers");
            }

            //Engine Capacity Type Check
            success = decimal.TryParse(tilavuus.Text, out decimal MoTilavuus);
            if (success)
            {
                newAuto.Moottorin_tilavuus = MoTilavuus;
            }
            else
            {
                MessageBox.Show("Engine capacity can only be numbers");
            }



            Console.WriteLine(paivamaara_Picker);

            Merkki_cBox.ValueMember = "ID";
            try
            {
                newAuto.AutonMerkkiID = (Merkki_cBox.SelectedItem as AutonMerkki).Id;

                newAuto.AutonMalliID = (Malli_cBox.SelectedItem as AutonMalli).Id;

                newAuto.PolttoaineID = (fuel_cBox.SelectedItem as Polttoaine).Id;

                newAuto.VaritID = (color_cBox.SelectedItem as Varit).Id;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Choose all values from the boxes");
                Console.WriteLine(ex);
            }


            //FIX DATE FORMATTING
            newAuto.Rekisteri_paivamaara = paivamaara_Picker.Value.Date;

            registerHandler.saveAuto(newAuto);
        }