change the GetMembers class to a static class

This commit is contained in:
Andreas Zweili 2017-08-30 15:23:13 +02:00
parent 918aca0b0e
commit eb17e67e19
4 changed files with 29 additions and 36 deletions

View File

@ -100,11 +100,10 @@ namespace db_AI_4
int RentPriceID; int RentPriceID;
RentPriceID = 1; RentPriceID = 1;
int MemberID; //int MemberID;
MemberID = 1; //MemberID = 1;
db.InsertRent(RentDateTimePicker.Value.Date.ToString("yyyyMMdd"), GetMembers.member_id, RentPriceID);
db.InsertRent(RentDateTimePicker.Value.Date.ToString("yyyyMMdd"), RentPriceID, MemberID);
RentDateTimePicker.Text = ""; RentDateTimePicker.Text = "";

View File

@ -25,17 +25,17 @@ namespace db_AI_4
} }
} }
// im moment nicht benötigt (sollte die id des momentanen members herauslesen)
public List<GetMembers> DisplayUser(string Email_address) public void CurrentUser(string input_mail)
{ {
List<int> QueryResult = new List<int>();
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb"))) using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb")))
{ {
var outputUser = connection.Query<GetMembers>($"SELECT member_id FROM dbo.members WHERE email_address = '{Email_address}'").ToList(); var command = "SELECT member_id FROM dbo.members WHERE members.email_address = @Email_Adress";
return outputUser; QueryResult = connection.Query<int>(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 // Insert Locations into Database start
@ -62,7 +62,7 @@ namespace db_AI_4
{ {
List<GetRents> rents = new List<GetRents>(); List<GetRents> rents = new List<GetRents>();
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)" + 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); " VALUES (@rent_date, @member_id, @rent_price_id, @location_id )", rents);
@ -73,17 +73,12 @@ namespace db_AI_4
//Registration function start //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"))) using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("marketdb")))
{ {
var command = "INSERT INTO dbo.members (email_address, password) VALUES ( @Email_address, @Password)";
List<GetMembers> members = new List<GetMembers>(); connection.Execute(command, new { Email_address = input_mail, Password = input_pw });
members.Add(new GetMembers { email_address = Email_address, password = Password });
connection.Execute("INSERT INTO dbo.members ( email_address, password)" +
" VALUES (@Email_address, @Password) ", members);
} }
} }
@ -123,7 +118,7 @@ namespace db_AI_4
if (count == 1) if (count == 1)
{ {
MessageBox.Show("It Worked"); CurrentUser(GetMembers.email_address);
Dashboard dashboard = new Dashboard(); Dashboard dashboard = new Dashboard();
dashboard.Show(); dashboard.Show();
} }

View File

@ -6,17 +6,15 @@ using System.Threading.Tasks;
namespace db_AI_4 namespace db_AI_4
{ {
public class GetMembers public static class GetMembers
{ {
public int member_id { get; set; } public static int member_id { get; set; }
public string email_address { get; set; } public static string email_address { get; set; }
public string password { get; set; } public static string password { get; set; }
public int member_status_id { get; set; } public static int member_status_id { get; set; }
public static string MemberInfo
public string MemberInfo
{ {
get get
{ {
@ -25,7 +23,7 @@ namespace db_AI_4
} }
public string MemberID public static string MemberID
{ {
get get
{ {

View File

@ -22,18 +22,19 @@ namespace db_AI_4
private void RegistrationButton_Click(object sender, EventArgs e) private void RegistrationButton_Click(object sender, EventArgs e)
{ {
DataAccess db = new DataAccess(); DataAccess db = new DataAccess();
GetMembers.email_address = EmailLoginBox.Text;
db.InsertMember(EmailLoginBox.Text, PasswordLoginBox.Text); GetMembers.password = PasswordLoginBox.Text;
db.InsertMember(GetMembers.email_address, GetMembers.password);
EmailLoginBox.Text = ""; MessageBox.Show("Member Registered.");
PasswordLoginBox.Text = "";
} }
private void LoginButton_Click(object sender, EventArgs e) private void LoginButton_Click(object sender, EventArgs e)
{ {
DataAccess db = new DataAccess(); 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);
} }