forked from yuanguozheng/Xupt_lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertify.xaml.cs
369 lines (359 loc) · 15.4 KB
/
certify.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Threading;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.ObjectModel;
using Microsoft.Phone.Net.NetworkInformation;
namespace Xupt_lib
{
public partial class certify : PhoneApplicationPage
{
ObservableCollection<BookInfo> BookData = new ObservableCollection<BookInfo>();
bool isloaded = false;
public certify()
{
InitializeComponent();
books.ItemsSource = BookData;
FavData.ItemsSource = FavInfo;
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
if (DeviceNetworkInformation.IsNetworkAvailable == false)
{
new App.ToastTips("网络不可用");
return;
}
if (isloaded == true)
return;
string user = NavigationContext.QueryString["user"];
if (user == "false")
{
textBlock3.Text = "同学你好!";
}
else
{
textBlock3.Text = string.Format("欢迎 {0} {1} 同学", App.User.Cls, App.User.Name);
}
string resultStr = (App.Current as App).info;
JArray data = JArray.Parse(resultStr);
isloaded = true;
if (data.Count == 0)
{
new App.ToastTips("暂时没有任何借阅信息");
//toptips.Begin();
textBlock3.Visibility = Visibility.Visible;
textBlock4.Text = "你暂时没有任何图书借阅信息";
textBlock4.Visibility = Visibility.Visible;
return;
}
for (int i = 0; i < data.Count - 1; i++)
{
BookData.Add(new BookInfo
{
id = ((string)data[i]["id"]).Replace(" ",""),
name = ((string)data[i]["name"]).Replace("\\u003d", "="),
barcode = (string)data[i]["barcode"],
library_id = (string)data[i]["library_id"],
department_id = (string)data[i]["department_id"],
isRenew = (string)data[i]["isRenew"],
state = (string)data[i]["state"],
date = (string)data[i]["date"],
detailvis=Visibility.Collapsed
});
}
show.Begin();
textBlock3.Visibility = Visibility.Visible;
//textBlock4.Visibility = Visibility.Visible;
}
bool buttonc = false;
int tmpid = -1;
private void Button_Click(object sender, RoutedEventArgs e)
{
buttonc = true;
var s = (Button)sender;
if (((RenewInfoClass)s.Tag).Enable == "False" || ((RenewInfoClass)s.Tag).Duration < 0)
{
new App.ToastTips("此书无法续借");
return;
}
if (((RenewInfoClass)s.Tag).Duration > 5)
{
if (MessageBox.Show("距到期超过5天,确实需要续借吗?", "续借提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
return;
}
else
{
if (MessageBox.Show("确实需要续借吗?", "续借提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
return;
}
tmpid = Convert.ToInt32(((RenewInfoClass)s.Tag).id.TrimEnd());
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://222.24.63.101/library/renew?barcode={0}&department_id={1}&library_id={2}", ((RenewInfoClass)s.Tag).barcode, ((RenewInfoClass)s.Tag).depart, ((RenewInfoClass)s.Tag).lib));
req.UserAgent = "XiyouLibrary_Windows_Phone_Client";
req.BeginGetResponse(new AsyncCallback(GetRenewResponse), req);
}
private void GetRenewResponse(IAsyncResult result)
{
string responsestring = "";
try
{
HttpWebRequest request = (HttpWebRequest)result.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
Stream streamResponse = response.GetResponseStream();
using (StreamReader streamread = new StreamReader(streamResponse))
{
responsestring = streamread.ReadToEnd();
}
streamResponse.Close();
}
catch
{
Deployment.Current.Dispatcher.BeginInvoke(() => { new App.ToastTips("网络错误"); });
return;
}
if (responsestring == "ok")
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
new App.ToastTips("续借成功");
if (tmpid != -1)
{
string[] tmp = Regex.Split(BookData[tmpid - 1].date, "/");
DateTime t = DateTime.Now.Date;
t = t + TimeSpan.FromDays(15);
BookData[tmpid - 1].date = t.ToString("yyyy/MM/dd");
BookData[tmpid - 1].isRenew = "False";
BookInfo tm = BookData[tmpid - 1];
BookData.RemoveAt(tmpid - 1);
BookData.Insert(tmpid - 1, tm);
}
});
}
else
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
new App.ToastTips("续借失败");
return;
});
}
}
private void grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
if (buttonc == true)
{
buttonc = false;
return;
}
var s = (Grid)sender;
int i = Convert.ToInt32(s.Tag.ToString().TrimEnd());
if (BookData[i - 1].detailvis == Visibility.Collapsed)
{
BookData[i - 1].detailvis = Visibility.Visible;
}
else
{
BookData[i - 1].detailvis = Visibility.Collapsed;
}
}
ObservableCollection<FavList> FavInfo = new ObservableCollection<FavList>();
bool isFavloaded = false;
private void Panorama1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch (Panorama1.SelectedIndex)
{
case 1:
if (isFavloaded == true)
return;
FavInfo.Clear();
FavLoadingTip.Visibility = Visibility.Visible;
UniRequest request = new UniRequest("http://xiyoumobile.com/lib/favorite.aspx", "POST");
request.AddParams("ID", App.ID);
request.AddParams("Password", App.Password);
isFavloaded = true;
request.StartRequest(result =>
{
FavLoadingTip.Visibility = Visibility.Collapsed;
JArray data = null;
try
{
data = JArray.Parse(result);
}
catch
{
NullFavResult.Visibility = Visibility.Visible;
isFavloaded = true;
return;
}
if (data.Count == 0)
{
NullFavResult.Visibility = Visibility.Visible;
isFavloaded = true;
return;
}
foreach (var s in data)
{
FavInfo.Add(new FavList
{
ID = (string)s["ID"],
Title = (string)s["Title"],
Img = (string)s["Img"],
Sort = (string)s["Sort"]
});
}
isFavloaded = true;
});
break;
default: break;
}
}
private void DelFav_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("确实要将这本书移出你的收藏夹吗?", "温馨提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
return;
var s = (MenuItem)sender;
string id = s.Tag.ToString();
load.IsVisible = true;
UniRequest request = new UniRequest("http://xiyoumobile.com/lib/DelFav.aspx", "POST");
request.AddParams("ID", App.ID);
request.AddParams("Password", App.Password);
request.AddParams("Book", id);
request.StartRequest(result =>
{
load.IsVisible = false;
if (!result.Contains("Deleted_Successed"))
{
new App.ToastTips("移出失败");
return;
}
else
{
new App.ToastTips("移出成功");
int i;
for (i = 0; i < FavInfo.Count; i++)
{
if (FavInfo[i].ID == id)
break;
}
FavInfo.RemoveAt(i);
if (FavInfo.Count == 0)
NullFavResult.Visibility = Visibility.Visible;
return;
}
});
}
private void StackPanel_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
var s = (StackPanel)sender;
string uri = "/BookDetail.xaml?id=" + s.Tag.ToString();
this.NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}
private void Refresh_Click(object sender, EventArgs e)
{
switch (Panorama1.SelectedIndex)
{
case 0:
load.IsVisible = true;
UniRequest request = new UniRequest("http://old.xiyoumobile.com/library/login?stmp=" + DateTime.Now.ToString("yyyyMMddHHmmssfff"), "POST");
request.AddParams("userNumber", App.ID);
request.AddParams("password", App.Password);
request.StartRequest(result =>
{
load.IsVisible = false;
JArray data = JArray.Parse(result);
if (data.Count == 0)
{
new App.ToastTips("暂时没有任何借阅信息");
//toptips.Begin();
textBlock3.Visibility = Visibility.Visible;
textBlock4.Text = "你暂时没有任何图书借阅信息";
textBlock4.Visibility = Visibility.Visible;
return;
}
BookData.Clear();
for (int i = 0; i < data.Count - 1; i++)
{
BookData.Add(new BookInfo
{
id = ((string)data[i]["id"]).Replace(" ", ""),
name = ((string)data[i]["name"]).Replace("\\u003d", "="),
barcode = (string)data[i]["barcode"],
library_id = (string)data[i]["library_id"],
department_id = (string)data[i]["department_id"],
isRenew = (string)data[i]["isRenew"],
state = (string)data[i]["state"],
date = (string)data[i]["date"],
detailvis = Visibility.Collapsed
});
}
show.Begin();
textBlock3.Visibility = Visibility.Visible;
});
break;
case 1:
NullFavResult.Visibility = Visibility.Collapsed;
load.IsVisible = true;
FavLoadingTip.Visibility = Visibility.Visible;
UniRequest request1 = new UniRequest("http://xiyoumobile.com/lib/favorite.aspx", "POST");
request1.AddParams("ID", App.ID);
request1.AddParams("Password", App.Password);
isFavloaded = true;
request1.StartRequest(aresult =>
{
load.IsVisible = false;
FavLoadingTip.Visibility = Visibility.Collapsed;
JArray data = null;
try
{
data = JArray.Parse(aresult);
}
catch
{
NullFavResult.Visibility = Visibility.Visible;
isFavloaded = true;
return;
}
if (data.Count == 0)
{
NullFavResult.Visibility = Visibility.Visible;
isFavloaded = true;
return;
}
FavInfo.Clear();
foreach (var s in data)
{
FavInfo.Add(new FavList
{
ID = (string)s["ID"],
Title = (string)s["Title"],
Img = (string)s["Img"],
Sort = (string)s["Sort"]
});
}
isFavloaded = true;
});
break;
default: break;
}
}
private void GetBookDetail_Click(object sender, RoutedEventArgs e)
{
var s = (MenuItem)sender;
string uri = "/BookDetail.xaml?barcode=" + s.Tag.ToString().Replace("书号:","");
this.NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}
}
}