Ejemplo n.º 1
0
        private async void save(object sender, EventArgs e)
        {
            var brand = brandTextBox.Text;
            var model = modelTextBox.Text;
            var type  = 0;

            if (typeComboBox.Text != "")
            {
                type = (int)((CarType)Enum.Parse(typeof(CarType), typeComboBox.SelectedItem.ToString()));
            }
            var odometer           = odometerTextBox.Value;
            var registrationNumber = registrationNumberTextBox.Text;
            var efficiency         = efficiencyCheckBox.Checked;
            var isDisabled         = isDisabledCheckBox.Checked;
            var imageUrl           = imageUrlTextBox.Text;

            if (checkCorectness(brand, model, type, odometer, registrationNumber, efficiency, isDisabled))
            {
                await DatabaseService.insertCar(brand, model, type, odometer, registrationNumber, efficiency? 1 : 0, isDisabled? 1 : 0, imageUrl).ContinueWith(task =>
                {
                    bool result = task.Result;
                    if (result)
                    {
                        MessageBox.Show("Samochod zostal zapisany w bazie danych");
                        if (InvokeRequired)
                        {
                            Invoke(new Action(() => showParent()));
                        }
                        else
                        {
                            showParent();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Samochod o tej rejestracji juz istnieje w bazie danych!");
                    }
                });
            }
        }