/// <summary> /// Completing the reservation /// </summary> private void CompleteReservation() { DialogResult dialogResult = MessageBox.Show("Weet je zeker dat alle gegevens kloppen?", "Reservering afronden", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { int reservationId; int mainUserId; int bookerId; int mainBookerId; userName = mainBooker.FirstName + mainBooker.LastName; bool userNameNotCorrect = true; Database db = new Database(); db.OpenConnection(); db.CreateCommand("INSERT INTO RESERVATIONS (MAINBOOKER_ID, TOTALCOSTS, TOTALPAYED, CREATED) VALUES (0, :totalcosts, :totalpayed, :created) RETURNING id INTO :LASTID"); db.AddParameter("totalcosts", numPayCosts.Value); db.AddParameter("totalpayed", 0); db.AddParameter("created", DateTime.Now); db.GetParameter(":LASTID"); db.ExecuteCommand(); OracleParameter lastId = db.lastId; //MessageBox.Show(lastId.Value.ToString()); reservationId = Convert.ToInt32(lastId.Value.ToString()); while (userNameNotCorrect) { db.CreateCommand("SELECT USERNAME FROM USERS WHERE USERNAME = :username"); db.AddParameter(":username", userName); db.OpenConnection(); db.ExecuteCommand(); OracleDataReader dr = db.DataReader; if (dr.HasRows) userName += 1.ToString(); else userNameNotCorrect = false; } userNames.Add(userName); db.CreateCommand("INSERT INTO USERS (USERNAME, PASSWORD, UPLOADLIMIT, ISEMPLOYEE) VALUES (:username, :password, :uploadlimit, 0) RETURNING id INTO :LASTID"); db.AddParameter("username", userName); passWords.Add(GeneratePassword(8)); db.AddParameter("password", passWords[0]); db.AddParameter("uploadlimit", 5000000); db.GetParameter(":LASTID"); db.ExecuteCommand(); lastId = db.lastId; //MessageBox.Show(lastId.Value.ToString()); mainUserId = Convert.ToInt32(lastId.Value.ToString()); db.CreateCommand("SELECT * FROM ( SELECT ID,CARDVALUE FROM CARDVALUES WHERE AVAILABLE = 1 ) WHERE ROWNUM = 1"); db.ExecuteCommand(); OracleDataReader odr = db.DataReader; string cardValue; cardValue = GeneratePassword(10); while (odr.Read()) { cardValue = odr.GetString(1); db.CreateCommand("UPDATE CARDVALUES SET AVAILABLE = 0 WHERE id = :id"); db.AddParameter("id", odr.GetInt16(0)); db.ExecuteCommand(); } db.CreateCommand("INSERT INTO BOOKERS (RESERVATIONS_ID, USERS_ID, LOCATIONS_ID, FIRSTNAME, PHONE, CARDVALUE) VALUES (:reservation_id, :user_id, :location_id, :firstname, :phone, :cardvalue) RETURNING id INTO :LASTID"); db.AddParameter("reservation_id", reservationId); db.AddParameter("user_id", mainUserId); db.AddParameter("location_id", Convert.ToInt16(lbCampPlace.Text)); db.AddParameter("firstname", mainBooker.FirstName); db.AddParameter("phone", mainBooker.Phone); db.AddParameter("cardvalue", cardValue); db.GetParameter(":LASTID"); db.ExecuteCommand(); lastId = db.lastId; // MessageBox.Show(lastId.Value.ToString()); bookerId = Convert.ToInt32(lastId.Value.ToString()); db.CreateCommand("INSERT INTO MAINBOOKERS (BOOKERS_ID, LASTNAME, ADDRESS, POSTALCODE, PLACE, LAND) VALUES (:booker_id, :lastname, :address, :postalcode, :place, :land) RETURNING id INTO :LASTID"); db.AddParameter("booker_id", bookerId); db.AddParameter("lastname", mainBooker.LastName); db.AddParameter("address", mainBooker.Address); db.AddParameter("postalcode", mainBooker.PostalCode); db.AddParameter("place", mainBooker.Place); db.AddParameter("land", mainBooker.Land); db.GetParameter(":LASTID"); db.ExecuteCommand(); lastId = db.lastId; // MessageBox.Show(lastId.Value.ToString()); mainBookerId = Convert.ToInt32(lastId.Value.ToString()); db.CreateCommand("UPDATE RESERVATIONS SET MAINBOOKER_ID = :mainbooker_id WHERE id = :reservation_id"); db.AddParameter("mainbooker_id", mainBookerId); db.AddParameter("reservation_id", reservationId); db.ExecuteCommand(); for (int i = 0; i < medeboekers.Count; i++) { userName = medeboekers[i].Name; userNameNotCorrect = true; while (userNameNotCorrect) { db.CreateCommand("SELECT USERNAME FROM USERS WHERE USERNAME = :username"); db.AddParameter(":username", userName); db.OpenConnection(); db.ExecuteCommand(); OracleDataReader dr = db.DataReader; if (dr.HasRows) userName += 1.ToString(); else userNameNotCorrect = false; } userNames.Add(userName); db.CreateCommand("INSERT INTO USERS (USERNAME, PASSWORD, UPLOADLIMIT, ISEMPLOYEE) VALUES (:username, :password, :uploadlimit, 0) RETURNING id INTO :LASTID"); db.AddParameter("username", userName); passWords.Add(GeneratePassword(8)); db.AddParameter("password", passWords[i + 1]); db.AddParameter("uploadlimit", 5000000); db.GetParameter(":LASTID"); db.ExecuteCommand(); lastId = db.lastId; //MessageBox.Show(lastId.Value.ToString()); int userId = Convert.ToInt32(lastId.Value.ToString()); db.CreateCommand("SELECT * FROM ( SELECT ID,CARDVALUE FROM CARDVALUES WHERE AVAILABLE = 1 ) WHERE ROWNUM = 1"); db.ExecuteCommand(); OracleDataReader dar = db.DataReader; cardValue = GeneratePassword(10); while (odr.Read()) { cardValue = dar.GetString(1); db.CreateCommand("UPDATE CARDVALUES SET AVAILABLE = 0 WHERE id = :id"); db.AddParameter("id", dar.GetInt16(0)); db.ExecuteCommand(); } db.CreateCommand("INSERT INTO BOOKERS (RESERVATIONS_ID, USERS_ID, LOCATIONS_ID, FIRSTNAME, PHONE, CARDVALUE) VALUES (:reservation_id, :user_id, :location_id, :firstname, :phone, :cardvalue)"); db.AddParameter("reservation_id", reservationId); db.AddParameter("user_id", userId); db.AddParameter("location_id", Convert.ToInt16(lbCampPlace.Text)); db.AddParameter("firstname", medeboekers[i].Name); db.AddParameter("phone", medeboekers[i].PhoneNumber); db.AddParameter("cardvalue", cardValue); db.ExecuteCommand(); } db.CloseConnection(); CreateEndTextFile(); //EMPTY FORMS //STEP 1 numNumPers.Value = 0; tbFirstName.Text = ""; tbLastName.Text = ""; tbPhone.Text = ""; tbAddress.Text = ""; tbPostalCode.Text = ""; tbLivePlace.Text = ""; tbLand.Text = ""; //STEP 3 cbPayMethod.SelectedIndex = -1; tbPayName.Text = ""; tbPayIBAN.Text = ""; cbPayLater.Checked = false; //STEP 4 lbCampPlace.Text = ""; //STEP 5 uitleenbareItems.Clear(); geleendeItems.Clear(); cbNoItemReservation.Checked = false; MessageBox.Show("De reservering is succesvol in de database geplaatst", "Succes!"); Reserveren.SelectedIndex = 0; } }