Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: Add Development Report #37

Closed
wants to merge 11 commits into from
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This workflow will build and publish a WinUI 3 unpackaged desktop application
# built on .NET.

name: WinUI 3 unpackaged app

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:

strategy:
matrix:
configuration: [Release]
platform: [x64, x86]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Solution_Name: '.\REZ\REZ.sln'

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.0.2

# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}

# Create the app by building and publishing the project
- name: Create the app
run: msbuild $env:Solution_Name /t:Publish /p:Configuration=$env:Configuration /p:Platform=$env:Platform
env:
Configuration: ${{ matrix.configuration }}
Platform: ${{ matrix.platform }}

# Upload the app
- name: Upload app
uses: actions/upload-artifact@v2
with:
name: Upload app
path: ${{ env.Solution_Name }}\\bin
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
35 changes: 15 additions & 20 deletions REZ/AddAccountModal.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,17 @@ private void InputsValidation()
// Maybe later we can add the INotifyPropertyChanged interface.
private void InputName_TextChange(object sender, TextChangedEventArgs e)
{
Regex regex = new Regex("^[a-zA-ZÀ-ÿ]{1,20}$");
if (String.IsNullOrEmpty(Name.Text))
Regex regex = new Regex("^([a-zA-ZÀ-ÿ]{3,10})+([ a-zA-ZÀ-ÿ]{0,20})$");
if (!regex.IsMatch(Name.Text))
{
ErrorMessage_Name.Visibility = Visibility.Visible;
ErrorMessage_Name.Text = Name.Text + "Por favor digite um nome.";
IsNameInputValid = false;
ErrorMessage_Name.Text = String.IsNullOrEmpty(Name.Text)
? $"Por favor digite um nome."
: $"{Name.Text} - não e um nome valido. Por favor insira outro nome.";
}
else if (!regex.IsMatch(Name.Text))
else
{
ErrorMessage_Name.Visibility = Visibility.Visible;
ErrorMessage_Name.Text = Name.Text + " não é um nome válido. Por favor insira outro nome.";
IsNameInputValid = false;
}
else
{
ErrorMessage_Name.Visibility = Visibility.Collapsed;
IsNameInputValid = true;
}
Expand All @@ -89,9 +85,7 @@ private void InputName_TextChange(object sender, TextChangedEventArgs e)
// Maybe later we can add the INotifyPropertyChanged interface.
private void CPFNumber_TextChange(object sender, TextChangedEventArgs e)
{

TextBox textBox = sender as TextBox;

string formattedCPF = FormatCPF(textBox.Text);

if (formattedCPF != textBox.Text)
Expand All @@ -100,8 +94,6 @@ private void CPFNumber_TextChange(object sender, TextChangedEventArgs e)
textBox.SelectionStart = formattedCPF.Length;
}


Regex regex = new Regex("^\\d{3}\\.?\\d{3}\\.?\\d{3}-?\\d{2}$");
if (String.IsNullOrEmpty(CPF.Text))
{
ErrorMessage_CPF.Visibility = Visibility.Visible;
Expand All @@ -112,17 +104,18 @@ private void CPFNumber_TextChange(object sender, TextChangedEventArgs e)
//{
// 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;
// IsCPFInputValid = false;
//}
else
{
ErrorMessage_CPF.Visibility = Visibility.Collapsed;
IsCPFInputValid = true;
}
InputsValidation();

}

//----------------------------------------------------------------------------
// This will validate the CPF number with its specific format and logic
private bool ValidateCPF(string cpf)
{
string digitsOnly = new string(cpf.Where(char.IsDigit).ToArray());
Expand Down Expand Up @@ -163,9 +156,14 @@ private bool ValidateCPF(string cpf)
int.Parse(digitsOnly[10].ToString()) == secondDigit;
}


//----------------------------------------------------------------------------
// This method will autoformat user input adding dots and dash to the CPF number
// for correct formatting.
// By this, the user will only need to input 1234568900 and the TextBox field
// will live update to 123.456.789-00.
private string FormatCPF(string cpf)
{

string digitsOnly = new string(cpf.Where(char.IsDigit).ToArray());

if (digitsOnly.Length > 11)
Expand All @@ -186,10 +184,7 @@ private string FormatCPF(string cpf)
{
formattedCPF = formattedCPF.Insert(11, "-");
}

return formattedCPF;
}


}
}
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
3 changes: 3 additions & 0 deletions REZ/REZ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,7 @@
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
<PropertyGroup>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
</Project>
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
Loading
Loading