Advertisement
tamkuipap

Untitled

Feb 3rd, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using RestSharp;
  11. using System.IO;
  12. using System.Text.RegularExpressions;
  13. using System.Diagnostics;
  14. using Newtonsoft.Json;
  15. using Newtonsoft.Json.Serialization;
  16. using Newtonsoft.Json.Converters;
  17.  
  18.  
  19. namespace WindowsFormsApplication12
  20. {
  21. public partial class Form1 : Form
  22. {
  23. public Form1()
  24. {
  25. InitializeComponent();
  26. }
  27. public string JData = "";
  28. public void GetData(string CodeHD)
  29. {
  30. string url = "https://services.giaohangtietkiem.vn/services/shipment/v2/partner_id:" + CodeHD;
  31. label1.Text = "Code Hóa Đơn : " + CodeHD;
  32. label2.Text = "url GET : " + url;
  33. var client = new RestClient(url);
  34. client.Timeout = -1;
  35. var request = new RestRequest(Method.GET);
  36. request.AddHeader("Token", "1e1742c4b2e405cbffA70406c0fA9f385EB49151");
  37. request.AddHeader("Content-Type", "application/json");
  38. IRestResponse response = client.Execute(request);
  39.  
  40. JData = response.Content; //Data GET được
  41. }
  42.  
  43.  
  44. private void button1_Click_1(object sender, EventArgs e)
  45. {
  46. //Console.OutputEncoding = Encoding.UTF8; //Gõ tiếng việt, lưu lại cho nhớ
  47. #region Get Data
  48.  
  49. string CodeHD = textBox1.Text.ToString();
  50. GetData(CodeHD);
  51.  
  52. if (JData.Contains("false") != true)
  53. {
  54. Gstatus JsonData = JsonConvert.DeserializeObject<Gstatus>(JData); //Chuyển Json Data get được vào lớp
  55.  
  56. textBox2.Clear(); //clear box và show cách thông tin đơn hàng
  57. textBox2.AppendText("Mã GHTK : " + JsonData.order.label_id);
  58. textBox2.AppendText(Environment.NewLine);
  59. textBox2.AppendText("Mã Hóa Đơn Kiotviet : " + JsonData.order.partner_id);
  60. textBox2.AppendText(Environment.NewLine);
  61. textBox2.AppendText("Tên Khách Hàng : " + JsonData.order.customer_fullname);
  62. textBox2.AppendText(Environment.NewLine);
  63. textBox2.AppendText("Số Điện Thoại : " + JsonData.order.customer_tel);
  64. textBox2.AppendText(Environment.NewLine);
  65. textBox2.AppendText("Địa Chỉ : " + JsonData.order.address);
  66. textBox2.AppendText(Environment.NewLine);
  67. textBox2.AppendText("COD Thu hộ : " + JsonData.order.pick_money);
  68. textBox2.AppendText(Environment.NewLine);
  69. textBox2.AppendText("Khối Lượng ĐH : " + JsonData.order.weight);
  70. textBox2.AppendText(Environment.NewLine);
  71. textBox2.AppendText("Trạng Thái ĐH : " + JsonData.order.status_text);
  72. textBox2.AppendText(Environment.NewLine);
  73. textBox2.AppendText("Phí Ship : " + JsonData.order.ship_money);
  74. }
  75.  
  76. else
  77. {
  78. for (int i = 5; i > 1; i--)
  79. {
  80. CodeHD = "https://services.giaohangtietkiem.vn/services/shipment/v2/partner_id:" + ".0" + i;
  81. GetData(CodeHD);
  82. if (JData.Contains("false") == true)
  83. {
  84. JData = "hóa đơn " + CodeHD + " không tồn tại trên hệ thống giao hàng tiết kiệm";
  85. textBox2.Text = JData;
  86. }
  87. else
  88. {
  89. Gstatus JsonData = JsonConvert.DeserializeObject<Gstatus>(JData); //Chuyển Json Data get được vào lớp
  90.  
  91. textBox2.Clear(); //clear box và show cách thông tin đơn hàng
  92. textBox2.AppendText("Mã GHTK : " + JsonData.order.label_id);
  93. textBox2.AppendText(Environment.NewLine);
  94. textBox2.AppendText("Mã Hóa Đơn Kiotviet : " + JsonData.order.partner_id);
  95. textBox2.AppendText(Environment.NewLine);
  96. textBox2.AppendText("Tên Khách Hàng : " + JsonData.order.customer_fullname);
  97. textBox2.AppendText(Environment.NewLine);
  98. textBox2.AppendText("Số Điện Thoại : " + JsonData.order.customer_tel);
  99. textBox2.AppendText(Environment.NewLine);
  100. textBox2.AppendText("Địa Chỉ : " + JsonData.order.address);
  101. textBox2.AppendText(Environment.NewLine);
  102. textBox2.AppendText("COD Thu hộ : " + JsonData.order.pick_money);
  103. textBox2.AppendText(Environment.NewLine);
  104. textBox2.AppendText("Khối Lượng ĐH : " + JsonData.order.weight);
  105. textBox2.AppendText(Environment.NewLine);
  106. textBox2.AppendText("Trạng Thái ĐH : " + JsonData.order.status_text);
  107. textBox2.AppendText(Environment.NewLine);
  108. textBox2.AppendText("Phí Ship : " + JsonData.order.ship_money);
  109. }
  110. }
  111.  
  112. }
  113.  
  114.  
  115.  
  116. //if ( JData.Contains("false") == true ) //Xét tồn tại của đợn trên hệ thống GHTK
  117. //{
  118. // JData = "hóa đơn " + CodeHD + " không tồn tại trên hệ thống giao hàng tiết kiệm";
  119. // textBox2.Text = JData;
  120. //}
  121.  
  122. //else
  123. //{
  124.  
  125. // Gstatus JsonData = JsonConvert.DeserializeObject<Gstatus>(JData); //Chuyển Json Data get được vào lớp
  126.  
  127. // textBox2.Clear(); //clear box và show cách thông tin đơn hàng
  128. // textBox2.AppendText("Mã GHTK : " + JsonData.order.label_id);
  129. // textBox2.AppendText(Environment.NewLine);
  130. // textBox2.AppendText("Mã Hóa Đơn Kiotviet : " + JsonData.order.partner_id);
  131. // textBox2.AppendText(Environment.NewLine);
  132. // textBox2.AppendText("Tên Khách Hàng : " + JsonData.order.customer_fullname);
  133. // textBox2.AppendText(Environment.NewLine);
  134. // textBox2.AppendText("Số Điện Thoại : " + JsonData.order.customer_tel);
  135. // textBox2.AppendText(Environment.NewLine);
  136. // textBox2.AppendText("Địa Chỉ : " + JsonData.order.address);
  137. // textBox2.AppendText(Environment.NewLine);
  138. // textBox2.AppendText("COD Thu hộ : " + JsonData.order.pick_money);
  139. // textBox2.AppendText(Environment.NewLine);
  140. // textBox2.AppendText("Khối Lượng ĐH : " + JsonData.order.weight);
  141. // textBox2.AppendText(Environment.NewLine);
  142. // textBox2.AppendText("Trạng Thái ĐH : " + JsonData.order.status_text);
  143. // textBox2.AppendText(Environment.NewLine);
  144. // textBox2.AppendText("Phí Ship : " + JsonData.order.ship_money);
  145.  
  146. //TextboxShow(JsonData.order.address);
  147. //textBox2.Text = (JsonData.order.status_text) + Environment.NewLine;
  148. //textBox2.SelectionStart = textBox2.TextLength;
  149. //textBox2.ScrollToCaret();
  150. //textBox2.AppendText(JsonData.order.partner_id);
  151.  
  152.  
  153. //textBox2.Lines.Add(JsonData.order.status_text);
  154. //textBox2.Lines.Add(JsonData.order.partner_id);
  155. //string json = JsonConvert.SerializeObject(JData);
  156. //Ghtk account = JsonConvert.DeserializeObject<Ghtk>(json);
  157. //txtDebugOutput.Text = jPerson.ToString;
  158. //debugOutput("Here :" + jPerson.ToString());
  159. //MessageBox.Show(jPerson.ToString);
  160.  
  161. }
  162.  
  163.  
  164. //string ConvJson = JsonConvert.DeserializeObject<dynamic>(JData);
  165.  
  166.  
  167. //File.WriteAllText("data.html", response.Content);
  168. //Process.Start("data.html");
  169. #endregion
  170. }
  171.  
  172. //public class TextboxShow(string strShow)
  173. //{
  174. //textBox2.Text = (strShow) + Environment.NewLine;
  175. //textBox2.SelectionStart = textBox2.TextLength;
  176. //textBox2.ScrollToCaret();
  177. //}
  178.  
  179.  
  180.  
  181.  
  182.  
  183. public class Gstatus
  184. {
  185. public string success { get; set; }
  186. public string message { get; set; }
  187. public Gorder order { get; set; }
  188. }
  189.  
  190. public class Gorder
  191. {
  192. public string label_id { get; set; }
  193. public string partner_id { get; set; }
  194. public string status { get; set; }
  195. public string value { get; set; }
  196. public string insurance { get; set; }
  197. public string ship_money { get; set; }
  198. public string storage_day { get; set; }
  199. public string created { get; set; }
  200. public string pick_money { get; set; }
  201. public string is_freeship { get; set; }
  202. public string modified { get; set; }
  203. public string customer_fullname { get; set; }
  204. public string customer_tel { get; set; }
  205. public string message { get; set; }
  206. public string pick_date { get; set; }
  207. public string deliver_date { get; set; }
  208. public string address { get; set; }
  209. public string weight { get; set; }
  210. public string status_text { get; set; }
  211. }
  212.  
  213. class HoaDon
  214. {
  215. public string label_id { get; set; }
  216. public string partner_id { get; set; }
  217. public string status { get; set; }
  218. public string value { get; set; }
  219. public string insurance { get; set; }
  220. public string ship_money { get; set; }
  221. public string storage_day { get; set; }
  222. public string created { get; set; }
  223. public string pick_money { get; set; }
  224. public string is_freeship { get; set; }
  225. public string modified { get; set; }
  226. public string customer_fullname { get; set; }
  227. public string customer_tel { get; set; }
  228. public string pick_date { get; set; }
  229. public string deliver_date { get; set; }
  230. public string address { get; set; }
  231. public string weight { get; set; }
  232. public string status_text { get; set; }
  233. }
  234.  
  235. //private void button2_Click(object sender, EventArgs e)
  236. //{
  237. //string KcodeHD = textBox1.Text.ToString();
  238. //string Kurl = "https://services.giaohangtietkiem.vn/services/shipment/v2/partner_id:" + KcodeHD;
  239. //label1.Text = "Code Hóa Đơn : " + KcodeHD;
  240. //label2.Text = "url GET : " + Kurl;
  241.  
  242. //var client = new RestClient(Kurl);
  243. //client.Timeout = -1;
  244.  
  245. //var request = new RestRequest(Method.GET);
  246. //request.AddHeader("Token", "1e1742c4b2e405cbffA70406c0fA9f385EB49151");
  247. //request.AddHeader("Content-Type", "application/json");
  248.  
  249. //IRestResponse response = client.Execute(request);
  250.  
  251. //string JData = response.Content; //Data GET được
  252.  
  253.  
  254.  
  255.  
  256. }
  257.  
  258.  
  259.  
  260.  
  261. //#region json function
  262. //private void deserialiseJSON(string strJSON)
  263. //{
  264. // try
  265. // {
  266. // var jPerson = JsonConvert.DeserializeObject<dynamic>(strJSON);
  267. // debugOutput("Here :" + jPerson.ToString());
  268.  
  269. // //debugOutput("Fisrtname : " + jPerson.firstname);
  270. // //debugOutput("Lastname : " + jPerson.lastname);
  271. // //debugOutput("Age : " + jPerson.age);
  272. // //debugOutput("Still Alive : " + jPerson.isalive);
  273. // }
  274. // catch (Exception ex)
  275. // {
  276. // debugOutput("Problem : " + ex.Message.ToString());
  277. // }
  278. //}
  279.  
  280.  
  281. //#endregion
  282.  
  283.  
  284. //#region Debug Output
  285. //private void debugOutput(string strDebugText)
  286. //{
  287. // try
  288. // {
  289. // System.Diagnostics.Debug.WriteLine(strDebugText + Environment.NewLine);
  290. // txtDebugOutput.Text = txtDebugOutput + strDebugText + Environment.NewLine;
  291. // txtDebugOutput.SelectionStart = txtDebugOutput.TextLength;
  292. // txtDebugOutput.ScrollToCaret();
  293. // }
  294. // catch (Exception ex)
  295. // {
  296. // System.Diagnostics.Debug.WriteLine(ex.Message.ToString() + Environment.NewLine);
  297. // }
  298. //}
  299. //#endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement