Skip to content

Commit

Permalink
app is working fine!
Browse files Browse the repository at this point in the history
  • Loading branch information
andavgc committed Aug 27, 2023
1 parent 778b2cb commit 161dbc6
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 58 deletions.
2 changes: 1 addition & 1 deletion REZ/AccountInfo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<Run Text="Número do pedido: "/>
<Run Text="{Binding OrderId}"/>
</TextBlock>
<TextBlock Text="{Binding Price}" FontSize="12"/>
<TextBlock Text="{Binding FinalPrice}" FontSize="12"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
Expand Down
9 changes: 5 additions & 4 deletions REZ/AccountInfo.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Product> productsList)
{

double subtotal = SubtotalValueCalculator(productsList);
string subtotalValue = subtotal.ToString("0.00");
double taxa = subtotal * 0.1;
Expand All @@ -62,9 +62,10 @@ public double SubtotalValueCalculator(List<Product> 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;
}

Expand Down
26 changes: 6 additions & 20 deletions REZ/AccountsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Account> { };
shoppingCart = InicializeNewShoppingCart();
shoppingCart = new ShoppingCart();
//Criar a conta no DB
}

//----------------------------------------------------------------------------
public static List<Account> AddNewAccount(Account account)
{

Expand All @@ -49,6 +49,7 @@ public static List<Account> AddNewAccount(Account account)
return Accounts;
}

//----------------------------------------------------------------------------
public static void RemoveAccount(Account account)
{
//Remover conta do DB
Expand All @@ -66,6 +67,7 @@ public static void RemoveAccount(Account account)

}

//----------------------------------------------------------------------------
public static Account SwitchAccounts(Account newAccount)
{
if (Accounts.Count > 0)
Expand All @@ -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<Account> GetAvailableUsers()
{
List<Account> availableUsers = new List<Account>();
Expand Down
12 changes: 6 additions & 6 deletions REZ/AddAccountModal.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions REZ/CloseAccountConfirmation.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public CloseAccountConfirmation()
{
this.InitializeComponent();
}

}
}
5 changes: 3 additions & 2 deletions REZ/FoodMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -226,5 +226,6 @@ public void UpdateUser(Account user)
Greetings.Text = $"Olá, {User.Name}!";
ShoppingCart.DefineUser(User);
}

}
}
11 changes: 10 additions & 1 deletion REZ/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Product : ICloneable
private string category;
private string subCategory;
private int quantity;
private double finalPrice = 0;

public string OrderId
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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,

};
}

Expand Down
23 changes: 16 additions & 7 deletions REZ/ShoppingCart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Product> OrderProducts
{
Expand All @@ -24,9 +24,10 @@ public static List<Product> OrderProducts
}

//----------------------------------------------------------------------------
public ShoppingCart(string orderId)
public ShoppingCart()
{
OrderId = orderId;
OrderId = (int.Parse(OrderId) + 1).ToString();

if (User != null)
{

Expand Down Expand Up @@ -112,28 +113,36 @@ public void CompleteOrder(List<Account> accountsToDivide, List<Product> 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;
}

}

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();

}
Expand Down
4 changes: 2 additions & 2 deletions REZ/ShoppingCartModal.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@

<StackPanel Width="468" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="Selecione as contas que vão compartilhar esse pedido com você:" TextAlignment="Left" Foreground="Gray" />
<ComboBox x:Name="AccountsComboBox" Width="400" SelectionChanged="SplitAccount_Updater">
<ComboBox x:Name="AccountsComboBox" Width="400" >
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsSelected}" IsEnabled="{Binding IsEnabled}" />
<CheckBox Content="{Binding Name}" Tag="{Binding CPF}" IsChecked="{Binding IsSelected}" IsEnabled="{Binding IsEnabled}" Checked="AddAccountToSplit" Unchecked="RemoveAccountToSplit" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Expand Down
36 changes: 21 additions & 15 deletions REZ/ShoppingCartModal.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Account> selectedAccounts = new List<Account>();

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;
}

}


}

//----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions REZ/SwitchAccountModal.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public SwitchAccountModal()

}

//----------------------------------------------------------------------------
private void SelectedUserChanged(object sender, SelectionChangedEventArgs e)
{
UserToChange = AccountsOptions.SelectedItem as Account;
Expand Down

0 comments on commit 161dbc6

Please sign in to comment.