using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Dapper; using System.Data; using System.Windows.Forms; using System.Data.SqlClient; namespace db_AI_4 { public class DataAccess { public SqlConnection connection { get; private set; } //Read locations from the Database function start public List GetLocations(string LocationName) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb"))) { var output = connection.Query($"SELECT * FROM locations WHERE location_name like '%{ LocationName }%'").ToList(); return output; } } // im moment nicht benötigt (sollte die id des momentanen members herauslesen) public List DisplayUser(string Email_address) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb"))) { var outputUser = connection.Query($"SELECT member_id FROM dbo.members WHERE email_address = '{Email_address}'").ToList(); return outputUser; } } //Read locations from the Database function end // Insert Locations into Database start public void InsertLocations(string StreetName, int LocationCapacity, string LocationName) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb"))) { List locations = new List(); locations.Add(new GetLocations { streetname = StreetName, location_capacity = LocationCapacity, location_name = LocationName }); connection.Execute("INSERT INTO dbo.locations (streetname, location_capacity, location_name)" + " VALUES (@streetName, @location_capacity, @location_name)", locations); } } // Insert Locations into Database end // Insert Rents into Database start public void InsertRent(string RentDate, int MemberID, int RentPriceID ) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb"))) { List rents = new List(); rents.Add(new GetRents { rent_date = RentDate, member_id = 1, rent_price_id = RentPriceID, location_id = 1}); connection.Execute("INSERT INTO dbo.rents (rent_date, member_id, rent_price_id, location_id)" + " VALUES (@rent_date, @member_id, @rent_price_id, @location_id )", rents); } } // Insert Rents into Database end //Registration function start public void InsertMember(string Email_address, string Password) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb"))) { List members = new List(); members.Add(new GetMembers { email_address = Email_address, password = Password }); connection.Execute("INSERT INTO dbo.members ( email_address, password)" + " VALUES (@Email_address, @Password) ", members); } } //Registration function end //Read Rented locations start internal List GetRentedLocations(string LocationName) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb"))) { var rentoutput = connection.Query( $"SELECT * FROM [RentedLocations] WHERE location_name like '%{ LocationName }%' ORDER BY rent_date ASC ").ToList(); return rentoutput; } } //Read Rented locations end //CheckLogin function start public void CheckLogin(string Email_address, string Password) { SqlConnection con = new SqlConnection(Helper.CnnVal("marketdb")); con.Open(); SqlCommand cmd = new SqlCommand($"SELECT * FROM dbo.members WHERE email_address = '{Email_address}' and password = '{Password}'",con); SqlDataReader reader; reader = cmd.ExecuteReader(); int count = 0; while (reader.Read()) { count += 1; } if (count == 1) { MessageBox.Show("It Worked"); Dashboard dashboard = new Dashboard(); dashboard.Show(); } else if (count > 0) { MessageBox.Show("Already existing"); } else { MessageBox.Show("Username or Password not correct"); } //CheckLogin function end } } }