Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.98 KB | None | 0 0
  1. public partial class frmSignUp : Form
  2. {
  3. playersignup[] players = new playersignup[20];
  4. public frmSignUp()
  5. {
  6. InitializeComponent();
  7.  
  8. }
  9.  
  10. private void lblUsername_Click(object sender, EventArgs e)
  11. {
  12.  
  13. }
  14.  
  15. private void frmSignUp_Load(object sender, EventArgs e)
  16. {
  17.  
  18.  
  19.  
  20. }
  21.  
  22. private void btnConfirm_Click(object sender, EventArgs e)
  23. {
  24.  
  25. bool valid = false;
  26. bool existinguser = false;
  27.  
  28. playersignup player = new playersignup();
  29. int size = Ulitityclass.ReadFromFile(ref players);
  30. player.Firstname = txtEnterFirstName.Text;
  31. player.Secondname = txtEnterSecondName.Text;
  32. player.ComboBox = cbgender.Text;
  33. player.Dateofbirth = dtpDOB.Value;
  34. player.Email = txtemail.Text;
  35. player.Password = txtPassword.Text;
  36. player.Reenterpassword = txtReenterPassword.Text;
  37. player.Username = txtUserName.Text;
  38. if ((player.Username != null) && (player.Firstname != null) && (player.Secondname != null) && (player.ComboBox != null) && (player.Dateofbirth != null) && (player.Email != null) && (player.Password != null) && (player.Reenterpassword != null))
  39. {
  40. valid = true;
  41. existinguser = Ulitityclass.UserExists(players, player.Username, player.Password, player.Email);
  42.  
  43. }
  44. if ((valid == true) && (existinguser == false))
  45. {
  46.  
  47. players[size] = player;
  48. //// for (int x = 0; x < players.Length; x++)
  49. // {
  50.  
  51. // players[x] = new playersignup(txtEnterFirstName.Text, txtEnterSecondName.Text, dtpDOB.Value, txtemail.Text, txtUserName.Text, txtPassword.Text, txtReenterPassword.Text, cbgender.Text);
  52. size++;
  53. Ulitityclass.WriteToFile(players, size);
  54. // }
  55.  
  56.  
  57. }
  58.  
  59.  
  60. int errorcounter = 0;
  61. playersignup myplayersignup = new playersignup();
  62.  
  63.  
  64. try//try catch blocks used to output error message if the data is not valid. in the try block it will test the data eg first name
  65. {
  66. myplayersignup.Firstname = (txtEnterFirstName.Text);//will check in the textbox if its valid
  67. }
  68. catch (ExceptionClass ex)//in the catch part if their is indeed a invalid input which is checked in the set part of the property, it will be invalid if the method(which sets the validation) returns false. it will then be thrown from there and then caught here in the apporatite catch block
  69. {
  70.  
  71. P1.SetError(txtEnterFirstName, ex.Errormessage);// error provider will output message set in the approiate method of each data
  72. errorcounter++;//this will be used to output either success sign up(if=0) or unsuccessful sign up if higher
  73. }
  74.  
  75. try
  76. {
  77. myplayersignup.Secondname = (txtEnterSecondName.Text);
  78. }
  79. catch (ExceptionClass ex)
  80. {
  81. P1.SetError(txtEnterSecondName, ex.Errormessage);
  82. errorcounter++;
  83. }
  84. try
  85. {
  86. myplayersignup.Dateofbirth = (dtpDOB.Value);
  87. }
  88. catch (ExceptionClass ex)
  89. {
  90. P1.SetError(dtpDOB, ex.Errormessage);
  91. errorcounter++;
  92. }
  93. try
  94. {
  95. myplayersignup.Email = (txtemail.Text);
  96.  
  97. }
  98. catch (ExceptionClass ex)
  99. {
  100. P1.SetError(txtemail, ex.Errormessage);
  101. errorcounter++;
  102. }
  103. try
  104. {
  105. myplayersignup.Username = (txtUserName.Text);
  106.  
  107. }
  108. catch (ExceptionClass ex)
  109. {
  110. P1.SetError(txtUserName, ex.Errormessage);
  111. errorcounter++;
  112. }
  113. try
  114. {
  115. myplayersignup.Password = (txtPassword.Text);
  116. }
  117. catch (ExceptionClass ex)
  118. {
  119. P1.SetError(txtPassword, ex.Errormessage);
  120. errorcounter++;
  121. }
  122. try
  123. {
  124. myplayersignup.Reenterpassword = (txtReenterPassword.Text);
  125. }
  126. catch (ExceptionClass ex)
  127. {
  128. P1.SetError(txtReenterPassword, ex.Errormessage);
  129. errorcounter++;
  130. }
  131. try
  132. {
  133. myplayersignup.ComboBox = (cbgender.Text);
  134.  
  135. }
  136. catch (ExceptionClass ex)
  137. {
  138. P1.SetError(cbgender, ex.Errormessage);
  139. errorcounter++;
  140. }
  141.  
  142. {
  143. if (errorcounter == 0)//this will happen if all data entered is valid
  144. {
  145.  
  146. MessageBox.Show("Successful Sign Up");//makes user aware with outputting that the sign up is successful
  147. P1.Clear();//clears error provider as for example if user first time enter some data wrong their will be error providers and after they successful enter the data the error provider will be cleared
  148.  
  149.  
  150. }
  151. else//if the user gets at least one invalid data input when signing up this will be executed
  152. {
  153.  
  154. MessageBox.Show("Unsucessful Sign Up");//makes user aware that they have at least entered once piece of invalid data
  155.  
  156. }
  157. }
  158. }
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. private void lblSecondName_Click(object sender, EventArgs e)
  166. {
  167.  
  168. }
  169.  
  170. private void dtpDOB_ValueChanged(object sender, EventArgs e)
  171. {
  172.  
  173. }
  174.  
  175. private void txtEnterFirstName_TextChanged(object sender, EventArgs e)
  176. {
  177.  
  178. }
  179.  
  180. private void txtEnterSecondName_TextChanged(object sender, EventArgs e)
  181. {
  182.  
  183. }
  184.  
  185. private void cbgender_SelectedIndexChanged(object sender, EventArgs e)
  186. {
  187.  
  188. }
  189.  
  190. private void txtemail_TextChanged(object sender, EventArgs e)
  191. {
  192.  
  193. }
  194.  
  195. private void txtUserName_TextChanged(object sender, EventArgs e)
  196. {
  197. }
  198.  
  199. private void txtPassword_TextChanged(object sender, EventArgs e)
  200. {
  201.  
  202. }
  203.  
  204. private void txtReenterPassword_TextChanged(object sender, EventArgs e)
  205. {
  206.  
  207. }
  208.  
  209. private void btnlogin_Click(object sender, EventArgs e)
  210. {
  211. long pos = -1;
  212. bool found = false;
  213. players = new playersignup[20];
  214. playersignup playerdetails = new playersignup();
  215. Stream sr;
  216. string requsername;
  217. string reqpassword;
  218. reqpassword = txtPassword.Text;
  219. requsername = txtUserName.Text;
  220. sr = File.Open("PlayerDetails.bin", FileMode.Open, FileAccess.ReadWrite);
  221. BinaryFormatter bf = new BinaryFormatter();
  222. try
  223. {
  224. while (sr.Position < sr.Length)
  225. {
  226. pos = sr.Position;
  227. playerdetails = (playersignup)bf.Deserialize(sr);
  228.  
  229. if ((playerdetails.Username.Trim().CompareTo(requsername.Trim()) == 0) && ((playerdetails.Password.Trim().CompareTo(reqpassword.Trim()) == 0)))
  230. {
  231. found = true;
  232. sr.Seek(pos, SeekOrigin.Begin);
  233.  
  234. bf.Serialize(sr, playerdetails);
  235. MessageBox.Show("Sucessful Match");
  236.  
  237. Frmmainmenu mainmenu = new Frmmainmenu();
  238. this.Hide();
  239. mainmenu.ShowDialog();
  240. this.Close();
  241. }
  242. for (int x = 0; x < players.Length; x++)
  243. {
  244. if ((txtusernamelogin.Text == players[x].Username) && (txtpasswordlogin.Text == players[x].Password))
  245. {
  246. found = true;
  247. sr.Seek(pos, SeekOrigin.Begin);
  248.  
  249. bf.Serialize(sr, playerdetails);
  250.  
  251. MessageBox.Show("Successful login");
  252. Frmmainmenu mainmenu = new Frmmainmenu();
  253. this.Hide();
  254. mainmenu.ShowDialog();
  255. this.Close();
  256. }
  257. else
  258. {
  259. MessageBox.Show("Unsuccessful match");
  260. }
  261. }
  262. }
  263. sr.Close();
  264.  
  265. }
  266. catch (Exception g)
  267. {
  268.  
  269.  
  270. }
  271. }
  272. }
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement