Skip to content

Commit 50779e4

Browse files
committed
Updated the Json Parser
added attributes field
1 parent ba9e8ac commit 50779e4

17 files changed

Lines changed: 67 additions & 35 deletions
12.5 KB
Binary file not shown.

OrderManagerPrototype/OrderManagerPrototype/Model/Order.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ public Order()
1010
Products = new List<Product>();
1111
}
1212

13-
public Order(int orderID,string tableNumber,string dateTime,List<Product> products)
13+
public Order(int orderID,string tableNumber,string dateTime,List<Product> products,double totalPrice)
1414
{
1515
Products = new List<Product>();
1616
this.TableNumber = tableNumber;
17+
this.TotalPrice = totalPrice;
1718
this.DateTime = dateTime;
1819
this.Products = products;
1920
this.OrderID = orderID;
@@ -41,15 +42,8 @@ public string DateTime
4142

4243
public double TotalPrice
4344
{
44-
get
45-
{
46-
double price =0;
47-
foreach (Product product in Products)
48-
price += product.Price;
49-
50-
return price;
51-
}
52-
45+
get;
46+
set;
5347
}
5448

5549
public List<Product> Products

OrderManagerPrototype/OrderManagerPrototype/Model/Product.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ public class Product
1111

1212
#region Public Constructors
1313

14-
public Product(string name,double price,string notes,int quantity)
14+
public Product(string name,double price,string notes,int quantity,string attributes=" ")
1515
{
1616
this.Name = name;
1717
this.Price = price;
1818
this.Notes = notes;
1919
this.Quantity = quantity;
20+
this.Attributes = attributes;
2021
}
2122

2223
public Product()
@@ -65,6 +66,13 @@ public int Quantity
6566
set;
6667
}
6768

69+
[JsonProperty("attributes")]
70+
public string Attributes
71+
{
72+
get;
73+
set;
74+
}
75+
6876
static public int Fields
6977
{
7078
get
@@ -75,6 +83,21 @@ static public int Fields
7583

7684
#endregion
7785

86+
#region Public Helper Properties
87+
88+
public String Title
89+
{
90+
get
91+
{
92+
if (Attributes != null)
93+
return (this.Name + " " + Attributes.Replace("-", " ") + "x" + Quantity);
94+
else
95+
return (this.Name + " x" + Quantity);
96+
}
97+
}
98+
99+
#endregion
100+
78101
#region Override Equality
79102

80103
public override bool Equals(Object obj)

OrderManagerPrototype/OrderManagerPrototype/Templates/DynamicVisualTemplate.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int TableNumberHeight
7979

8080
int TotalPriceWidth
8181
{
82-
get { return 90; }
82+
get { return 100; }
8383
}
8484

8585
int TotalPriceHeight
@@ -246,9 +246,9 @@ void InitializeViewboxesAndLabels(Product product)
246246
CurrentHeight += ProductFieldHeight;
247247

248248
Label productNameLabel = new Label();
249-
productNameLabel.Width = BorderWidth / 4;
249+
productNameLabel.Width = product.Title.Length * 10 + 1;
250250
productNameLabel.FontWeight = FontWeights.Bold;
251-
productNameLabel.Content = product.Name + " x" + product.Quantity;
251+
productNameLabel.Content = product.Title;
252252
productViewbox.Child = productNameLabel;
253253
this.wrapPanel.Children.Add(productViewbox);
254254

OrderManagerPrototype/OrderManagerPrototype/UI/MainWindow.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ public MainWindow()
6161

6262
}
6363

64+
//Add mock product
6465
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
6566
{
6667
List<Product> products = new List<Product>();
67-
products.Add(new Product("name",1.1,"notes",2));
68+
products.Add(new Product("name",1.1,"notes",2,"attribute-at"));
6869
products.Add(new Product("name2", 1.12, "this is a really really long message",1));
69-
DynamicVisualTemplate mock1 = new DynamicVisualTemplate(new Order(1,"1","16.00 - 1/1/2006",products));
70+
DynamicVisualTemplate mock1 = new DynamicVisualTemplate(new Order(1,"1","16.00 - 1/1/2006",products,10));
7071
mock1.removeEvent+=removeOrderEvent;
7172
this.InboxView.Items.Add(mock1.OrderTemplate);
7273
this.InboxCounter.Content=this.InboxView.Items.Count;
@@ -79,7 +80,7 @@ private void InboxView_MouseRightButtonUp(object sender, System.Windows.Input.Mo
7980

8081
#region Handle Events
8182

82-
//TODO: review remove algorithm
83+
//TODO: review remove algorithm
8384
void removeOrderEvent(object sender, EventArgs e)
8485
{
8586
OrderEventArgs eventArgs = (OrderEventArgs)e;

OrderManagerPrototype/OrderManagerPrototype/Updater/NetworkUtil.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using Newtonsoft.Json;
55
using Newtonsoft.Json.Linq;
6+
using System.Threading;
67

78
namespace OrderManagerPrototype.Updater
89
{
@@ -31,22 +32,31 @@ public static JObject GetJson(string url)
3132
}
3233
}
3334

34-
public static void NotifyWebService(int id,string uript1 = "http://snf-185147.vm.okeanos.grnet.gr:8080/qorderws/orders/order/", string uript2 = "/order?status=ACCEPTED")
35+
public static void NotifyWebService(int id, string uript1 = "http://snf-185147.vm.okeanos.grnet.gr:8080/qorderws/orders/order/", string uript2 = "/order?status=ACCEPTED")
3536
{
36-
try
37+
using (var wb = new WebClient())
3738
{
38-
using (var wb = new WebClient())
39+
Console.WriteLine("Notified " + id);
40+
Byte[] bytes = new byte[] { 0x20 };
41+
Thread notifierThread = new Thread(
42+
o =>
3943
{
40-
Console.WriteLine("Notified " +id);
41-
Byte[] bytes = new byte[] { 0x20};
42-
var response = wb.UploadData(uript1 + id + uript2, "POST", bytes);
43-
}
44-
}catch(Exception ex)
45-
{
46-
Console.WriteLine(ex.Message);
44+
try
45+
{
46+
var response = wb.UploadData(uript1 + id + uript2, "POST", bytes);
47+
}
48+
catch (Exception ex)
49+
{
50+
Console.WriteLine(ex.Message);
51+
}
52+
});
53+
notifierThread.IsBackground = true;
54+
notifierThread.Start();
4755
}
4856
}
4957

58+
59+
5060
public static List<Order> GetOrderList(string url)
5161
{
5262

@@ -71,7 +81,7 @@ public static List<Order> GetOrderList(string url)
7181

7282
orderitem.TableNumber = (string)orderArrayItem["tableNumber"];
7383
orderitem.DateTime = (string)orderArrayItem["dateTime"];
74-
//orderitem.TotalPrice = (double)orderArrayItem["totalPrice"];
84+
orderitem.TotalPrice = (double)orderArrayItem["totalPrice"];
7585
JArray orders = (JArray)orderArrayItem["orderedProducts"];
7686

7787
foreach (JObject order in orders)
@@ -81,6 +91,7 @@ public static List<Order> GetOrderList(string url)
8191
JObject orderDTO = (JObject)order["productDTO"];
8292
product.Name = (string)orderDTO["name"];
8393
product.Price = (double)orderDTO["price"];
94+
product.Attributes = (string)order["attributes"];
8495
product.Quantity = (int)order["quantity"];
8596
product.Notes = (string)order["notes"];
8697
productList.Add(product);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)