private void Login() { string username = textBoxUsername.Text; string password = textBoxPassword.Text; bool isUser = false; if (username.Length > 0 && password.Length > 0) { try { FormLoading.Show(); Database db = new Database(); db.CreateCommand("SELECT id FROM users WHERE username = :username AND password = :password AND isemployee = 1"); db.AddParameter("username", username); db.AddParameter("password", password); db.OpenConnection(); db.ExecuteCommand(); OracleDataReader dr = db.DataReader; if (dr.HasRows) { isUser = true; } db.CloseConnection(); FormLoading.CloseForm(); } catch (Exception ex) { MessageBox.Show(ex.Message); labelResult.Text = "Verbinding met database mislukt."; return; } if (isUser) { this.Hide(); this.formMain = new FormMain(); this.formMain.Show(); this.formMain.FormClosing += formMain_FormClosing; } else { labelResult.Text = "Uw aanmeldgegevens zijn onjuist."; } } }
/// <summary> /// this method gets the reservation by ID /// </summary> public static Reservation GetById(int id) { Reservation reservation = null; Database db = new Database(); db.CreateCommand("SELECT * FROM reservations where id = :id"); db.AddParameter("id", id); db.OpenConnection(); db.ExecuteCommand(); OracleDataReader dr = db.DataReader; if (dr.HasRows) { dr.Read(); double totalcosts = Convert.ToDouble(dr.GetFloat(3)); double totalpayed = Convert.ToDouble(dr.GetFloat(2)); reservation = new Reservation(id, totalcosts, totalpayed); } db.CloseConnection(); return reservation; }
public bool Pay(double amountToPay) { if (!Payed) { // The reservation amount payed must not preceed the costs. // Fixed here. if (amountToPay + AmountPayed > TotalCosts) { amountToPay = TotalCosts - AmountPayed; } AmountPayed += amountToPay; // Update record in the database. Database db = new Database(); db.CreateCommand("UPDATE reservations SET totalpayed = :totalpayed WHERE id = :id"); db.AddParameter("id", id); db.AddParameter("id", AmountPayed); db.OpenConnection(); db.ExecuteCommand(); db.CloseConnection(); return true; } return false; }
/// <summary> /// RFID_TAG is a event for scanning the RFID card that the customer will get /// this method will check if the booker is a mainbooker or just a regular booker. /// This event also controls the main form, it changes the output of labels, listviews /// </summary> void rfid_Tag(object sender, TagEventArgs e) { if (timer.Enabled) { return; } string cardvalue = e.Tag; Booker booker = null; LbRFID2.Text = cardvalue; rfid.LED = true; // light on try { Database db = new Database(); db.CreateCommand("SELECT id FROM bookers WHERE cardvalue = :cardvalue"); db.AddParameter("cardvalue", cardvalue); db.OpenConnection(); db.ExecuteCommand(); OracleDataReader dr = db.DataReader; dr.Read(); if (dr.HasRows) { int id = dr.GetInt32(0); booker = Booker.GetById(id); Debug.AutoFlush = true; // If the booker is not found. if (booker == null) { LbNaam2.Text = "Boeker is niet gevonden in ons systeem."; } else { LbNaam2.Text = booker.FirstName; LbTelefoon2.Text = booker.Phone; // If the booker is the mainbooker. if (booker.IsMainBooker) { if (!booker.Reservation.Payed) { // RESERVATION IS NOT PAYED. LbBetaald2.Text = "Niet betaald"; LbHoofdboeker2.Text = "Ja"; PnError.Visible = true; Console.Beep(2000, 600); lbInOut.ForeColor = Color.Red; lbInOut.Text = "IN/OUT"; } else { //Reservation is paid LbBetaald2.Text = "Voldaan"; LbHoofdboeker2.Text = "Ja"; PnError.Visible = false; Console.Beep(2000, 100); Console.Beep(2000, 200); booker.ToggleActive(); if (booker.IsCardActive) { lbInOut.ForeColor = Color.Green; lbInOut.Text = "IN"; } else { lbInOut.ForeColor = Color.Red; lbInOut.Text = "OUT"; } } } // Default booker. else { PnError.Visible = false; LbHoofdboeker2.Text = "Nee"; LbBetaald2.Text = "Niet van toepassing"; Console.Beep(2000, 100); Console.Beep(2000, 200); booker.ToggleActive(); if (booker.IsCardActive) { lbInOut.ForeColor = Color.Green; lbInOut.Text = "IN"; } else { lbInOut.ForeColor = Color.Red; lbInOut.Text = "OUT"; } } } } else { LbNaam2.Text = "Geen persoon"; LbBetaald2.Text = " "; LbHoofdboeker2.Text = " "; lbInOut.ForeColor = Color.Red; lbInOut.Text = "IN/OUT"; LbTelefoon2.Text = ""; } db.CloseConnection(); } catch (Exception ex) { MessageBox.Show(ex.Message); } timer.Start(); }
/// <summary> /// This method will turn the card on active or non-active /// When card is active the user is on the terrain /// when card is non-active the user left or is not on the terrain /// </summary> public void ToggleActive() { Database db = new Database(); if (IsCardActive) { db.CreateCommand("UPDATE bookers SET cardactive = 0 WHERE id = :id"); } else { db.CreateCommand("UPDATE bookers SET cardactive = 1 WHERE id = :id"); } db.AddParameter("id", Id); db.OpenConnection(); db.ExecuteCommand(); db.CloseConnection(); isCardActive = !isCardActive; }
/// <summary> /// This Method will get the booker and looks if it's a mainbooker /// </summary> public void LoadMainBooker() { Database db = new Database(); db.CreateCommand("SELECT * FROM mainbookers where bookers_id = :id"); db.AddParameter("id", Id); db.OpenConnection(); db.ExecuteCommand(); OracleDataReader dr = db.DataReader; dr.Read(); if (dr.HasRows) { isMainBooker = true; mainBookerLastName = dr.GetValueByColumn<string>("lastname"); } else { isMainBooker = false; } db.CloseConnection(); isMainBookerLoaded = true; }
/// <summary> /// This Method will check if the RFID card is active or not /// </summary> public void LoadCardActive() { Database db = new Database(); db.CreateCommand("SELECT * FROM bookers where id = :id AND cardactive = 1"); db.AddParameter("id", Id); db.OpenConnection(); db.ExecuteCommand(); OracleDataReader dr = db.DataReader; if (dr.HasRows) { isCardActive = true; } else { isCardActive = false; } db.CloseConnection(); }
/// <summary> /// This Method will get the booker by ID /// </summary> public static Booker GetById(int id) { Booker booker = null; Database db = new Database(); db.CreateCommand("SELECT * FROM bookers WHERE id = :id"); db.AddParameter("id", id); db.OpenConnection(); db.ExecuteCommand(); OracleDataReader dr = db.DataReader; if (dr.HasRows) { dr.Read(); booker = new Booker(id, dr.GetValueByColumn<string>("firstname"), dr.GetValueByColumn<string>("Phone"), dr.GetValueByColumn<int>("reservations_id")); } db.CloseConnection(); return booker; }