diff --git a/REZ/AccountInfo.xaml b/REZ/AccountInfo.xaml index 6e642f1..abe1fba 100644 --- a/REZ/AccountInfo.xaml +++ b/REZ/AccountInfo.xaml @@ -88,7 +88,7 @@ - + diff --git a/REZ/AccountInfo.xaml.cs b/REZ/AccountInfo.xaml.cs index 3e9f483..4a22d93 100644 --- a/REZ/AccountInfo.xaml.cs +++ b/REZ/AccountInfo.xaml.cs @@ -36,14 +36,14 @@ public AccountInfo() this.InitializeComponent(); UpdateUser(User); Debug.WriteLine($"[AccountInfo] Current User: {User.Name}"); - UpdatePrice(ProductsList); - myListView.ItemsSource = User.ItemsList; + } //---------------------------------------------------------------------------- public void UpdatePrice(List productsList) { + double subtotal = SubtotalValueCalculator(productsList); string subtotalValue = subtotal.ToString("0.00"); double taxa = subtotal * 0.1; @@ -62,9 +62,10 @@ public double SubtotalValueCalculator(List productsList) foreach (Product product in productsList) { - finalValue += product.Price; + Debug.WriteLine($"{product.Name}: {product.Quantity}"); + finalValue += product.FinalPrice; } - + Debug.WriteLine($"[AccountInfo] Valor subtotal final: R$ {finalValue}"); return finalValue; } diff --git a/REZ/AccountsList.cs b/REZ/AccountsList.cs index 3b9e5be..5138ee9 100644 --- a/REZ/AccountsList.cs +++ b/REZ/AccountsList.cs @@ -27,20 +27,20 @@ public static Account SelectedAccount set { selectedAccount = value; } } - public static ShoppingCart Cart { get { return shoppingCart; } set { shoppingCart = value; } } + //---------------------------------------------------------------------------- public AccountsList() { - //Accounts = new List { }; - shoppingCart = InicializeNewShoppingCart(); + shoppingCart = new ShoppingCart(); //Criar a conta no DB } + //---------------------------------------------------------------------------- public static List AddNewAccount(Account account) { @@ -49,6 +49,7 @@ public static List AddNewAccount(Account account) return Accounts; } + //---------------------------------------------------------------------------- public static void RemoveAccount(Account account) { //Remover conta do DB @@ -66,6 +67,7 @@ public static void RemoveAccount(Account account) } + //---------------------------------------------------------------------------- public static Account SwitchAccounts(Account newAccount) { if (Accounts.Count > 0) @@ -91,23 +93,7 @@ public static Account SwitchAccounts(Account newAccount) return SelectedAccount; } - - public void CloseAccounts() - { - //deletar todas as contas do DB - Accounts.Clear(); - InicializeNewShoppingCart(); - - } - - private ShoppingCart InicializeNewShoppingCart() - { - Random random = new Random(); // mudar para um gerador de Id de respeito - string newOrderId = random.Next(0, 100).ToString(); - return new ShoppingCart(newOrderId); - - } - + //---------------------------------------------------------------------------- public static List GetAvailableUsers() { List availableUsers = new List(); diff --git a/REZ/AddAccountModal.xaml.cs b/REZ/AddAccountModal.xaml.cs index 4cf857a..51cbaa3 100644 --- a/REZ/AddAccountModal.xaml.cs +++ b/REZ/AddAccountModal.xaml.cs @@ -100,12 +100,12 @@ private void CPFNumber_TextChange(object sender, TextChangedEventArgs e) ErrorMessage_CPF.Text = CPF.Text + "Por favor digite um número de CPF."; IsCPFInputValid = false; } - else if (!ValidateCPF(CPF.Text)) - { - ErrorMessage_CPF.Visibility = Visibility.Visible; - ErrorMessage_CPF.Text = CPF.Text + " não é um CPF válido. Por favor insira um número de CPF."; - IsCPFInputValid = false; - } + //else if (!ValidateCPF(CPF.Text)) + //{ + // ErrorMessage_CPF.Visibility = Visibility.Visible; + // ErrorMessage_CPF.Text = CPF.Text + " não é um CPF válido. Por favor insira um número de CPF."; + // IsCPFInputValid = false; + //} else { ErrorMessage_CPF.Visibility = Visibility.Collapsed; diff --git a/REZ/CloseAccountConfirmation.xaml.cs b/REZ/CloseAccountConfirmation.xaml.cs index 3897bff..8a1e28e 100644 --- a/REZ/CloseAccountConfirmation.xaml.cs +++ b/REZ/CloseAccountConfirmation.xaml.cs @@ -27,5 +27,6 @@ public CloseAccountConfirmation() { this.InitializeComponent(); } + } } diff --git a/REZ/FoodMenu.xaml.cs b/REZ/FoodMenu.xaml.cs index b79cfdb..2947946 100644 --- a/REZ/FoodMenu.xaml.cs +++ b/REZ/FoodMenu.xaml.cs @@ -193,8 +193,8 @@ public void SwitchUser_ButtonClick(object sender, RoutedEventArgs e) } - //---------------------------------------------------------------------------- - private async void CreateAccount(object sender, RoutedEventArgs e) + //---------------------------------------------------------------------------- + private async void CreateAccount(object sender, RoutedEventArgs e) { ContentDialog dialog = new ContentDialog(); dialog.XamlRoot = this.XamlRoot; @@ -226,5 +226,6 @@ public void UpdateUser(Account user) Greetings.Text = $"Olá, {User.Name}!"; ShoppingCart.DefineUser(User); } + } } \ No newline at end of file diff --git a/REZ/Product.cs b/REZ/Product.cs index dd3f804..e311599 100644 --- a/REZ/Product.cs +++ b/REZ/Product.cs @@ -14,6 +14,7 @@ public class Product : ICloneable private string category; private string subCategory; private int quantity; + private double finalPrice = 0; public string OrderId { @@ -44,6 +45,12 @@ public double Price { get { return quantity > 0? price * quantity : price; } set { price = value; } + } + + public double FinalPrice + { + get { return finalPrice; } + set { finalPrice = value; } } public string Description { @@ -79,7 +86,9 @@ public object Clone() return new Product(this.Name, this.Description, this.Price, this.imageSource, this.Category) { SubCategory = this.SubCategory, - Quantity = this.Quantity + Quantity = this.Quantity, + OrderId = this.OrderId, + }; } diff --git a/REZ/ShoppingCart.cs b/REZ/ShoppingCart.cs index e8f1ca9..7d15681 100644 --- a/REZ/ShoppingCart.cs +++ b/REZ/ShoppingCart.cs @@ -15,7 +15,7 @@ public class ShoppingCart // public AccountsList OpenAccounts; public static Account User = AccountsList.SelectedAccount; public double TotalPrice; - public string OrderId; + public static string OrderId = "0"; public static List OrderProducts { @@ -24,9 +24,10 @@ public static List OrderProducts } //---------------------------------------------------------------------------- - public ShoppingCart(string orderId) + public ShoppingCart() { - OrderId = orderId; + OrderId = (int.Parse(OrderId) + 1).ToString(); + if (User != null) { @@ -112,15 +113,21 @@ public void CompleteOrder(List accountsToDivide, List orderIte foreach (Product item in orderItemsList) { double valueForEach = item.DivideItemPrice(accountsToDivide, accountsQuantity); + + Debug.WriteLine($"contas para dividir: {accountsToDivide.Count}"); foreach (Account account in accountsToDivide) { + Product newItem = item.Clone() as Product; + //newItem.Price = valueForEach; bool addNewItem = true; + foreach (Product itemInAccount in account.ItemsList) { - if (item.Name == itemInAccount.Name) + if (newItem.Name == itemInAccount.Name) { - itemInAccount.Quantity += item.Quantity; + itemInAccount.Quantity += newItem.Quantity; + itemInAccount.FinalPrice += valueForEach; addNewItem = false; } @@ -128,12 +135,14 @@ public void CompleteOrder(List accountsToDivide, List orderIte if (addNewItem) { - Product newItem = item.Clone() as Product; - newItem.Price = valueForEach; + newItem.FinalPrice += valueForEach; account.AddItem(newItem); } + Debug.WriteLine($"adddNewItem: {addNewItem}"); + Debug.WriteLine($"items na conta: {account.ItemsList.Count}"); } + item.RemoveItemFromCart(); } diff --git a/REZ/ShoppingCartModal.xaml b/REZ/ShoppingCartModal.xaml index d573ae2..9f046bf 100644 --- a/REZ/ShoppingCartModal.xaml +++ b/REZ/ShoppingCartModal.xaml @@ -65,10 +65,10 @@ - + - + diff --git a/REZ/ShoppingCartModal.xaml.cs b/REZ/ShoppingCartModal.xaml.cs index aa55d9c..ead7bbe 100644 --- a/REZ/ShoppingCartModal.xaml.cs +++ b/REZ/ShoppingCartModal.xaml.cs @@ -15,6 +15,7 @@ using Newtonsoft.Json; using static System.Net.WebRequestMethods; using System.Diagnostics; +using System.Security.Principal; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -43,30 +44,35 @@ public ShoppingCartModal(ShoppingCart shoppingCart, ContentDialog dialog) DataContext = this; } - private void CountryComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + //---------------------------------------------------------------------------- + private void AddAccountToSplit(object sender, RoutedEventArgs e) { - List selectedAccounts = new List(); - + CheckBox checkBox = sender as CheckBox; + + foreach (Account account in CreatedAccounts) + { + if (account.Name == (string)checkBox.Content && account.CPF == (string)checkBox.Tag && account.IsEnabled == true) + { + AccountsToDivide = ShoppingCart.AddSplitAccount(account); + break; + } + } } - private void SplitAccount_Updater(object sender, SelectionChangedEventArgs e) + //---------------------------------------------------------------------------- + private void RemoveAccountToSplit(object sender, RoutedEventArgs e) { - Debug.WriteLine($"Created accounts: {CreatedAccounts.Count}"); - foreach (var account in CreatedAccounts) + CheckBox comboBox = sender as CheckBox; + + foreach (Account account in ShoppingCart.AccountsToDivide) { - if (account.IsSelected) - { - ShoppingCart.AddSplitAccount(account); - } - else + if (account.Name == (string)comboBox.Content && account.CPF == (string)comboBox.Tag) { - ShoppingCart.RemoveSplitAccount(account); + AccountsToDivide = ShoppingCart.AddSplitAccount(account); + break; } - } - - } //---------------------------------------------------------------------------- diff --git a/REZ/SwitchAccountModal.xaml.cs b/REZ/SwitchAccountModal.xaml.cs index 85f133d..6b5045c 100644 --- a/REZ/SwitchAccountModal.xaml.cs +++ b/REZ/SwitchAccountModal.xaml.cs @@ -38,6 +38,7 @@ public SwitchAccountModal() } + //---------------------------------------------------------------------------- private void SelectedUserChanged(object sender, SelectionChangedEventArgs e) { UserToChange = AccountsOptions.SelectedItem as Account;