private void button1_Click_1(object sender, EventArgs e) { string tmp = ""; string authLevel = ""; try { using (SqlConnection connection = new SqlConnection( global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase)) { using (SqlCommand cmd = new SqlCommand("SELECT password, authLevel FROM Admin WHERE username=@user", connection)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@user", userBox.Text); connection.Open(); SqlDataReader o = cmd.ExecuteReader(); if (o != null) { while (o.Read()) { tmp = o["password"].ToString(); authLevel = o["authLevel"].ToString(); } } connection.Close(); } } if (passBox.Text != tmp || tmp == "") { List <Label> Labels = new List <Label>(); Labels.Add(MyLabel.SetOKLabel("Login Failed!")); Labels.Add(MyLabel.SetOKLabel("Incorrect Username/Password")); List <Button> Buttons = new List <Button>(); Buttons.Add(MyButton.SetOKThemeButton()); MyMessageBox.Show( Labels, "", Buttons, MyImage.SetFailed()); userBox.Text = ""; passBox.Text = ""; } else { List <Label> Labels = new List <Label>(); Labels.Add(MyLabel.SetOKLabel("Successfull Login!")); Labels.Add(MyLabel.SetOKLabel("Welcome Back " + userBox.Text + "!")); List <Button> Buttons = new List <Button>(); Buttons.Add(MyButton.SetOKThemeButton()); MyMessageBox.Show( Labels, "", Buttons, MyImage.SetSuccess()); HomeForm h = new HomeForm(authLevel, userBox.Text); h.MaximizeBox = false; h.MinimizeBox = false; this.Hide(); h.ShowDialog(); this.Close(); } } catch (Exception ex) { List <Label> Labels = new List <Label>(); Labels.Add(MyLabel.SetOKLabel("General Error")); Labels.Add(MyLabel.SetOKLabel(ex.Message)); List <Button> Buttons = new List <Button>(); Buttons.Add(MyButton.SetOKThemeButton()); MyMessageBox.Show( Labels, "", Buttons, MyImage.SetFailed()); } }
private void button3_Click(object sender, EventArgs e) { try { using (SqlConnection connection = new SqlConnection( global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase)) { using (SqlCommand command2 = new SqlCommand("INSERT INTO Account(PaymentDate,ExpirationDate,Price,Name,Surname,MemberId)" + "VALUES(@PaymentDate,@ExpirationDate,@Price,@Name,@Surname,@MemberId)", connection)) { int x = Convert.ToInt32(noofmonthslabel.Text); command2.Parameters.AddWithValue("PaymentDate", DateTime.Today); command2.Parameters.AddWithValue("ExpirationDate", Convert.ToDateTime(membershipuntil.Text)); command2.Parameters.AddWithValue("Price", pricelabel.Text); command2.Parameters.AddWithValue("Name", namelabel.Text); command2.Parameters.AddWithValue("Surname", surnamelabel.Text); command2.Parameters.AddWithValue("MemberId", b.id); command2.Connection.Open(); if (command2.ExecuteNonQuery().ToString() == "1") { List <Label> Labels = new List <Label>(); Labels.Add(MyLabel.SetOKLabel("Membership extension.")); Labels.Add(MyLabel.SetOKLabel("Successfully Passed")); List <Button> Buttons = new List <Button>(); Buttons.Add(MyButton.SetOKThemeButton()); MyMessageBox.Show( Labels, "", Buttons, MyImage.SetSuccess()); } else { List <Label> Labels = new List <Label>(); Labels.Add(MyLabel.SetOKLabel("Membership extension.")); Labels.Add(MyLabel.SetOKLabel("Failed.")); List <Button> Buttons = new List <Button>(); Buttons.Add(MyButton.SetOKThemeButton()); MyMessageBox.Show( Labels, "", Buttons, MyImage.SetFailed()); } command2.Connection.Close(); this.Close(); } } } catch (Exception ex) { List <Label> Labels = new List <Label>(); Labels.Add(MyLabel.SetOKLabel("Membership extension.")); Labels.Add(MyLabel.SetOKLabel(ex.Message)); List <Button> Buttons = new List <Button>(); Buttons.Add(MyButton.SetOKThemeButton()); MyMessageBox.Show( Labels, "", Buttons, MyImage.SetFailed()); } }
private void HomeForm_Load(object sender, EventArgs e) { timer1.Start(); try { using (SqlConnection connection = new SqlConnection(global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase)) { bool tmp = false; using (SqlCommand cmd = new SqlCommand("SELECT PATH FROM Settings WHERE Id=1", connection)) { cmd.CommandType = CommandType.Text; connection.Open(); object o = cmd.ExecuteScalar(); if (o != null) { if (o.ToString() == "") { tmp = true; } else { tmp = false; } } else { tmp = true; } cmd.Connection.Close(); } if (tmp) { using (SqlCommand command = new SqlCommand("UPDATE Settings SET PATH=@p WHERE Id=1 ", connection)) { string wanted_path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())); command.Parameters.AddWithValue("@p", wanted_path); command.Connection.Open(); command.ExecuteNonQuery(); command.Connection.Close(); } } } sport.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); sport.Open(); } catch (Exception ex) { List <Label> Labels = new List <Label>(); Labels.Add(MyLabel.SetOKLabel("General Error")); Labels.Add(MyLabel.SetOKLabel(ex.Message)); List <Button> Buttons = new List <Button>(); Buttons.Add(MyButton.SetOKThemeButton()); MyMessageBox.Show( Labels, "", Buttons, MyImage.SetFailed()); } }
private void GetInfo() { try { Int64 i = Convert.ToInt64(id); using (SqlConnection connection = new SqlConnection( global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase)) { using (SqlCommand cmd = new SqlCommand("SELECT id FROM Member WHERE CardId=@CardId", connection)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@CardId", i); connection.Open(); object o = cmd.ExecuteScalar(); if (o != null) { string city = o.ToString(); int k = Convert.ToInt32(city); using (SqlCommand cmd2 = new SqlCommand("SELECT Name, Surname, Address, PhoneNumber, TypeId, NumOfEntrances, Gender, " + "LastEntrance FROM Member WHERE id=@id", connection)) { cmd2.CommandType = CommandType.Text; cmd2.Parameters.AddWithValue("@id", k); SqlDataReader dr = cmd2.ExecuteReader(); while (dr.Read()) { string name1 = dr["Name"].ToString(); string surname1 = dr["Surname"].ToString(); string address1 = dr["Address"].ToString(); string phoneno1 = dr["PhoneNumber"].ToString(); string typeid1 = dr["TypeId"].ToString(); int numofentrances1 = Convert.ToInt32(dr["NumOfEntrances"]); DateTime lastEntr = Convert.ToDateTime(dr["LastEntrance"]); string gender1 = dr["Gender"].ToString(); DateTime z = methods.GetExpirationDate(k); if (lastEntr.Date != DateTime.Today) { numofentrances1++; methods.WriteEntrance(k, numofentrances1, name1, surname1); } methods.WriteLastEntrance(k); lastEntr = DateTime.Now; a.Name = name1; a.Surname = surname1; a.Address = address1; a.PhoneNumber = phoneno1; a.TypeId = typeid1; a.NumOfEntrances = numofentrances1; a.ExpirationDate = z; a.CardId = i; a.LastEntrance = lastEntr; a.Gender = gender1; a.id = k; } } } connection.Close(); } } } catch (Exception ex) { List <Label> Labels = new List <Label>(); Labels.Add(MyLabel.SetOKLabel("General Error")); Labels.Add(MyLabel.SetOKLabel(ex.Message)); List <Button> Buttons = new List <Button>(); Buttons.Add(MyButton.SetOKThemeButton()); MyMessageBox.Show( Labels, "", Buttons, MyImage.SetFailed()); } }