예제 #1
0
        private void buttonVehicleAdd_Click_1(object sender, EventArgs e)
        {
            textBoxCapacityValue.Text = textBoxCapacityValue.Text.Replace(',', '.');
            textBoxVolumeValue.Text   = textBoxVolumeValue.Text.Replace(',', '.');

            if (textBoxCapacityValue.Text == "")
            {
                errorProvider1.SetError(textBoxCapacityValue, "Pole nie moze byc puste!");
            }
            else if (textBoxVolumeValue.Text == "")
            {
                errorProvider2.SetError(textBoxVolumeValue, "Pole nie moze byc puste!");
            }
            else if (textBoxRegistrationNrValue.Text == "")
            {
                errorProvider3.SetError(textBoxRegistrationNrValue, "Pole nie moze byc puste!");
            }
            else
            {
                double capacity, volume;
                if (double.TryParse(textBoxCapacityValue.Text, NumberStyles.Any, culture, out capacity) &&
                    double.TryParse(textBoxVolumeValue.Text, NumberStyles.Any, culture, out volume))
                {
                    RegistrationNr = RegistrationNr.ToUpper();
                    Vehicle vehicle = new Vehicle(RegistrationNr, Capacity, Volume);

                    if (AddVehicle(vehicle))
                    {
                        textBoxRegistrationNrValue.Clear();
                        textBoxCapacityValue.Clear();
                        textBoxVolumeValue.Clear();
                        MessageBox.Show("Pomyślnie dodano pojazd");
                    }
                }
                else
                {
                    errorProvider1.SetError(textBoxCapacityValue, "Zly typ danych");
                    errorProvider2.SetError(textBoxVolumeValue, "Zly typ danych");
                }
            }
        }
예제 #2
0
        private void buttonVehicleEdit_Click(object sender, EventArgs e)
        {
            if (textBoxRegistrationNumerValue.Text == "")
            {
                errorProvider1.SetError(textBoxRegistrationNumerValue, "Pole nie może być puste!");
            }
            else if (textBoxCapacityValue.Text == "")
            {
                errorProvider2.SetError(textBoxCapacityValue, "Pole nie może być puste!");
            }
            else if (textBoxVolumeValue.Text == "")
            {
                errorProvider3.SetError(textBoxVolumeValue, "Pole nie może być puste!");
            }
            else
            {
                textBoxVolumeValue.Text   = textBoxVolumeValue.Text.Replace(',', '.');
                textBoxCapacityValue.Text = textBoxCapacityValue.Text.Replace(',', '.');

                double capacity, volume;
                if (double.TryParse(textBoxCapacityValue.Text, NumberStyles.Any, culture, out capacity) &&
                    double.TryParse(textBoxVolumeValue.Text, NumberStyles.Any, culture, out volume))
                {
                    RegistrationNr = RegistrationNr.ToUpper();

                    if (UpdateVehicleInfo(VehicleID, RegistrationNr, Capacity, Volume))
                    {
                        textBoxRegistrationNumerValue.Clear();
                        textBoxCapacityValue.Clear();
                        textBoxVolumeValue.Clear();
                        MessageBox.Show("Pomyślnie edytowano pojazd.");
                    }
                }
                else
                {
                    errorProvider1.SetError(textBoxCapacityValue, "Nieprawidlowa wartosc");
                }
            }
        }