From eb17e67e19966a7d73608d03fc929ba194ff28f1 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Wed, 30 Aug 2017 15:23:13 +0200 Subject: [PATCH] change the GetMembers class to a static class --- .../db_AI-4_V3/db_AI-4/Dashboard.cs | 7 ++--- .../db_AI-4_V3/db_AI-4/DataAccess.cs | 29 ++++++++----------- .../db_AI-4_V3/db_AI-4/GetMembers.cs | 16 +++++----- .../db_AI-4_V3/db_AI-4/LoginForm.cs | 13 +++++---- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/Dashboard.cs b/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/Dashboard.cs index f10d4ca..846c924 100644 --- a/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/Dashboard.cs +++ b/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/Dashboard.cs @@ -100,11 +100,10 @@ namespace db_AI_4 int RentPriceID; RentPriceID = 1; - int MemberID; - MemberID = 1; + //int MemberID; + //MemberID = 1; - - db.InsertRent(RentDateTimePicker.Value.Date.ToString("yyyyMMdd"), RentPriceID, MemberID); + db.InsertRent(RentDateTimePicker.Value.Date.ToString("yyyyMMdd"), GetMembers.member_id, RentPriceID); RentDateTimePicker.Text = ""; diff --git a/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/DataAccess.cs b/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/DataAccess.cs index 359c93e..588ac56 100644 --- a/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/DataAccess.cs +++ b/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/DataAccess.cs @@ -25,17 +25,17 @@ namespace db_AI_4 } } - // im moment nicht benötigt (sollte die id des momentanen members herauslesen) - public List DisplayUser(string Email_address) + + public void CurrentUser(string input_mail) { + List QueryResult = new List(); 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; + { + var command = "SELECT member_id FROM dbo.members WHERE members.email_address = @Email_Adress"; + QueryResult = connection.Query(command, new { Email_Adress = input_mail }).ToList(); + GetMembers.member_id = Convert.ToInt32(QueryResult[0]); } } - //Read locations from the Database function end - // Insert Locations into Database start @@ -62,7 +62,7 @@ namespace db_AI_4 { List rents = new List(); - rents.Add(new GetRents { rent_date = RentDate, member_id = 1, rent_price_id = RentPriceID, location_id = 1}); + rents.Add(new GetRents { rent_date = RentDate, member_id = GetMembers.member_id, 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); @@ -73,17 +73,12 @@ namespace db_AI_4 //Registration function start - public void InsertMember(string Email_address, string Password) + public void InsertMember(string input_mail, string input_pw) { 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); + var command = "INSERT INTO dbo.members (email_address, password) VALUES ( @Email_address, @Password)"; + connection.Execute(command, new { Email_address = input_mail, Password = input_pw }); } } @@ -123,7 +118,7 @@ namespace db_AI_4 if (count == 1) { - MessageBox.Show("It Worked"); + CurrentUser(GetMembers.email_address); Dashboard dashboard = new Dashboard(); dashboard.Show(); } diff --git a/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/GetMembers.cs b/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/GetMembers.cs index f10e6e7..03c8be3 100644 --- a/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/GetMembers.cs +++ b/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/GetMembers.cs @@ -6,17 +6,15 @@ using System.Threading.Tasks; namespace db_AI_4 { - public class GetMembers + public static class GetMembers { - public int member_id { get; set; } - public string email_address { get; set; } - public string password { get; set; } - public int member_status_id { get; set; } + public static int member_id { get; set; } + public static string email_address { get; set; } + public static string password { get; set; } + public static int member_status_id { get; set; } - - - public string MemberInfo + public static string MemberInfo { get { @@ -25,7 +23,7 @@ namespace db_AI_4 } - public string MemberID + public static string MemberID { get { diff --git a/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/LoginForm.cs b/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/LoginForm.cs index 40991ee..51b6bae 100644 --- a/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/LoginForm.cs +++ b/csharp/marketconnectionNET2.0/db_AI-4_V3/db_AI-4/LoginForm.cs @@ -22,18 +22,19 @@ namespace db_AI_4 private void RegistrationButton_Click(object sender, EventArgs e) { DataAccess db = new DataAccess(); - - db.InsertMember(EmailLoginBox.Text, PasswordLoginBox.Text); - - EmailLoginBox.Text = ""; - PasswordLoginBox.Text = ""; + GetMembers.email_address = EmailLoginBox.Text; + GetMembers.password = PasswordLoginBox.Text; + db.InsertMember(GetMembers.email_address, GetMembers.password); + MessageBox.Show("Member Registered."); } private void LoginButton_Click(object sender, EventArgs e) { DataAccess db = new DataAccess(); - db.CheckLogin(EmailLoginBox.Text, PasswordLoginBox.Text); + GetMembers.email_address = EmailLoginBox.Text; + GetMembers.password = PasswordLoginBox.Text; + db.CheckLogin(GetMembers.email_address, GetMembers.password); }