Example #1
0
        private void createCarBtn_Click(object sender, EventArgs e)
        {
            if (createCarBtn.Text == "Update" && carId != null)
            {
                if (
                    !AdditionalFunctions.isEmpty(code) &&
                    !AdditionalFunctions.isEmpty(model) &&
                    !AdditionalFunctions.isEmpty(creationDate) &&
                    !AdditionalFunctions.isEmpty(driverId) &&
                    isChanged
                    )
                {
                    try {
                        bool res = db.updateCar(
                            new Car(
                                AdditionalFunctions.trimFlWhitespaces(code),
                                AdditionalFunctions.trimFlWhitespaces(model),
                                new SqlDate(AdditionalFunctions.trimFlWhitespaces(creationDate)),
                                AdditionalFunctions.trimFlWhitespaces(driverId)
                                ),
                            carId);

                        if (res)
                        {
                            Close();
                            parent.refreshTable(TabChooser.Cars);
                        }
                        else
                        {
                            MessageBox.Show("Error occord with Car's update, Please try again later.");
                            Close();
                        }
                    } catch (Exception ex) {
                        MessageBox.Show("Error occord with Car's update, Please try again later.");
                        Close();
                    }
                }
                else
                {
                    if (!isChanged)
                    {
                        MessageBox.Show("No data has changed, If you want to close please click the X button on the top");
                    }
                    else
                    {
                        MessageBox.Show("One of the fields are not filled, Please fill and try again.");
                    }
                }
            }
            else
            {
                if (
                    !AdditionalFunctions.isEmpty(code) &&
                    !AdditionalFunctions.isEmpty(model) &&
                    !AdditionalFunctions.isEmpty(creationDate) &&
                    !AdditionalFunctions.isEmpty(driverId)
                    )
                {
                    bool res = db.addNewCar(new Car(
                                                AdditionalFunctions.trimFlWhitespaces(code),
                                                AdditionalFunctions.trimFlWhitespaces(model),
                                                new SqlDate(AdditionalFunctions.trimFlWhitespaces(creationDate)),
                                                AdditionalFunctions.trimFlWhitespaces(driverId)
                                                ));

                    if (res)
                    {
                        Close();
                        parent.refreshTable(TabChooser.Cars);
                    }
                    else
                    {
                        MessageBox.Show("Error occord with Car's creation, Please try again later.");
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("One of the fields are not filled, Please fill and try again.");
                }
            }
        }
Example #2
0
        private void addNewATMButton_Click(object sender, EventArgs e)
        {
            if (
                atmSize != (int)AtmSize.NONE &&
                capacity > 0 &&
                !AdditionalFunctions.isEmpty(brand) &&
                !AdditionalFunctions.isEmpty(street) &&
                !AdditionalFunctions.isEmpty(houseNumber) &&
                !AdditionalFunctions.isEmpty(zipCode) &&
                !AdditionalFunctions.isEmpty(city) &&
                !AdditionalFunctions.isEmpty(lat) &&
                !AdditionalFunctions.isEmpty(lng) &&
                isChanged
                )
            {
                // Add new changes into the database
                Address addr = new Address(
                    AdditionalFunctions.trimFlWhitespaces(street),
                    int.Parse(AdditionalFunctions.trimFlWhitespaces(houseNumber)),
                    AdditionalFunctions.trimFlWhitespaces(city),
                    AdditionalFunctions.trimFlWhitespaces(zipCode),
                    AdditionalFunctions.isEmpty(AdditionalFunctions.trimFlWhitespaces(lat)) ? 0.0 : double.Parse(lat),
                    AdditionalFunctions.isEmpty(AdditionalFunctions.trimFlWhitespaces(lng)) ? 0.0 : double.Parse(lng)
                    );

                if (addNewATMButton.Text == "Update")
                {
                    try {
                        bool res = db.updateATM(
                            new ATM(
                                addr,
                                capacity,
                                (int)atmSize,
                                brand
                                ),
                            db.getAddressByID(baseAddressId),
                            atmId,
                            baseAddressId
                            );

                        MessageBox.Show($"ATM number {atmId} updated successfuly");
                        Close();
                    } catch (Exception ex) {
                        Console.WriteLine(ex);
                        MessageBox.Show("Error occord with ATM's update, Please try again later.");
                        Close();
                    }
                }
                else
                {
                    bool res = db.addNewATM(
                        new ATM(
                            addr,
                            capacity,
                            (int)atmSize,
                            AdditionalFunctions.trimFlWhitespaces(brand)
                            )
                        );
                }
            }
            else
            {
                if (!isChanged)
                {
                    MessageBox.Show("No data has changed, If you want to close please click the X button on the top");
                }
                else
                {
                    MessageBox.Show("One of the fields are not filled, Please fill and try again.");
                }
            }
        }