forked from zengpengkindle/CommonUsedFunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHome.aspx.cs
More file actions
109 lines (92 loc) · 3.42 KB
/
Copy pathHome.aspx.cs
File metadata and controls
109 lines (92 loc) · 3.42 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
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Interview1
{
public partial class Home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string userName="vtrax$16";
string pwd = "test16";
//doto no bind now
string url1 = "http://localhost/DelTraxShopRS/DelTraxShopRS.svc/logintraxid/vtrax$16/test16/0/0";
string resultStr1 = Global.get(url1);
Console.WriteLine(resultStr1);
Label3.Text = resultStr1;
//todo: get shop_id, time consuming operation
string shop_id = GetShopId(resultStr1);
Label6.Text = shop_id;
//acquire data from shop_id
string url2 = "http://localhost/DelTraxShopRS/DelTraxShopRS.svc/dealers/16309/0";
string resultStr2 = Global.get(url2);
//Label4.Text=resultStr2;
//parse dealers info
var dealers = ParseDealerInfo(resultStr2);
//bind data to table
BindDataToTable(dealers);
}
private List<Dealer> ParseDealerInfo(string jsonStr)
{
JObject mJObj = JObject.Parse(jsonStr);
string tmp1 = (string)mJObj["GetShopDealersResult"];
mJObj = JObject.Parse(tmp1);
var tmp2 = (JArray)mJObj["Data"];
List<Dealer> dealers = new List<Dealer>();
foreach (var tmp3 in tmp2)
{
Console.WriteLine(tmp3.ToString());
dealers.Add(GetDealer(tmp3.ToString()));
}
return dealers;
}
private void BindDataToTable(List<Dealer> dealers)
{
DataTable dt = new DataTable();
dt.Columns.Add("dealer_id");
dt.Columns.Add("dealer");
dt.Columns.Add("ship_vendor_id");
dt.Columns.Add("ems_make_id");
foreach (var tmpDealer in dealers)
{
DataRow NewRow = dt.NewRow();
NewRow[0] = tmpDealer.dealer_id;
NewRow[1] = tmpDealer.dealer;
NewRow[2] = tmpDealer.ship_vendor_id;
NewRow[3] = tmpDealer.ems_make_id;// tmpdeal.Text;
dt.Rows.Add(NewRow);
}
GridView1.DataSource = dt;
GridView1.DataBind();
//GridView1.DataSource = dt;
//GridViewl.DataBind();
}
private Dealer GetDealer(string jsonStr)
{
Dealer resDealer = new Dealer();
JObject mJObj = JObject.Parse(jsonStr);
resDealer.dealer_id = (int)mJObj["dealer_id"];
resDealer.dealer = mJObj["dealer"].ToString();
resDealer.ship_vendor_id = (int)mJObj["ship_vendor_id"];
resDealer.ems_make_id = (int)mJObj["ems_make_id"];
return resDealer;
}
private string GetShopId(string jsonStr)
{
JObject mJObj = JObject.Parse(jsonStr);
string tmp1 = (string)mJObj["VerifyLoginTraxIdResult"];
mJObj = JObject.Parse(tmp1);
var tmp2 = mJObj["Data"][0];
var tmp3 = tmp2["shop_id"];
return (string)tmp3;
}
}
}