ShowCardInformation.cs
6.21 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using MoyaAdminLib;
using MoyaAdminUI.MoyaAPI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
namespace MoyaAdminUI
{
public partial class ShowCardInformation : Form
{
public static string CARD_PREFIX = "277";
public static string TICKET_PREFIX = "279";
public static string CARD_PLACE = "cardplace";
public ShowCardInformation()
{
InitializeComponent();
}
private void barcodeTimer_Tick(object sender, EventArgs e)
{
barcodeTimer.Stop();
int id = 0;
string ret = "";
RestClient client = new RestClient(Properties.Settings.Default.ApiURL);
if (parseCardId(barcodeTextBox.Text, out id))
ret = client.MakeRequest("card/Get/" + id);
else if (parseEventUserId(barcodeTextBox.Text, out id))
ret = client.MakeRequest("user/card/" + id);
var ser = new JavaScriptSerializer();
Card card = ser.Deserialize<Card>(ret);
if (card != null)
{
nameTextBox.Text = card.wholeName;
nickTextBox.Text = card.username;
cardTemplateTextBox.Text = card.cardTemplate;
cardStateTextBox.Text = card.state;
pictureBox1.ImageLocation = RestClient.GetRequestURL(Properties.Settings.Default.ApiURL, "card/GetImage/" + card.cardId);
if (card.state == Card.CARD_STATE_PRINTED)
{
ret = "";
client = new RestClient(Properties.Settings.Default.ApiURL);
try
{
ret = client.MakeRequest("meta/v1/printedcard/" + card.cardId + "/card-filing");
}
catch (ApplicationException ex)
{
if (!ex.Message.Contains("HTTP NoContent"))
return;
}
if (ret != null && ret != "")
{
MetaData data = getValue(ret);
int bookNumber = 0;
int pageNumber = 0;
int slotNumber = 0;
getCardPlace(data, out bookNumber, out pageNumber, out slotNumber);
if (bookNumber > 0)
bookNumericUpDown.Value = bookNumber;
if (pageNumber > 0)
pageNumericUpDown.Value = pageNumber;
if (slotNumber > 0)
slotNumericUpDown.Value = slotNumber;
}
}
}
barcodeTextBox.Text = "";
}
public void getCardPlace(MetaData data, out int bookNumber, out int pageNumber, out int slotNumber)
{
bookNumber = 0;
pageNumber = 0;
slotNumber = 0;
if (data != null)
{
if (data.key == CARD_PLACE)
{
if (data.value != null && data.value != "")
{
string[] fields = data.value.Split(new string[] { "." }, StringSplitOptions.None);
if (fields.Length > 2)
{
if (fields.Length == 3)
{
int.TryParse(fields[0], out bookNumber);
int.TryParse(fields[1], out pageNumber);
int.TryParse(fields[2], out slotNumber);
}
}
}
}
}
}
private MetaData getValue(string ret)
{
MetaData data = null;
if (ret != null && ret != "")
{
ret = ret.Trim();
if (ret.StartsWith("{") && ret.EndsWith("}"))
{
ret = ret.Replace("{", "");
ret = ret.Replace("}", "");
if (ret.Contains(":"))
{
data = new MetaData();
string[] fields = ret.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
if (fields.Length == 2)
{
if (fields[0].StartsWith("\""))
fields[0] = fields[0].Substring(1, fields[0].Length -1);
if (fields[0].EndsWith("\""))
fields[0] = fields[0].Substring(0, fields[0].Length - 1);
data.key = fields[0];
if (fields[1].StartsWith("\""))
fields[1] = fields[1].Substring(1, fields[1].Length - 1);
if (fields[1].EndsWith("\""))
fields[1] = fields[1].Substring(0, fields[1].Length - 1);
data.value = fields[1];
}
}
}
}
return data;
}
private bool parseCardId(string data, out int id)
{
id = 0;
if (data.Length == 13 && data.Substring(0, 3) == CARD_PREFIX)
{
int.TryParse(data.Substring(3, 9), out id);
if (id > 0)
return true;
}
return false;
}
private bool parseEventUserId(string data, out int id)
{
id = 0;
if (data.Length == 13 && data.Substring(0, 3) == TICKET_PREFIX)
{
int.TryParse(data.Substring(3, 9), out id);
if (id > 0)
return true;
}
return false;
}
private void barcodeTextBox_TextChanged(object sender, EventArgs e)
{
if (barcodeTextBox.Text != "")
barcodeTimer.Start();
}
}
}