コード例 #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.");
                }
            }
        }
コード例 #2
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            if (
                !AdditionalFunctions.isEmpty(id) &&
                !AdditionalFunctions.isEmpty(name) &&
                !AdditionalFunctions.isEmpty(birth_date) &&
                !AdditionalFunctions.isEmpty(role) &&
                !AdditionalFunctions.isEmpty(username) &&
                !AdditionalFunctions.isEmpty(password) &&
                !AdditionalFunctions.isEmpty(secPassword) &&
                !AdditionalFunctions.isEmpty(phoneNumber) &&
                !AdditionalFunctions.isEmpty(gender) &&
                !AdditionalFunctions.isEmpty(street) &&
                !AdditionalFunctions.isEmpty(house_num) &&
                !AdditionalFunctions.isEmpty(city) &&
                !AdditionalFunctions.isEmpty(zip_code) &&
                isChanged
                )
            {
                if (password == secPassword)
                {
                    if (submitButton.Text == "Update")
                    {
                        try {
                            bool res = db.updateEmployee(
                                new Employee(
                                    id,
                                    name,
                                    new SqlDate(birth_date),
                                    role,
                                    username,
                                    password,
                                    phoneNumber,
                                    new Address(
                                        street,
                                        int.Parse(house_num),
                                        city,
                                        zip_code,
                                        0.0,
                                        0.0
                                        )
                                    ),
                                address,
                                addressID
                                );

                            if (res)
                            {
                                Close();
                                parent.refreshTable(TabChooser.Employees);
                            }
                            else
                            {
                                MessageBox.Show($"Error occord with { name }'s update, Please try again later.");
                                Close();
                            }
                        } catch (Exception ex) {
                            MessageBox.Show($"Error occord with { name }'s update, Please try again later.");
                            Close();
                        }
                    }
                    else
                    {
                        db.addNewEmploeey(
                            new Employee(
                                id,
                                name,
                                new SqlDate(birth_date),
                                role, username,
                                AdditionalFunctions.MD5(AdditionalFunctions.MD5(password)),
                                phoneNumber,
                                gender,
                                address
                                )
                            );
                    }
                }
            }
            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.");
                }

                if (AdditionalFunctions.isEmpty(id))
                {
                    idTextBox.BackColor = Color.Red;
                }
            }
        }