What's new

C# Pa help naman po pano mag lagay ng peso sign

Kingh3h3

Forum Veteran
Joined
Aug 7, 2018
Posts
686
Reaction
2,938
Points
551
Pa help naman mga lodi pano mag lagay ng peso sign sa code ko
ito po yung code

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace mingmingPOS
{
internal class BaseMenu

{
public void Menulist()
{
List<Product> productList = new List<Product>();
List<Product> cart = new List<Product>();

bool exit = false;
while (!exit)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("==================================================================================================================");
Console.WriteLine();
Console.WriteLine(" WELCOME TO MINGMING POS");
Console.WriteLine();
Console.WriteLine(" 1. ADD PRODUCT");
Console.WriteLine(" 2. UPDATE PRODUCT");
Console.WriteLine(" 3. REMOVE PRODUCT");
Console.WriteLine(" 4. DISPLAY ALL PRODUCTS");
Console.WriteLine(" 5. ADD ITEM TO CART");
Console.WriteLine(" 6. REMOVE ITEM FROM CART");
Console.WriteLine(" 7. DISPLAY ALL ITEMS IN CART");
Console.WriteLine(" 8. CHECKOUT");
Console.WriteLine();
Console.WriteLine(" 9. LOG OUT");
Console.WriteLine();
Console.WriteLine("==================================================================================================================");
Console.WriteLine();

int choice = GetMenuChoice();
switch (choice)
{
case 1:
AddProduct(productList);
break;
case 2:
UpdateProduct(productList);
break;
case 3:
RemoveProduct(productList);
break;
case 4:
DisplayProducts(productList);
break;
case 5:
AddToCart(productList, cart);
break;
case 6:
RemoveFromCart(cart);
break;
case 7:
DisplayCart(cart);
break;
case 8:
Checkout(cart);
break;
case 9:
exit = true;
break;
}
}
}

static int GetMenuChoice()
{
Console.WriteLine();
Console.Write(" Enter your choice : ");
string input = Console.ReadLine();
Console.WriteLine("============================");
Console.WriteLine();
Console.WriteLine();
int choice;
while (!int.TryParse(input, out choice) || choice < 1 || choice > 9)
{
Console.Write(" Invalid choice. Enter a number between 1 and 9 : ");
input = Console.ReadLine();
}
return choice;
}

static void AddProduct(List<Product> productList)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-PH");
int code = GetNextCode(productList);
Console.Write(" Enter the product name : ");
string name = Console.ReadLine();
Console.Write(" Enter the product price : ");
double price = GetPrice();
Console.Write(" Enter the product quantity : ");
int quantity = GetQuantity();

DateTime dateAdded = DateTime.Now;
Product product = new Product(code, name, price, quantity, dateAdded);
productList.Add(product);
Console.WriteLine(" Product added successfully!");
}

static void UpdateProduct(List<Product> productList)
{
Console.Write(" Enter the code of the product to update : ");
int code = GetProductCode(productList);
if (code == -1)
{
Console.Write(" Product not found. Display the products to know the code.");
return;
}
Product product = GetProductByCode(productList, code);
Console.Write(" Enter the new product name : ");
string name = Console.ReadLine();
Console.Write(" Enter the new product price : ");
double price = GetPrice();
Console.Write(" Enter the new product quantity : ");
int quantity = GetQuantity();

product.Name = name;
product.Price = price;
product.Quantity = quantity;
Console.WriteLine(" Product updated successfully!");
}

static void RemoveProduct(List<Product> productList)
{
Console.Write(" Enter the code of the product to remove: ");
int code = GetProductCode(productList);
if (code == -1)
{
Console.WriteLine(" Product not found. Display products to know the code.");
return;
}

Product product = GetProductByCode(productList, code);
productList.Remove(product);
Console.WriteLine(" Product removed successfully!");
}

static void DisplayProducts(List<Product> productList)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-PH");
Console.WriteLine(" PRODUCT LIST ");
Console.WriteLine();
foreach (Product product in productList)
{
Console.WriteLine();
Console.WriteLine($" Code : {product.Code}\n" +
$" Name : {product.Name}\n" +
$" Price : {product.Price:C}\n" +
$" Quantity : {product.Quantity}\n" +
$" Product added at {DateTime.Now}");
Console.WriteLine();
Console.WriteLine("------------------------------------------------------------------------------------------------------------------");
}
}

static void AddToCart(List<Product> productList, List<Product> cart)
{
Console.Write(" Enter the code of the product to add to the cart : ");
int code = GetProductCode(productList);
if (code == -1)
{
Console.WriteLine(" Product not found. Display the products to know the code");
return;
}

Product product = GetProductByCode(productList, code);
Console.Write(" Enter the quantity to add to the cart : ");
int quantity = GetQuantity();
if (quantity > product.Quantity)
{
Console.WriteLine(" Not enough stock.");
return;
}

product.Quantity -= quantity;
Product cartProduct = GetProductByCode(cart, code);
if (cartProduct == null)
{
DateTime dateTime= DateTime.Now;
cartProduct = new Product(product.Code, product.Name, product.Price, quantity, dateTime);
cart.Add(cartProduct);
}
else
{
cartProduct.Quantity += quantity;
}
Console.WriteLine(" Product added to cart successfully!");
}

static void RemoveFromCart(List<Product> cart)
{
Console.Write(" Enter the code of the product to remove from the cart: ");
int code = GetProductCode(cart);
if (code == -1)
{
Console.WriteLine(" Product not found. Display the products to know the code.");
return;
}
Product cartProduct = GetProductByCode(cart, code);
Console.Write(" Enter the quantity to remove from the cart : ");
int quantity = GetQuantity();
if (quantity > cartProduct.Quantity)
{
Console.WriteLine(" Invalid quantity.");
return;
}

cartProduct.Quantity -= quantity;
if (cartProduct.Quantity == 0)
{
cart.Remove(cartProduct);
}
Console.WriteLine(" Product removed from cart successfully!");
}

static void DisplayCart(List<Product> cart)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-PH");
Console.WriteLine(" CART");
Console.WriteLine();
foreach (Product product in cart)
{
Console.WriteLine();
Console.WriteLine($" Code : {product.Code}\n" +
$" Name : {product.Name}\n" +
$" Price : {product.Price:C}\n" +
$" Quantity : {product.Quantity}\n" +
$" Product added at {DateTime.Now}");
Console.WriteLine();
Console.WriteLine("------------------------------------------------------------------------------------------------------------------");
}
}

static void Checkout(List<Product> cart)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-PH");
Console.WriteLine(" Your Checkout ");
double total = 0;
foreach (Product product in cart)
{
total += product.Price * product.Quantity;

Console.WriteLine($" Code : {product.Code}\n" +
$" Name : {product.Name}\n" +
$" Price : {product.Price:C}\n" +
$" Quantity : {product.Quantity}\n" +
$" Total : {total:C}\n" +
$" Product added at {DateTime.Now}");
Console.WriteLine("------------------------------------------------------------------------------------------------------------------");

}

cart.Clear();
}

static int GetNextCode(List<Product> productList)
{
int maxCode = 0;
foreach (Product product in productList)
{
if (product.Code > maxCode)
{
maxCode = product.Code;
}
}
return maxCode + 1;
}

static int GetProductCode(List<Product> productList)
{
string input = Console.ReadLine();
int code;
while (!int.TryParse(input, out code))
{
Console.Write(" Invalid code. Enter a number : ");
input = Console.ReadLine();
}
Product product = GetProductByCode(productList, code);
if (product == null)
{
return -1;
}
return code;
}

static Product GetProductByCode(List<Product> productList, int code)
{
foreach (Product product in productList)
{
if (product.Code == code)
{
return product;
}
}
return null;
}

static double GetPrice()
{
string input = Console.ReadLine();
double price;
while (!double.TryParse(input, out price) || price <= 0)
{
Console.Write(" Invalid price. Enter a positive number : ");
input = Console.ReadLine();
}
return price;
}

static int GetQuantity()
{
string input = Console.ReadLine();
int quantity;
while (!int.TryParse(input, out quantity) || quantity <= 0)
{
Console.Write(" Invalid quantity. Enter a positive number : ");
input = Console.ReadLine();
}
return quantity;

}
class Product
{
public int Code { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public int Quantity { get; set; }

public DateTime Dateadded { get; set; }
public Product(int code, string name, double price, int quantity, DateTime dateAdded)
{
Code = code;
Name = name;
Price = price;
Quantity = quantity;
Dateadded = dateAdded;
}
}
}
}
 

Similar threads

Back
Top