-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
160 lines (121 loc) · 5.01 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace profiwowdektop
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public string Url = "http://profi-wow-api.sebrogala.com/";
public IList<CItem> ListCItems;
public IList<CComponents> ListCComponentses;
public MainWindow()
{
InitializeComponent();
}
private void ButtonLogIn_Click(object sender, RoutedEventArgs e)
{
LogiInWindow loginWindow = new LogiInWindow();
loginWindow.Show();
//if(loginWindow.Closed)
}
private void ButtonShowJWTBearer_Click(object sender, RoutedEventArgs e)
{
TextBox.Text = AbstractApiConnector.userBearer;
}
private void ButtonGetProfessions_Click(object sender, RoutedEventArgs e)
{
AbstractApiConnector connector = new UserApiConnector();
var profeskistring = connector.GetRespGet("/professions",
"Authorization: Bearer " + AbstractApiConnector.userBearer);
IEnumerable<CProfession> professions =
JsonConvert.DeserializeObject<IEnumerable<CProfession>>(profeskistring);
foreach (CProfession item in (IList)professions)
{
ComboBoxProfessions.Items.Add(item.name);
}
}
private void BtnSearchItem_Click(object sender, RoutedEventArgs e)
{
AbstractApiConnector connector = new UserApiConnector();
string itemName = TxBoxSearchItem.Text;
itemName = itemName.Replace(' ', '_');
var itemsstring = connector.GetRespGet("/item/" + itemName, "Authorization: Bearer " + AbstractApiConnector.userBearer);
try
{
CItem item = JsonConvert.DeserializeObject<CItem>(itemsstring);
ListCItems = new List<CItem>();
ListCComponentses = new List<CComponents>();
ListCItems.Add(item);
foreach (CItem itemItem in ListCItems)
{
AddItemToPanel(true, itemItem.name, itemItem.icon_src,
"", "");
}
foreach (var component in item.components)
{
ListCComponentses.Add(component);
}
ItemName.Content = item.name;
ItemImage.Source = new BitmapImage(new Uri("http://" + item.icon_src));
ItemPrice.Content = " ";
foreach (CComponents itemComponent in ListCComponentses)
{
AddItemToPanel(false, itemComponent.name, itemComponent.icon_src,
itemComponent.price_each.ah_price.ToString(), itemComponent.price_each.user_price.ToString());
}
}
catch (Exception)
{
MessageBox.Show("nie mozna odnalezc przedmiotu");
}
}
private void AddItemToPanel(bool Top, string name, string icon_src, string priceAH, string priceUSER)
{
var StackPanelBottomDyn = new StackPanel();
StackPanelBottomDyn.Width = 160;
StackPanelBottomDyn.Height = 171;
StackPanelBottomDyn.Orientation = Orientation.Vertical;
StackPanelBottomDyn.VerticalAlignment = VerticalAlignment.Top;
StackPanelBottomDyn.HorizontalAlignment = HorizontalAlignment.Left;
StackPanelBottomDyn.Background = Brushes.NavajoWhite;
//tools in panel
//label
StackPanelBottomDyn.Children.Add(new Label { Content = name });
//image
StackPanelBottomDyn.Children.Add(new Image
{
Source = new BitmapImage(new Uri("http://" + icon_src)),
Stretch = Stretch.Fill,
Width = 56,
Height = 56
});
//price - textbox
StackPanelBottomDyn.Children.Add(new Label { Content = "AH price" });
StackPanelBottomDyn.Children.Add(new TextBox
{
Text = priceAH
});
StackPanelBottomDyn.Children.Add(new Label { Content = "USER price" });
StackPanelBottomDyn.Children.Add(new TextBox
{
Text = priceUSER
});
if (Top) //if true add item to top panel
{
StackPanelTop.Children.Add(StackPanelBottomDyn);
}
else //ifa false add item to bottom panel
{
StackPanelBottom.Children.Add(StackPanelBottomDyn);
}
}
}
}