--- DatabaseLayer.cpp 2006/09/01 02:23:19 19 +++ DatabaseLayer.cpp 2006/09/03 09:14:24 27 @@ -6,7 +6,7 @@ DatabaseLayer::DatabaseLayer(void) { - db.OpenEx("ODBC; Description=; DRIVER=SQL Server; SERVER=TK-Teacher; UID=GroupTwo; PWD=toog30"); + db.OpenEx("ODBC; Description=; DRIVER=SQL Server; SERVER=TK-Teacher; UID=GroupTwo; PWD=toog30", CDatabase::noOdbcDialog); db.ExecuteSQL("USE GroupTwo"); } @@ -106,6 +106,8 @@ SQL.Format("UPDATE Udlån SET Afleveringsdato = Getdate() WHERE Stregkode= '%s' AND Afleveringsdato IS NULL ", barcode); db.ExecuteSQL(SQL); + + checkReservations(barcode); return true; } @@ -119,13 +121,12 @@ return true; } -bool DatabaseLayer::EquipmentReservation(Person CheckPersID, Equipment CheckEquip, int Numdays) +bool DatabaseLayer::EquipmentReservation(CString barcode, Person CheckPerson) { CString SQL; - SQL.Format("UPDATE Udstyr SET Status = '2' WHERE Stregkode = '%s' ", CheckEquip.barcode); - db.ExecuteSQL(SQL); - SQL.Format("INSERT INTO Resevation (PersonID, Stregkode, Startdato, Antaldage) VALUES( '%s','%s', GetDate(),'%d')", CheckPersID.id, CheckEquip.barcode, Numdays); + SQL.Format("INSERT INTO Resevation (PersonID, Stregkode, Startdato) VALUES( '%s','%s', GetDate())", CheckPerson.id, barcode); db.ExecuteSQL(SQL); + checkReservations(barcode); return true; } @@ -218,6 +219,8 @@ { vector buffer; + //here are the wanted equipments found through 3 seperate queries - I could also + //find them all in one query where I joined the 3 selects via a UNION CString SQL; if (available == true) { SQL = "SELECT DISTINCT Udstyr.stregkode,Udstyr.Navn,Udstyr.Beskrivelse,Udstyr.Placering,Status.Beskrivelse \ @@ -240,13 +243,13 @@ INNER JOIN Status ON Udstyr.status = Status.StatusID \r\n\ INNER JOIN Resevation ON Udstyr.Stregkode = Resevation.stregkode \r\n\ INNER JOIN Person ON Resevation.PersonID = Person.PersonID\r\n\ - WHERE Udstyr.Status = 2 "; + WHERE ( Udstyr.Status = 2 OR Person.Initialer = '" + inits + "') "; if (barcode != "") SQL += " AND Udstyr.stregkode = '" + barcode + "' "; if (name != "") SQL += " AND Udstyr.Navn LIKE '%" + name + "%' "; - if (inits != "") - SQL += " AND Person.Initialer = '" + inits + "' "; + //if (inits != "") + // SQL += " AND Person.Initialer = '" + inits + "' "; CRecordset rs(&db); rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); @@ -276,6 +279,9 @@ rs.Close(); } + // now I have the equipment rows the user asked for, now I need some more checkout and + // reservation data for each piece of equipment + for (int i=0; i0) { + rs.MoveFirst(); + rs.GetFieldValue((short)0,status); + } + rs.Close(); + + + if (reservationCount > 0 && status == 3) {//equipment is available and has at lease one reservation + SQL = "UPDATE Udstyr SET Status = 2 WHERE Stregkode = '" + barcode + "'"; + db.ExecuteSQL(SQL); + } +} + +bool DatabaseLayer::DeleteReservation(CString barcode, CString resid) +{ + CString SQL = "DELETE FROM Resevation WHERE resevationid = " + resid; + db.ExecuteSQL(SQL); + checkReservations(barcode); + return true; +} +