Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions Order.Management/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,12 @@ namespace Order.Management
{
class Circle : Shape
{
public int circlePrice = 3;
public Circle(int red, int blue, int yellow)
{
Name = "Circle";
base.Price = circlePrice;
AdditionalCharge = 1;
base.NumberOfRedShape = red;
base.NumberOfBlueShape = blue;
base.NumberOfYellowShape = yellow;
}
public override int Total()
{
return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal();
}
public override string Name => "Circle";

public int RedCirclesTotal()
{
return (base.NumberOfRedShape * Price);
}
public int BlueCirclesTotal()
{
return (base.NumberOfBlueShape * Price);
}
public int YellowCirclesTotal()
public override int Price => 3;

public Circle(int red, int blue, int yellow) :base(red, blue, yellow)
{
return (base.NumberOfYellowShape * Price);
}
}
}
13 changes: 13 additions & 0 deletions Order.Management/CustomerInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Order.Management
{
class CustomerInfo
{
public string CustomerName { get; set; }
public string Address { get; set; }
public string DueDate { get; set; }
}
}
65 changes: 17 additions & 48 deletions Order.Management/CuttingListReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,32 @@ namespace Order.Management
{
class CuttingListReport : Order
{
public int tableWidth = 20;
public CuttingListReport(string customerName, string customerAddress, string dueDate, List<Shape> shapes)
public CuttingListReport(CustomerInfo customerInfo, List<Shape> shapes) : base(customerInfo, shapes)
{
base.CustomerName = customerName;
base.Address = customerAddress;
base.DueDate = dueDate;
base.OrderedBlocks = shapes;
}

public override void GenerateReport()
{
Console.WriteLine("\nYour cutting list has been generated: ");
Console.WriteLine(base.ToString());
generateTable();
}
public void generateTable()
public override int TableWidth => 20;

public override string ReportType => "Cutting List";

public override void GenerateTable()
{
PrintLine();
PrintRow(" ", " Qty ");
PrintLine();
PrintRow("Square",base.OrderedBlocks[0].TotalQuantityOfShape().ToString());
PrintRow("Triangle", base.OrderedBlocks[1].TotalQuantityOfShape().ToString());
PrintRow("Circle", base.OrderedBlocks[2].TotalQuantityOfShape().ToString());
PrintRow(new List<string> {
" ",
" Qty "
});
PrintLine();
}
public void PrintLine()
{
Console.WriteLine(new string('-', tableWidth));
}

public void PrintRow(params string[] columns)
{
int width = (tableWidth - columns.Length) / columns.Length;
string row = "|";

foreach (string column in columns)
foreach (var order in OrderedBlocks)
{
row += AlignCentre(column, width) + "|";
PrintRow(new List<string>
{
order.Name,
order.TotalQuantity.ToString(),
});
}

Console.WriteLine(row);
}

public string AlignCentre(string text, int width)
{
text = text.Length > width ? text.Substring(0, width - 3) + "..." : text;

if (string.IsNullOrEmpty(text))
{
return new string(' ', width);
}
else
{
return text.PadRight(width - (width - text.Length) / 2).PadLeft(width);
}
PrintLine();
}


}
}
91 changes: 23 additions & 68 deletions Order.Management/InvoiceReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,93 +6,48 @@ namespace Order.Management
{
class InvoiceReport : Order
{
public int tableWidth = 73;
public InvoiceReport(string customerName, string customerAddress, string dueDate, List<Shape> shapes)
public override string ReportType => "Invoice" ;

private string PriceAtText => "@ $";
private string PriceTotalText => "ppi = $";
private int TotalReds => TotalAmountOfRedShapes();

public InvoiceReport(CustomerInfo customerInfo, List<Shape> shapes) : base(customerInfo, shapes)
{
base.CustomerName = customerName;
base.Address = customerAddress;
base.DueDate = dueDate;
base.OrderedBlocks = shapes;
}

public override void GenerateReport()
{
Console.WriteLine("\nYour invoice report has been generated: ");
Console.WriteLine(base.ToString());
ReportHeader(ReportType);
GenerateTable();
OrderSquareDetails();
OrderTriangleDetails();
OrderCircleDetails();
RedPaintSurcharge();
}
Console.WriteLine(Environment.NewLine);
foreach (var order in OrderedBlocks)
{
Console.WriteLine("{0} {1} {2}{3} {4}{5}",order.Name, order.TotalQuantity, PriceAtText, order.Price, PriceTotalText, order.TotalPrice);
}

public void RedPaintSurcharge()
{
Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + base.OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge());
RedPaintSurcharge();
}

public int TotalAmountOfRedShapes()
private void RedPaintSurcharge()
{
return base.OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape +
base.OrderedBlocks[2].NumberOfRedShape;
Console.WriteLine("{0} {1} {2}{3} {4}{5}","Red Paint Surcharge", TotalAmountOfRedShapes(), PriceAtText, TotalReds, PriceTotalText , TotalPriceRedPaintSurcharge());
}

public int TotalPriceRedPaintSurcharge()
{
return TotalAmountOfRedShapes() * base.OrderedBlocks[0].AdditionalCharge;
}
public void GenerateTable()
{
PrintLine();
PrintRow(" ", " Red ", " Blue ", " Yellow ");
PrintLine();
PrintRow("Square", base.OrderedBlocks[0].NumberOfRedShape.ToString(), base.OrderedBlocks[0].NumberOfBlueShape.ToString(), base.OrderedBlocks[0].NumberOfYellowShape.ToString());
PrintRow("Triangle", base.OrderedBlocks[1].NumberOfRedShape.ToString(), base.OrderedBlocks[1].NumberOfBlueShape.ToString(), base.OrderedBlocks[1].NumberOfYellowShape.ToString());
PrintRow("Circle", base.OrderedBlocks[2].NumberOfRedShape.ToString(), base.OrderedBlocks[2].NumberOfBlueShape.ToString(), base.OrderedBlocks[2].NumberOfYellowShape.ToString());
PrintLine();
}
public void OrderSquareDetails()
{
Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].Total());
}
public void OrderTriangleDetails()
private int TotalAmountOfRedShapes()
{
Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].Total());
}
public void OrderCircleDetails()
{
Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].Total());
}
public void PrintLine()
{
Console.WriteLine(new string('-', tableWidth));
}

public void PrintRow(params string[] columns)
{
int width = (tableWidth - columns.Length) / columns.Length;
string row = "|";

foreach (string column in columns)
var totalReds = 0;
foreach(var order in OrderedBlocks)
{
row += AlignCentre(column, width) + "|";
totalReds += order.NumberOfRedShape;
}

Console.WriteLine(row);
return totalReds;
}

public string AlignCentre(string text, int width)
private int TotalPriceRedPaintSurcharge()
{
text = text.Length > width ? text.Substring(0, width - 3) + "..." : text;

if (string.IsNullOrEmpty(text))
{
return new string(' ', width);
}
else
{
return text.PadRight(width - (width - text.Length) / 2).PadLeft(width);
}
return TotalReds * base.OrderedBlocks[0].AdditionalChargeRed;
}
}
}
99 changes: 91 additions & 8 deletions Order.Management/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,100 @@ namespace Order.Management
{
abstract class Order
{
public string CustomerName { get; set; }
public string Address { get; set; }
public string DueDate { get; set; }
public int OrderNumber { get; set; }
public List<Shape> OrderedBlocks { get; set; }
CustomerInfo CustomerInfo { get; set; }
public int OrderNumber { get; private set; }
public List<Shape> OrderedBlocks { get; private set; }

public abstract void GenerateReport();
public Order(CustomerInfo customerInfo, List<Shape> shapes)
{
CustomerInfo = customerInfo;
OrderedBlocks = shapes;
}

#region Abstract Methods
public virtual void GenerateTable()
{
PrintLine();
PrintRow(new List<string>
{
" ",
" Red ",
" Blue ",
" Yellow "
});
PrintLine();
foreach(var order in OrderedBlocks)
{
PrintRow(new List<string>
{
order.Name,
order.NumberOfRedShape.ToString(),
order.NumberOfBlueShape.ToString(),
order.NumberOfYellowShape.ToString()
});
}
PrintLine();
}

#endregion

#region Abstract Properties

public virtual int TableWidth => 73;
public abstract string ReportType { get; }
#endregion

#region Protected/Private Methods

public virtual void GenerateReport()
{
ReportHeader(ReportType);
GenerateTable();
}

protected void PrintRow(List<string> columns)
{
int width = (TableWidth - columns.Count) / columns.Count;
string row = "|";

public string ToString()
foreach (string column in columns)
{
row += AlignCentre(column, width) + "|";
}

Console.WriteLine(row);
}

private string CustomerDetails()
{
return "\nName: " + CustomerInfo.CustomerName + " Address: " + CustomerInfo.Address + " Due Date: " + CustomerInfo.DueDate + " Order #: " + OrderNumber;
}

protected void PrintLine()
{
Console.WriteLine(new string('-', TableWidth));
}

protected void ReportHeader(string reportType)
{
return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber;
Console.WriteLine("\nYour {0} report has been generated: ", ReportType);
Console.WriteLine(CustomerDetails());
}

private string AlignCentre(string text, int width)
{
text = text.Length > width ? text.Substring(0, width - 3) + "..." : text;

if (string.IsNullOrEmpty(text))
{
return new string(' ', width);
}
else
{
return text.PadRight(width - (width - text.Length) / 2).PadLeft(width);
}
}

#endregion
}
}
Loading