예제 #1
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            Hide();

            string query = "INSERT INTO Customers (Id, FirstName, LastName, Address, Phone) " +
                           "VALUES (@id, @firstName, @lastName, @address, @phoneNumber)";

            GetCustomerId();

            conn.Open();

            command = new SQLiteCommand(query, conn);

            if (txtFirstName.Text == "" || txtLastName.Text == "" || txtAddress.Text == "" || txtPhoneNo.Text == "")
            {
                MessageBox.Show("Please fill in all the details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                command.Parameters.AddWithValue("@id", _customerId);
                command.Parameters.AddWithValue("@firstName", txtFirstName.Text.Substring(0, 1).ToUpper(CultureInfo.CurrentCulture) + txtFirstName.Text.Substring(1));
                command.Parameters.AddWithValue("@lastName", txtLastName.Text.Substring(0, 1).ToUpper(CultureInfo.CurrentCulture) + txtLastName.Text.Substring(1));
                command.Parameters.AddWithValue("@address", txtAddress.Text.Substring(0, 1).ToUpper(CultureInfo.CurrentCulture) + txtAddress.Text.Substring(1));
                command.Parameters.AddWithValue("@phoneNumber", txtPhoneNo.Text);

                command.ExecuteNonQuery();

                MessageBox.Show("Customer Added", "Customer Addition", MessageBoxButtons.OK, MessageBoxIcon.None);
            }

            conn.Close();

            frmHome home = new frmHome();

            home.Show();
        }
예제 #2
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            Hide();

            // Cars Add

            string queryCar = "INSERT INTO Cars (Id, CarMake, CarModel, NumberPlate, RoadTax, RoadTaxDuration, MOT, MOTDuration) " +
                              "VALUES (@id, @carMake, @carModel, @numberPlate, @roadTax, @roadTaxDuration, @MOT, @MOTDuration)";

            GetCarId();

            conn.Open();

            command = new SQLiteCommand(queryCar, conn);

            if (txtCarMake.Text == "" || txtCarModel.Text == "" || txtNumberPlate.Text == "")
            {
                MessageBox.Show("Please enter the car make, model and number plate.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                command.Parameters.AddWithValue("@id", _carId);
                command.Parameters.AddWithValue("@carMake", txtCarMake.Text.ToUpper());
                command.Parameters.AddWithValue("@carModel", txtCarModel.Text.ToUpper());
                command.Parameters.AddWithValue("@numberPlate", txtNumberPlate.Text.ToUpper());
                command.Parameters.AddWithValue("@roadTax", dateTimeRoadTax.Value.Date);
                command.Parameters.AddWithValue("@roadTaxDuration", cmbRTDuration.Text);
                command.Parameters.AddWithValue("@MOT", dateTimeMOT.Value.Date);
                command.Parameters.AddWithValue("@MOTDuration", cmbMOTDuration.Text);

                command.ExecuteNonQuery();

                MessageBox.Show("Car Added", "Car Addition", MessageBoxButtons.OK, MessageBoxIcon.None);
            }

            // Reminders Add

            if (cmbRTDuration.Text != "" || cmbMOTDuration.Text != "")
            {
                string queryReminder = "INSERT INTO Reminders (Id, Type, Car, Customer, Notes, DueOn) " +
                                       "VALUES (@id, @type, @car, @customer, @notes, @dueOn)";

                // Runs twice - First time is gets the road tax and second time it gets the MOT
                for (int i = 0; i < 2; i++)
                {
                    conn.Close();

                    GetReminderId();

                    conn.Open();

                    command = new SQLiteCommand(queryReminder, conn);

                    command.Parameters.AddWithValue("@id", _reminderId);
                    command.Parameters.AddWithValue("@type", i == 0 ? "Road Tax Due" : "MOT Due");
                    command.Parameters.AddWithValue("@car", txtCarMake.Text.ToUpper() + " " + txtCarModel.Text.ToUpper());
                    command.Parameters.AddWithValue("@customer", "N/A");
                    command.Parameters.AddWithValue("@notes", "N/A");
                    command.Parameters.AddWithValue("@dueOn", i == 0 ? GetRoadTaxDate(dateTimeRoadTax.Value).Date : GetMOTDate(dateTimeMOT.Value).Date);

                    command.ExecuteNonQuery();
                }
            }

            conn.Close();

            frmHome home = new frmHome();

            home.Show();
        }