public Form2(DBConnector myConnector, UserDataStorage myDataStorage) { this.myConnector = myConnector; this.myDataStorage = myDataStorage; InitializeComponent(); }
public UserDataStorage LoadUserData(long PESEL) { UserDataStorage dataStorage = new UserDataStorage(); List <Object> tempReader; string query = "SELECT * FROM users WHERE pesel = \"" + PESEL; tempReader = sendCustomReaderQuery(query); dataStorage.PESEL = PESEL; dataStorage.login = (string)tempReader[1]; dataStorage.password = (string)tempReader[2]; dataStorage.name = (string)tempReader[3]; dataStorage.surName = (string)tempReader[4]; query = "SELECT BicycleID FROM RentsActive WHERE PESEL = \"" + PESEL + "\" ;"; tempReader = sendCustomReaderQuery(query); if (tempReader.Count > 0) { dataStorage.hasRentedBike = true; dataStorage.BicycleID = (int)tempReader[0]; } return(dataStorage); }
public UserDataStorage returnBicycleToStation(UserDataStorage dataStorage, string streetName, bool brokeReport) { List <Object> tempReader; UserDataStorage tempStorage = dataStorage; tempStorage.hasRentedBike = false; string query; string tempFirstDate, tempSecondDate; string [] dateFormat = new string[2]; long minutes; const double ratio = 0.3; double cost; tempFirstDate = "SELECT DateOfRent FROM rentsactive WHERE PESEL = \"" + tempStorage.PESEL + "\""; tempSecondDate = "SELECT NOW()"; query = "SELECT TIMESTAMPDIFF(MINUTE,(" + tempFirstDate + "),(" + tempSecondDate + ") );"; tempReader = sendCustomReaderQuery(query); minutes = (long)tempReader[0]; cost = (minutes - 15) * ratio; if (cost < 0) { cost = 0; } query = "SELECT DATE_FORMAT(DateOfRent, '%Y-%m-%d %T') FROM rentsactive WHERE PESEL = \"" + tempStorage.PESEL + "\";"; tempReader = sendCustomReaderQuery(query); query = "INSERT INTO rentsarchive VALUES (NULL, \"" + tempStorage.PESEL + "\", \"" + tempStorage.BicycleID + "\", (\'" + tempReader[0].ToString() + " \') , DEFAULT," + cost + " , " + brokeReport + " );"; sendCustomInsertOrUpdateQuery(query); query = "DELETE FROM rentsactive WHERE PESEL = \"" + tempStorage.PESEL + "\";"; sendCustomInsertOrUpdateQuery(query); query = "UPDATE Bicycles SET StationID = (SELECT StationID FROM Stations WHERE StreetName = \"" + streetName + "\"), IsReportedBroken = " + brokeReport + " WHERE BicycleID = \"" + tempStorage.BicycleID + "\";"; sendCustomInsertOrUpdateQuery(query); query = "UPDATE Stations SET BicycleCount = BicycleCount + 1 WHERE StreetName = \"" + streetName + "\" ;"; sendCustomInsertOrUpdateQuery(query); return(tempStorage); }
public UserDataStorage rentBike(UserDataStorage dataStorage, int bicycleID) { UserDataStorage tempStorage = dataStorage; tempStorage.hasRentedBike = true; tempStorage.BicycleID = bicycleID; string query; query = "UPDATE Stations SET BicycleCount = BicycleCount - 1 WHERE StationID = (SELECT StationID FROM Bicycles WHERE BicycleID = \"" + bicycleID + "\");"; sendCustomInsertOrUpdateQuery(query); query = "UPDATE Bicycles SET StationID = 0 WHERE BicycleID = \"" + bicycleID + "\" ;"; sendCustomInsertOrUpdateQuery(query); query = "INSERT INTO RentsActive VALUES (NULL, \"" + tempStorage.PESEL + "\", \"" + tempStorage.BicycleID + "\", DEFAULT );"; sendCustomInsertOrUpdateQuery(query); return(tempStorage); }
private void logInButton_Click(object sender, EventArgs e) { if (!legal(loginTextBox.Text) || !legal(passwordTextBox.Text)) { incorrectLoginDataLabel.Text = "Podany login i/lub haslo naruszaja zasady dot. wprowadzania danych"; } else if (!myConnector.checkIfLoginAndPasswordAreCorrect(loginTextBox.Text, passwordTextBox.Text)) { incorrectLoginDataLabel.Text = "Podany login i/lub hasło są nieprawidłowe"; } else { myDataStorage = myConnector.LoadUserData(loginTextBox.Text); Form3 f = new Form3(myConnector, myDataStorage); f.Show(); this.Hide(); } }
private void rentButton_Click(object sender, EventArgs e) { if (!legal(streetNameTextBox.Text)) { infoLabel.Text = "Nieprawidłowe Dane"; infoLabel.Update(); } else { int bicycleID = myConnector.checkIfBicycleIsAvailable(streetNameTextBox.Text); if (bicycleID > 0) { myDataStorage = myConnector.rentBike(myDataStorage, bicycleID); rentButton.Enabled = false; returnButton.Enabled = true; } else { infoLabel.Text = "Nie mamy roweru na tej ulicy"; infoLabel.Update(); } } }
public void AddNewUser(UserDataStorage dataStorage) { string query = "INSERT INTO Users VALUES (\"" + dataStorage.PESEL + "\",\"" + dataStorage.name + "\", \"" + dataStorage.surName + "\", \"" + dataStorage.login + "\", \"" + dataStorage.password + "\", \"" + 0 + "\") ;"; sendCustomInsertOrUpdateQuery(query); }