Advertisement
JeremyProxy

RegisterValidation

Dec 28th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.04 KB | None | 0 0
  1.  
  2. private async void btnNext_Clicked(object sender, EventArgs e)
  3. {
  4. try
  5. {
  6. HttpClient client = new HttpClient();
  7. var response = await client.GetStringAsync("http://ipoladroid01-001-site1.btempurl.com/Restserver/index.php/users/view");
  8. var user = JsonConvert.DeserializeObject<List<Users>>(response);
  9.  
  10. for (int i = 0; i < user.Count; i++)
  11. {
  12. if (entUsername.Text == user[i].mem_acc_username)
  13. {
  14. _continue = false;
  15. DisplayAlert("Notice", "This username is already used please choose another.", "OK");
  16.  
  17. entUsername.Focus();
  18.  
  19.  
  20. }
  21. else
  22. {
  23. _continue = true;
  24. }
  25.  
  26.  
  27. }
  28.  
  29.  
  30. if (_continue == true)
  31. {
  32.  
  33. if (entUsername.Text == null || entUsername.Text == "")
  34. {
  35. DisplayAlert("Notice", "Please input your desire username.", "OK");
  36. }
  37. else
  38. {
  39. if (entUsername.Text.Length < 8)
  40. {
  41. DisplayAlert("Notice", "Username must include 8-32 characters", "OK");
  42. }
  43. else
  44. {
  45. if (entPassword.Text == null || entPassword.Text == "")
  46. {
  47. DisplayAlert("Notice", "Please input your desire password.", "OK");
  48. }
  49. else
  50. {
  51. if (entPassword.Text.Length < 8)
  52. {
  53. DisplayAlert("Notice", "Password must include 8-45 characters", "OK");
  54. }
  55. else
  56. {
  57. if (entFname.Text == null || entFname.Text == "")
  58. {
  59. DisplayAlert("Notice", "Please input your Firstname.", "OK");
  60. }
  61. else
  62. {
  63. if (entLname.Text == null || entLname.Text == "")
  64. {
  65. DisplayAlert("Notice", "Please input your Password", "OK");
  66. }
  67. else
  68. {
  69. tempusername = entUsername.Text;
  70. temppassword = entPassword.Text;
  71. tempfname = entFname.Text;
  72. templname = entLname.Text;
  73.  
  74. var u = new Users();
  75. u.mem_acc_username = tempusername;
  76. u.mem_acc_password = temppassword;
  77.  
  78. u.mem_fname = tempfname;
  79. u.mem_lname = templname;
  80.  
  81. var page1 = new Registration2(u);
  82.  
  83.  
  84. Navigation.PushAsync(page1);
  85. _continue = false;
  86. }
  87. }
  88. }
  89. }
  90. }
  91.  
  92. }
  93.  
  94. }
  95. else
  96. {
  97. DisplayAlert("Notice", "Something went wrong please try again.", "OK");
  98.  
  99. }
  100. }
  101. catch(Exception ex)
  102. {
  103. DisplayAlert("Network error", "Please check your internet connection and try again.", "OK");
  104. }
  105.  
  106.  
  107.  
  108. }
  109.  
  110.  
  111. ///// Reg 2
  112.  
  113.  
  114.  
  115. private async void btnRegister_Clicked(object sender, EventArgs e)
  116. {
  117.  
  118. if (entAddress.Text == null | entAddress.Text == "")
  119. {
  120. DisplayAlert("Notice", "Please fill-up your current address.", "OK");
  121. entAddress.Focus();
  122. }
  123. else
  124. {
  125. if (entContact.Text == null || entContact.Text == "")
  126.  
  127. {
  128.  
  129. DisplayAlert("Notice", "Please input your phone number", "OK");
  130. }
  131. else
  132. {
  133. if (entContact.Text.Length < 11 )
  134. {
  135. DisplayAlert("Notice", "Enter a valid phone number", "OK");
  136. }
  137. else
  138. {
  139. Users users = new Users()
  140. {
  141.  
  142. mem_acc_username = tempusername,
  143. mem_acc_password = temppassword,
  144. mem_fname = tempfname,
  145. mem_lname = templname,
  146. mem_address = entAddress.Text,
  147. mem_mobile_no = entContact.Text,
  148. mem_bday = dateselected
  149.  
  150.  
  151. };
  152.  
  153. var page2 = new Registration3(users);
  154.  
  155.  
  156. Navigation.PushAsync(page2);
  157.  
  158. }
  159.  
  160. }
  161. }
  162.  
  163. }
  164.  
  165.  
  166.  
  167. //// Reg 3
  168.  
  169.  
  170. private async Task btnRegister_Clicked(object sender, EventArgs e)
  171. {
  172.  
  173. try
  174. {
  175. if (entBirth.SelectedIndex < 0)
  176. {
  177. DisplayAlert("Notice", "Please select a Security Question", "OK");
  178. }
  179. else
  180. {
  181. if(entAnswer.Text == null || entAnswer.Text == "")
  182. {
  183. DisplayAlert("Notice", "Please input your answer", "OK");
  184. entAnswer.Focus();
  185. }
  186. else
  187. {
  188. if(ent5digit.Text == null || ent5digit.Text == "")
  189. {
  190. DisplayAlert("Notice", "Please input your membership code, if you don't have membership code feel free to contact us.", "OK");
  191. }
  192. else
  193. {
  194. btnRegister.IsEnabled = false;
  195. Send5Digit sendthis = new Send5Digit()
  196. {
  197. membership_code = ent5digit.Text
  198. };
  199.  
  200.  
  201.  
  202. var json1 = JsonConvert.SerializeObject(sendthis);
  203.  
  204. var content1 = new StringContent(json1, Encoding.UTF8, "application/json");
  205.  
  206.  
  207. HttpClient client1 = new HttpClient();
  208.  
  209. var result1 = await client1.PostAsync("http://ipoladroid01-001-site1.btempurl.com/Restserver/index.php/customer/search_codes", content1);
  210. // var result1 = await client1.PostAsync("http://192.168.43.178/Restserver/index.php/customer/search_codes", content1);
  211. response = await result1.Content.ReadAsStringAsync();
  212. // await DisplayAlert("Debug", response, "OK");
  213. if (response == "[]")
  214. {
  215. await DisplayAlert("Notice", "Invalid Code", "OK");
  216. btnRegister.IsEnabled = true;
  217. }
  218. else
  219. {
  220. var validator = JsonConvert.DeserializeObject<List<Send5Digit>>(response);
  221. var memcode = validator[0].membership_code;
  222. var code = validator[0].code_number;
  223. var stat = validator[0].code_status;
  224.  
  225.  
  226. await DisplayAlert("Debug", memcode + code + stat, "OK");
  227.  
  228.  
  229. Send5Digit codez = new Send5Digit()
  230. {
  231. code_number = code
  232. };
  233.  
  234.  
  235. var json2 = JsonConvert.SerializeObject(codez);
  236.  
  237. var content2 = new StringContent(json2, Encoding.UTF8, "application/json");
  238.  
  239.  
  240. HttpClient client2 = new HttpClient();
  241.  
  242. var result2 = await client1.PostAsync("http://ipoladroid01-001-site1.btempurl.com/Restserver/index.php/customer/update_registered_codes", content2);
  243. // var result2 = await client1.PostAsync("http://192.168.43.178/Restserver/index.php/customer/update_registered_codes", content2);
  244. if (result2.StatusCode == System.Net.HttpStatusCode.Created)
  245. {
  246. Users users = new Users()
  247. {
  248.  
  249. mem_acc_username = tempmem_acc_username,
  250. mem_acc_password = tempmem_acc_password,
  251. mem_question = temp,
  252. mem_answer = entAnswer.Text,
  253. mem_fname = tempmem_fname,
  254. mem_lname = tempmem_lname,
  255. mem_address = tempmem_address,
  256. mem_mobile_no = tempmem_mobile,
  257. mem_bday = tempmem_bday,
  258. };
  259.  
  260.  
  261.  
  262. var json = JsonConvert.SerializeObject(users);
  263.  
  264.  
  265.  
  266. var content = new StringContent(json, Encoding.UTF8, "application/json");
  267.  
  268.  
  269. HttpClient client = new HttpClient();
  270.  
  271. var result = await client.PostAsync("http://ipoladroid01-001-site1.btempurl.com/Restserver/index.php/users/insert", content);
  272.  
  273.  
  274. // var result = await client.PostAsync("http://192.168.43.178/Restserver/index.php/users/insert", content);
  275.  
  276.  
  277. if (result.StatusCode == System.Net.HttpStatusCode.Created)
  278. {
  279. await DisplayAlert("Success :", "Account Registered", "OK");
  280. btnRegister.IsEnabled = true;
  281. Navigation.PushAsync(new MainPage());
  282. }
  283. else
  284. {
  285. await DisplayAlert("Failed", result.ToString(), "OK");
  286.  
  287. btnRegister.IsEnabled = true;
  288. }
  289. }
  290.  
  291.  
  292. else
  293. {
  294. await DisplayAlert("Failed", result2.ToString(), "OK");
  295.  
  296.  
  297. }
  298.  
  299.  
  300. }
  301. }
  302. }
  303. }
  304.  
  305.  
  306. }
  307. catch (Exception ex)
  308. {
  309. DisplayAlert("Hmmmm", "Something went wrong please try again later.", "OK");
  310. }
  311.  
  312. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement