Exemple #1
0
        private void BackToMenuBtn_Click(object sender, EventArgs e)
        {
            MenuScreenForm form = new MenuScreenForm();

            form.Show();

            Close();
        }
Exemple #2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                MenuScreenForm form = new MenuScreenForm();
                form.Show();

                Visible = false;
            }
            else if (e.KeyCode == Keys.Escape)
            {
                Dispose();
            }
        }
Exemple #3
0
        private void InsertCarBtn_MouseClick(object sender, MouseEventArgs e)
        {
            Regex    regex    = new Regex(@"(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$");
            bool     isValid  = regex.IsMatch(startDateTextBox.Text.Trim());
            bool     isValid2 = regex.IsMatch(startDateTextBox.Text.Trim());
            DateTime dt;

            isValid  = DateTime.TryParseExact(startDateTextBox.Text, "dd/MM/yyyy", new CultureInfo("en-GB"), System.Globalization.DateTimeStyles.None, out dt);
            isValid2 = DateTime.TryParseExact(endDateTextBox.Text, "dd/MM/yyyy", new CultureInfo("en-GB"), System.Globalization.DateTimeStyles.None, out dt);

            DateTime startData = DateTime.Parse(startDateTextBox.Text);
            DateTime endData   = DateTime.Parse(endDateTextBox.Text);

            con.Open();

            if (!isValid || startDateTextBox.Text == "" || !isValid2 || endDateTextBox.Text == "")
            {
                MessageBox.Show("Invalid date.");
            }

            else if (cityTextBox.Text == "")
            {
                MessageBox.Show("Introduce a city.");
            }
            else if (startData > endData)
            {
                MessageBox.Show("The start data cannot be bigger or equal than the end data.");
            }

            else
            {
                //if the model of the car does not exist in the Cars table it will give an error.
                SqlCommand command = con.CreateCommand();
                command.CommandText = "Select * from Cars where Model = '" + carModelTextBox.Text + "'";
                command.Parameters.AddWithValue("@CarModel", carModelTextBox.Text);
                SqlDataAdapter sda       = new SqlDataAdapter(command);
                DataTable      dataTable = new DataTable();
                sda.Fill(dataTable);

                //if the  client ID does not exist in the Customer table it will give an error.
                SqlCommand command2 = con.CreateCommand();
                command2.CommandText = "Select * from Customers where CostumerID = '" + clientIDTextBox.Text + "'";
                command2.Parameters.AddWithValue("@CostumerID", clientIDTextBox.Text);
                SqlDataAdapter sda2       = new SqlDataAdapter(command2);
                DataTable      dataTable2 = new DataTable();
                sda2.Fill(dataTable2);

                //if the  location does not exist in the Customer table it will give an error.
                SqlCommand command3 = con.CreateCommand();
                command3.CommandText = "Select * from Customers where Location = '" + cityTextBox.Text + "'";
                command3.Parameters.AddWithValue("@CostumerID", clientIDTextBox.Text);
                SqlDataAdapter sda3       = new SqlDataAdapter(command3);
                DataTable      dataTable3 = new DataTable();
                sda3.Fill(dataTable3);


                if (dataTable.Rows.Count > 0 && dataTable2.Rows.Count > 0 & dataTable3.Rows.Count > 0)
                {
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "insert into CarRent values('" + clientIDTextBox.Text + "' , '" +
                                      carModelTextBox.Text + "' , '" + startDateTextBox.Text + "' , '" + endDateTextBox.Text + "', '" + cityTextBox.Text + "')";

                    cmd.ExecuteNonQuery();

                    Close();


                    MenuScreenForm form = new MenuScreenForm();
                    form.Show();
                }

                else
                {
                    MessageBox.Show("The model of the car or the client ID or the location it does not exists in our database.Please check again.");
                }

                con.Close();
            }
        }
        private void UpdateCustomerBtn_MouseClick(object sender, MouseEventArgs e)
        {
            Regex    regex   = new Regex(@"(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$");
            bool     isValid = regex.IsMatch(birthDateTextBox.Text.Trim());
            DateTime dt;

            isValid = DateTime.TryParseExact(birthDateTextBox.Text, "dd/MM/yyyy", new CultureInfo("en-GB"), System.Globalization.DateTimeStyles.None, out dt);

            con.Open();

            if (!isValid || birthDateTextBox.Text == "")
            {
                MessageBox.Show("Invalid birth date.");
            }

            else if (clientNameTextBox.Text == "")
            {
                MessageBox.Show("Introduce a client name.");
            }

            else if (locationTextBox.Text == "")
            {
                MessageBox.Show("Introduce a location.");
            }

            else if (ZIPCodeTextBox.Text.Length < 6)
            {
                MessageBox.Show("The ZIP Code cannot be lower than 6 characters.");
            }

            else if (clientIDTextBox.Text == "")
            {
                MessageBox.Show("Introduce an ID to know what customer you want to update.");
            }


            else
            {
                SqlCommand cmd2;
                cmd2 = new SqlCommand("Select * FROM Customers WHERE CostumerID = '" + clientIDTextBox.Text + "'", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd2);
                da.Fill(ds);
                int i = ds.Tables[0].Rows.Count;

                if (i > 0)
                {
                    SqlCommand cmd = con.CreateCommand();

                    cmd.CommandType = CommandType.Text;

                    cmd.CommandText = " UPDATE Customers SET Name = '" + clientNameTextBox.Text + "' , BirthDate = '" + birthDateTextBox.Text + "' , Location = '" + locationTextBox.Text + "' Where CostumerID = '" + clientIDTextBox.Text + "'";

                    cmd.ExecuteNonQuery();

                    Close();

                    MenuScreenForm form = new MenuScreenForm();
                    form.Show();
                }

                //if the the customer ID introduced does not exists to update,there will be an error message.

                else
                {
                    MessageBox.Show("The customer inserted with this ID " + clientIDTextBox.Text + " does not exists.");
                    ds.Clear();
                }
            }
            con.Close();
        }
Exemple #5
0
        private void RegisterCustomerBtn_Click(object sender, EventArgs e)
        {
            Regex    regex   = new Regex(@"(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$");
            bool     isValid = regex.IsMatch(birthDateTextBox.Text.Trim());
            DateTime dt;

            isValid = DateTime.TryParseExact(birthDateTextBox.Text, "dd/MM/yyyy", new CultureInfo("en-GB"), System.Globalization.DateTimeStyles.None, out dt);

            con.Open();

            if (!isValid || birthDateTextBox.Text == "")
            {
                MessageBox.Show("Invalid birth date.");
            }

            else if (clientNameTextBox.Text == "")
            {
                MessageBox.Show("Introduce a client name.");
            }

            else if (locationTextBox.Text == "")
            {
                MessageBox.Show("Introduce a location.");
            }

            else if (ZIPCodeTextBox.Text.Length < 6)
            {
                MessageBox.Show("The ZIP Code cannot be lower than 6 characters.");
            }


            /* All the way up I have validated the fields.
             * I cannot validate the Customer ID because it is a primary key on the field and  also
             * it has auto increment.
             */

            else
            {
                SqlCommand cmd2;
                cmd2 = new SqlCommand("Select * FROM Customers WHERE Name = '" + clientNameTextBox.Text + "'", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd2);
                da.Fill(ds);
                int i = ds.Tables[0].Rows.Count;

                //if the the customer introduced already exists,there will be an error message.

                if (i > 0)
                {
                    MessageBox.Show("The customer inserted with this name " + clientNameTextBox.Text + " already exists.");
                    ds.Clear();
                }
                else
                {
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "insert into Customers values('" + clientNameTextBox.Text + "' , '" +
                                      birthDateTextBox.Text + "' , '" + locationTextBox.Text + "')";

                    cmd.ExecuteNonQuery();

                    Close();

                    MenuScreenForm form = new MenuScreenForm();
                    form.Show();
                }
            }

            con.Close();
        }