Exemple #1
0
        private void ReservationCustomer_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the '_291GroupProjectDataSet.Reservation' table. You can move, or remove it, as needed.
            //_291GroupProjectDataSet.Reservation.UserIDColumn.ColumnName
            /*get the useID*/

            data.myCommand.CommandText = "SELECT UserID from Users where Users.username = @uname";
            data.myCommand.Parameters.AddWithValue("uname", data.usr);
            Guid userID = Guid.Parse(data.myCommand.ExecuteScalar().ToString());

            //String userID = data.myCommand.ExecuteScalar().ToString();
            data.myCommand.Parameters.Clear();

            data.myCommand.CommandText = "SELECT * FROM Reservation where Reservation.UserID =@user";
            data.myCommand.Parameters.AddWithValue("user", userID);
            data.query(data.myCommand.CommandText);
            dataGridView1.DataSource = null;

            while (data.myReader.Read())
            {
                dataGridView1.Rows.Add(data.myReader["ReservationID"].ToString(),
                                       data.myReader["Start date"].ToString(),
                                       data.myReader["End date"].ToString(),
                                       data.myReader["Total Price"].ToString(),
                                       data.myReader["BranchID"].ToString(),
                                       data.myReader["VehicleID"].ToString(),
                                       data.myReader["UserID"].ToString());
            }

            data.myCommand.Parameters.Clear();
            data.myReader.Close();
        }
Exemple #2
0
        private void RemoveRowCustomer_Load(object sender, EventArgs e)
        {
            data.myCommand.CommandText = "SELECT UserID from Users where Users.username = @uname";
            data.myCommand.Parameters.AddWithValue("uname", reference.data.usr);
            Guid userID = (Guid)data.myCommand.ExecuteScalar();

            data.myCommand.Parameters.Clear();

            data.myCommand.CommandText = "SELECT * FROM Reservation where Reservation.UserID =@user";
            data.myCommand.Parameters.AddWithValue("user", userID);
            data.query(data.myCommand.CommandText);
            dataGridView1.DataSource = null;

            while (data.myReader.Read())
            {
                dataGridView1.Rows.Add(data.myReader["ReservationID"].ToString(),
                                       data.myReader["Start date"].ToString(),
                                       data.myReader["End date"].ToString(),
                                       data.myReader["Total Price"].ToString(),
                                       data.myReader["BranchID"].ToString(),
                                       data.myReader["VehicleID"].ToString(),
                                       data.myReader["UserID"].ToString());
            }

            data.myCommand.Parameters.Clear();
            data.myReader.Close();
        }
Exemple #3
0
        private void filterButton_Click(object sender, EventArgs e)
        {
            //cmd = "Select * from Car where Car.Color = @color and Car.Model = @model and Car.Make = @make and Car.[Type of Vehicle] = @type";
            cmd = "Select * from Car where ";

            // if the the boxes are filled go through them and add all parameters.
            if (parameters.Count > 0)
            {
                foreach (KeyValuePair <string, string> param in parameters)
                {
                    cmd = cmd + param.Key + " = " + param.Value + " and ";
                    switch (param.Value)
                    {
                    case ("@color"):
                        datab.myCommand.Parameters.AddWithValue("color", color);
                        break;

                    case ("@model"):
                        datab.myCommand.Parameters.AddWithValue("model", model);
                        break;

                    case ("@make"):
                        datab.myCommand.Parameters.AddWithValue("make", make);
                        break;

                    case ("@type"):
                        datab.myCommand.Parameters.AddWithValue("type", type);
                        break;

                    case ("@carID"):
                        datab.myCommand.Parameters.AddWithValue("carID", carID);
                        break;

                    case ("@status"):
                        datab.myCommand.Parameters.AddWithValue("status", availableCarsOnly);
                        break;
                    }
                }

                //MessageBox.Show("cmd = " + cmd);                    // Debug purposes

                int lastAnd = cmd.LastIndexOf(" and ");       // get last index of the and

                cmd = cmd.Remove(lastAnd);                    // remove last and
            }
            else
            {
                // This will be used if no text box was filled.
                int where = cmd.LastIndexOf(" where ");
                cmd       = cmd.Remove(where);
            }

            // run query
            //dataCommand.CommandText = cmd;
            try
            {
                datab.query(cmd);
                //dataRead = dataCommand.ExecuteReader();
                CarData.DataSource = null;
                CarData.Rows.Clear();
                while (datab.myReader.Read())
                {
                    CarData.Rows.Add(datab.myReader["VehicleID"].ToString(), datab.myReader["Color"].ToString(), datab.myReader["Model"].ToString(),
                                     datab.myReader["Make"].ToString(),
                                     datab.myReader["Status"].ToString(),
                                     datab.myReader["Type of Vehicle"].ToString(),
                                     datab.myReader["UserID"].ToString());
                }

                datab.myReader.Close();
                //dataCommand.Parameters.Clear();
                datab.clearParameters();
            }
            catch (Exception e3)
            {
                MessageBox.Show(e3.ToString(), "Error");
                //dataRead.Close();
                // Close();
            }
        }