private void BtnLogin_Click(object sender, EventArgs e) { if (textBoxLoginEmail.Text == "" || textBoxLoginPassword.Text == "") { MessageBox.Show("The username or password is incorrect", "Information"); } else { //Accès à la table eatfast_person dans la bdd DataSetEatFast personDataSet = new DataSetEatFast(); DataSetEatFastTableAdapters.EATFAST_PERSONTableAdapter listePerson = new DataSetEatFastTableAdapters.EATFAST_PERSONTableAdapter(); listePerson.Fill(personDataSet.EATFAST_PERSON); try { //Récupération de l'utilisateur int id = (int)listePerson.FillByEmail(textBoxLoginEmail.Text); DataSetEatFast.EATFAST_PERSONRow personRow = personDataSet.EATFAST_PERSON.FindByPER_ID(id); if (personRow.PER_PASSWORD.Equals(HashCode(textBoxLoginPassword.Text))) { if (personRow.PER_ACCOUNTTYPE == "Client") { //Si compte client this.Hide(); Homepage homePage = Homepage.getInstance(); homePage.Show(); homePage.initializeUser(personRow); } else { //Si compte administrateur this.Hide(); AdminHomepage adminHomepage = AdminHomepage.getInstance(); adminHomepage.Show(); adminHomepage.initializeUser(personRow); } } else { MessageBox.Show("The username or password is incorrect", "Information"); } } catch (Exception o) { MessageBox.Show("The username or password is incorrect", "Information"); Console.Write(o); } } }
private void AddOrder() { //Insertion dans la base de données OracleConnection con = new OracleConnection("DATA SOURCE=127.0.0.1:1521/HEGLOCAL;PASSWORD=manager;USER ID=SYSTEM"); // Open a database connection con.Open(); OracleCommand cmd = new OracleCommand(); // INSERT statement with RETURNING clause to get the generated ID cmd.CommandText = "INSERT INTO eatfast_data.eatfast_order (per_id,ord_date,ord_status,ord_deliveryaddress,ord_total,ord_paymentstatus)" + " VALUES (:per_id, :ord_date, 'Delivered', :ord_deliveryaddress, :ord_total, 'Paid') RETURNING ord_id INTO :orderId"; cmd.Connection = con; cmd.Parameters.Add(new OracleParameter("per_id", user.PER_ID)); cmd.Parameters.Add(new OracleParameter("ord_date", DateTime.Now)); cmd.Parameters.Add(new OracleParameter("ord_deliveryaddress", user.PER_ADDRESS)); cmd.Parameters.Add(new OracleParameter("ord_total", total)); cmd.Parameters.Add(new OracleParameter { ParameterName = ":orderId", OracleDbType = OracleDbType.Int32, Direction = ParameterDirection.Output }); // Execute INSERT statement cmd.ExecuteNonQuery(); //Ajout des produits dans la commande Int32 newId = Convert.ToInt32(cmd.Parameters[":orderId"].Value.ToString()); ConfirmOrder(newId); //Ajout de la commande dans le datagridview des commandes Homepage.getInstance().UpdateOrders(); //Réinitialisation du panier Homepage.getInstance().ClearCart(); MessageBox.Show("Your order is on the way!"); this.Close(); }
private void ConfirmOrder(Int32 id) { // On initialise notre dataset DataSetContains containsDataSet = new DataSetContains(); DataSetContainsTableAdapters.EATFAST_CONTAINSTableAdapter containsTableAdapter = new DataSetContainsTableAdapters.EATFAST_CONTAINSTableAdapter(); //Récupération du panier SortedList <int, CartProduct> cart = Homepage.getInstance().GetCart(); foreach (KeyValuePair <int, CartProduct> cartProduct in cart) { CartProduct product = (CartProduct)cartProduct.Value; //Ajout de chaque produit dans la commande containsTableAdapter.AddToOrder(id, product.getId(), product.getPrice(), product.getQuantity()); } }
private void UpdateUserAddress() { //Accès à la table eatfast_person dans la bdd DataSetEatFast personDataSet = new DataSetEatFast(); DataSetEatFastTableAdapters.EATFAST_PERSONTableAdapter listePerson = new DataSetEatFastTableAdapters.EATFAST_PERSONTableAdapter(); try { //Mise à jour de l'adresse de livraison listePerson.UpdateAddress(textBoxAddress.Text, id); Homepage.getInstance().UpdateAddress(textBoxAddress.Text); this.Close(); } catch (Exception o) { MessageBox.Show("Something went wrong"); Console.Write(o); } }
private void RegisterUser() { //Accès à la table eatfast_person dans la bdd DataSetEatFast personDataSet = new DataSetEatFast(); DataSetEatFastTableAdapters.EATFAST_PERSONTableAdapter listePerson = new DataSetEatFastTableAdapters.EATFAST_PERSONTableAdapter(); String name = textBoxSignupName.Text; String email = textBoxSignupEmail.Text; String password = HashCode(textBoxSignupPassword.Text); if (listePerson.FillByEmail(email) == null) { //Si le compte n'existe pas encore listePerson.AddAccount(name, email, password, "", "Client"); this.Hide(); Homepage homepage = Homepage.getInstance(); homepage.Show(); //Pour que le nouvel utilisateur indique son adresse de livraison homepage.InitializeNewUser(email); } else { //Sinon informer que l'utilisateur existe déjà MessageBox.Show("A user with this email already exists"); } }
private void CheckCardInformation(object sender, EventArgs e) { var cardOk = true; if (textBoxCardName.Text == "") { cardOk = false; } if (!long.TryParse(textBoxCardNumber.Text, out long cardNo)) { cardOk = false; } if ((numericUpDownMonth.Value < 0 || numericUpDownMonth.Value > 12)) { cardOk = false; } DateTime dt = DateTime.Now; Int32 mois = Int32.Parse(dt.ToString("MM")); Int32 annee = Int32.Parse(dt.ToString("yy")); if (numericUpDownYear.Value < annee) { cardOk = false; } else if (numericUpDownYear.Value == annee) { if (numericUpDownMonth.Value < mois) { cardOk = false; } } if (textBoxCardCVV.Text != "") { if (!Int32.TryParse(textBoxCardCVV.Text, out int cvv)) { cardOk = false; } else { if (cvv < 100 || cvv > 999) { cardOk = false; } else { Console.WriteLine("String could not be parsed."); } } } else { cardOk = false; } if (Homepage.getInstance().CalculateCartTotal() == 0) { cardOk = false; } if (cardOk) { btnSubmitPayment.Enabled = true; } else { btnSubmitPayment.Enabled = false; } }
private void Checkout_Load(object sender, EventArgs e) { this.total = Homepage.getInstance().CalculateCartTotal(); labelCartTotal.Text = "Total (CHF) : " + this.total; this.user = Homepage.getInstance().GetUser(); }