Esempio n. 1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int theSelectedRow;
            int amountOfRows;

            if (e.RowIndex != -1)
            {
                theSelectedRow = e.RowIndex;
                amountOfRows   = dataGridView1.SelectedRows.Count;

                String[] dataString = new String[dataGridView1.Columns.Count];
                String[] header     = new String[dataGridView1.Columns.Count];
                foreach (DataGridViewRow theRow in dataGridView1.SelectedRows)
                {
                    for (int i = 0; i < dataString.Length; i++)
                    {
                        //MessageBox.Show(theRow.Cells[i].Value.ToString());
                        dataString[i] = theRow.Cells[i].Value.ToString();
                        header[i]     = dataGridView1.Columns[i].HeaderText;
                    }
                }
                string rowData = "";
                for (int i = 0; i < dataString.Length; i++)
                {
                    rowData += dataString[i];
                }
                DateTime selectedDate = Convert.ToDateTime(dataString[Array.IndexOf(header, "Start date")]);
                DateTime currentTime  = DateTime.Now;
                /*messagebox to ask if the customer is sure they wants to do that*/
                string            warningMessage = "Are you sure to delete this reservation?";
                string            titleMessage   = "Warning";
                MessageBoxButtons warningBox     = MessageBoxButtons.YesNo;
                DialogResult      answer         = MessageBox.Show(warningMessage, titleMessage, warningBox);
                if (answer == DialogResult.Yes)
                {
                    /*delete reservation base on whether the start date has passed the current day*/
                    if ((selectedDate - currentTime).TotalDays <= 0)
                    {
                        MessageBox.Show("You cannot remove this reservation");
                    }
                    else
                    {
                        data.myCommand.CommandText =
                            "DELETE FROM Reservation where Reservation.ReservationID = @res";
                        Guid reservedID = Guid.Parse(dataString[Array.IndexOf(header, "ReservationID")]);
                        data.myCommand.Parameters.AddWithValue("res", reservedID);
                        data.myCommand.ExecuteNonQuery();
                        data.myCommand.Parameters.Clear();
                        updateRevTable();
                        //this.reservationTableAdapter.Fill(this._291GroupProjectDataSet.Reservation);
                        reference.updateTable();
                    }
                }

                //for (int i = 0; i < dataString.Length; i++)
                //{
                //CarInfoBox.Text = CarInfoBox.Text + dataString[i] + "\n";
                //}
            }
        }
Esempio n. 2
0
        private void confirmB_Click_1(object sender, EventArgs e)
        {
            /*add the information to the row*/
            //data = new database();
            /*search for the userID*/

            //try
            //{
            Guid guidLocation;

            data.myCommand.CommandText = "SELECT BranchID from Branch where Branch.Location =@location";
            data.myCommand.Parameters.AddWithValue("location", locationB.SelectedItem);
            guidLocation = (Guid)data.myCommand.ExecuteScalar();
            data.myCommand.Parameters.Clear();
            //guidLocation = (Guid)data.myCommand.ExecuteScalar();
            //data.myCommand.Parameters.Clear();
            Decimal price = calPrice(CarID, startTimePicker, endTimePicker);    //calculate price
            /*insert the row*/
            Guid guidRev = Guid.NewGuid();

            data.myCommand.CommandText = "INSERT INTO [dbo].[Reservation] VALUES (@ReservationID, @startDate, @endDate, @price, @BranchID, @VehicleID, @UserID)";
            data.myCommand.Parameters.AddWithValue("ReservationID", guidRev);
            data.myCommand.Parameters.AddWithValue("startDate", startTimePicker.Value);
            data.myCommand.Parameters.AddWithValue("endDate", endTimePicker.Value);
            data.myCommand.Parameters.AddWithValue("price", price);
            data.myCommand.Parameters.AddWithValue("BranchID", guidLocation);
            data.myCommand.Parameters.AddWithValue("VehicleID", CarID);
            data.myCommand.Parameters.AddWithValue("UserID", customerID);
            data.myCommand.ExecuteNonQuery();
            data.myCommand.Parameters.Clear();

            /*increment the customer's total year rent by 1*/
            data.myCommand.CommandText =
                "UPDATE Users SET Users.[Total Year Rent] = Users.[Total Year Rent]+1" +
                "where Users.UserID =@user";
            data.myCommand.Parameters.AddWithValue("user", this.customerID);
            data.myCommand.ExecuteNonQuery();
            data.myCommand.Parameters.Clear();
            /*let the car becomes unavailable for other user*/
            data.myCommand.CommandText =
                "UPDATE Car SET Car.Status = 1 where Car.VehicleID =@Vehicle";
            data.myCommand.Parameters.AddWithValue("Vehicle", CarID);
            data.myCommand.ExecuteNonQuery();
            data.myCommand.Parameters.Clear();
            //}
            //catch
            //{
            // MessageBox.Show("Please choose a city");
            //}
            theOpenResForm.updateTable();
            this.Close();
        }