/// <summary> /// Converts a string from the database to a jagged array /// </summary> /// <param name="schID">The scheduler ID of the seats you want to convert</param> /// <returns>Returns the jagged array</returns> public int[][] ConvertStringToArray(int schID) { DBSeat dbSeat = new DBSeat(); var seatListoperator = dbSeat.GetSeats(schID); int count = seatListoperator.Count(); int[][] jagged = new int[count][]; for (int row = 0; row < count; row++) { Seat s = seatListoperator.ElementAt(row); int i = 0; int lengthChar = (1 + s.ColumnArray.Count()) / 2; jagged[row] = new int[lengthChar]; foreach (char c in s.ColumnArray) { if (!c.Equals(',')) { jagged[row][i] = (int)Char.GetNumericValue(c); i++; } } } return(jagged); }
//This needs to have both schedulerID customerId and row and seat. //e.g. row = "1,1,1" seat = "2,3,4" /// <summary> /// Creats a reservation, updating the database /// </summary> /// <param name="row">The rows of the seats in format "1,2,1,1"</param> /// <param name="seatArray">The indexes of the seats in format "1,1,2,3". It is possible to reserve 1 twice, if the rows are different</param> /// <param name="schedulerID">The scheduler ID where you want to make a reservation</param> /// <param name="customerID">The customer ID of the customer that wants to make a reservation</param> /// <returns>Returns a boolean that is true or false, depending on success</returns> public bool MakeReservation(string row, string seatArray, int schedulerID, int customerID) { bool isAvailable = true; //find seat by schedulerID and use row and seat to see if they are available. //lock here. After you have writtin to the database release the lock. DBSeat seatTable = new DBSeat(); string[] rowArray = row.Split(','); //check if the row exist in database. for (int i = 0; i < rowArray.Length - 1; i++) { int rowIndex; Int32.TryParse(rowArray[i], out rowIndex); List <Seat> eachRowList = seatTable.GetSeatsBySchIDAndRow(schedulerID, rowIndex); foreach (Seat eachRow in eachRowList) { //check if the seat is available by using the seatArray (which is the index in the seatlist) string[] checkSeat = seatArray.Split(','); string[] seatList = eachRow.ColumnArray.Split(','); //check the index from checkSeat and see if that index in seatList is available foreach (string check in checkSeat) { int index = 0; Int32.TryParse(check, out index); int seatPoint; Int32.TryParse(seatList[index], out seatPoint); if (seatPoint <= 0) { //The seat is not available, therefore you should not reserve it. isAvailable = false; return(isAvailable); } index++; } } } //Remember to update seat in the seat table also. Or else it will only be updated in the reserve table. //so call to the dbSeat and make an update there also. Reservation reservation = new Reservation(); reservation.Seat = seatArray; reservation.Row = row; reservation.CustomerID = customerID; reservation.SchedulerID = schedulerID; int charArrayIndex = 0; string[] splitSeatArray = seatArray.Split(','); char[] charArray = new char[splitSeatArray.Length]; while (charArrayIndex < charArray.Length) { charArray[charArrayIndex] = '0'; charArrayIndex++; } string updateInfo = new string(charArray); seatTable.UpdateSeat(row, seatArray, updateInfo, schedulerID); //Husk at den returner en controlInt for at se om programmet failet i at indsætte i databasen. dbRes.insertReservation(reservation); return(isAvailable); }
/// <summary> /// Gets all seats by a scheduler ID /// </summary> /// <param name="schedulerID">The ID of the scheduler</param> /// <returns>Returns a list of seats</returns> public List <Seat> GetAllSeatsBySchedulerID(int schedulerID) { DBSeat dbSeat = new DBSeat(); return(dbSeat.GetSeats(schedulerID)); }