Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class frmSignUp : Form
- {
- playersignup[] players = new playersignup[20];
- public frmSignUp()
- {
- InitializeComponent();
- }
- private void lblUsername_Click(object sender, EventArgs e)
- {
- }
- private void frmSignUp_Load(object sender, EventArgs e)
- {
- }
- private void btnConfirm_Click(object sender, EventArgs e)
- {
- bool valid = false;
- bool existinguser = false;
- playersignup player = new playersignup();
- int size = Ulitityclass.ReadFromFile(ref players);
- player.Firstname = txtEnterFirstName.Text;
- player.Secondname = txtEnterSecondName.Text;
- player.ComboBox = cbgender.Text;
- player.Dateofbirth = dtpDOB.Value;
- player.Email = txtemail.Text;
- player.Password = txtPassword.Text;
- player.Reenterpassword = txtReenterPassword.Text;
- player.Username = txtUserName.Text;
- 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))
- {
- valid = true;
- existinguser = Ulitityclass.UserExists(players, player.Username, player.Password, player.Email);
- }
- if ((valid == true) && (existinguser == false))
- {
- players[size] = player;
- //// for (int x = 0; x < players.Length; x++)
- // {
- // players[x] = new playersignup(txtEnterFirstName.Text, txtEnterSecondName.Text, dtpDOB.Value, txtemail.Text, txtUserName.Text, txtPassword.Text, txtReenterPassword.Text, cbgender.Text);
- size++;
- Ulitityclass.WriteToFile(players, size);
- // }
- }
- int errorcounter = 0;
- playersignup myplayersignup = new playersignup();
- 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
- {
- myplayersignup.Firstname = (txtEnterFirstName.Text);//will check in the textbox if its valid
- }
- 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
- {
- P1.SetError(txtEnterFirstName, ex.Errormessage);// error provider will output message set in the approiate method of each data
- errorcounter++;//this will be used to output either success sign up(if=0) or unsuccessful sign up if higher
- }
- try
- {
- myplayersignup.Secondname = (txtEnterSecondName.Text);
- }
- catch (ExceptionClass ex)
- {
- P1.SetError(txtEnterSecondName, ex.Errormessage);
- errorcounter++;
- }
- try
- {
- myplayersignup.Dateofbirth = (dtpDOB.Value);
- }
- catch (ExceptionClass ex)
- {
- P1.SetError(dtpDOB, ex.Errormessage);
- errorcounter++;
- }
- try
- {
- myplayersignup.Email = (txtemail.Text);
- }
- catch (ExceptionClass ex)
- {
- P1.SetError(txtemail, ex.Errormessage);
- errorcounter++;
- }
- try
- {
- myplayersignup.Username = (txtUserName.Text);
- }
- catch (ExceptionClass ex)
- {
- P1.SetError(txtUserName, ex.Errormessage);
- errorcounter++;
- }
- try
- {
- myplayersignup.Password = (txtPassword.Text);
- }
- catch (ExceptionClass ex)
- {
- P1.SetError(txtPassword, ex.Errormessage);
- errorcounter++;
- }
- try
- {
- myplayersignup.Reenterpassword = (txtReenterPassword.Text);
- }
- catch (ExceptionClass ex)
- {
- P1.SetError(txtReenterPassword, ex.Errormessage);
- errorcounter++;
- }
- try
- {
- myplayersignup.ComboBox = (cbgender.Text);
- }
- catch (ExceptionClass ex)
- {
- P1.SetError(cbgender, ex.Errormessage);
- errorcounter++;
- }
- {
- if (errorcounter == 0)//this will happen if all data entered is valid
- {
- MessageBox.Show("Successful Sign Up");//makes user aware with outputting that the sign up is successful
- 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
- }
- else//if the user gets at least one invalid data input when signing up this will be executed
- {
- MessageBox.Show("Unsucessful Sign Up");//makes user aware that they have at least entered once piece of invalid data
- }
- }
- }
- private void lblSecondName_Click(object sender, EventArgs e)
- {
- }
- private void dtpDOB_ValueChanged(object sender, EventArgs e)
- {
- }
- private void txtEnterFirstName_TextChanged(object sender, EventArgs e)
- {
- }
- private void txtEnterSecondName_TextChanged(object sender, EventArgs e)
- {
- }
- private void cbgender_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void txtemail_TextChanged(object sender, EventArgs e)
- {
- }
- private void txtUserName_TextChanged(object sender, EventArgs e)
- {
- }
- private void txtPassword_TextChanged(object sender, EventArgs e)
- {
- }
- private void txtReenterPassword_TextChanged(object sender, EventArgs e)
- {
- }
- private void btnlogin_Click(object sender, EventArgs e)
- {
- long pos = -1;
- bool found = false;
- players = new playersignup[20];
- playersignup playerdetails = new playersignup();
- Stream sr;
- string requsername;
- string reqpassword;
- reqpassword = txtPassword.Text;
- requsername = txtUserName.Text;
- sr = File.Open("PlayerDetails.bin", FileMode.Open, FileAccess.ReadWrite);
- BinaryFormatter bf = new BinaryFormatter();
- try
- {
- while (sr.Position < sr.Length)
- {
- pos = sr.Position;
- playerdetails = (playersignup)bf.Deserialize(sr);
- if ((playerdetails.Username.Trim().CompareTo(requsername.Trim()) == 0) && ((playerdetails.Password.Trim().CompareTo(reqpassword.Trim()) == 0)))
- {
- found = true;
- sr.Seek(pos, SeekOrigin.Begin);
- bf.Serialize(sr, playerdetails);
- MessageBox.Show("Sucessful Match");
- Frmmainmenu mainmenu = new Frmmainmenu();
- this.Hide();
- mainmenu.ShowDialog();
- this.Close();
- }
- for (int x = 0; x < players.Length; x++)
- {
- if ((txtusernamelogin.Text == players[x].Username) && (txtpasswordlogin.Text == players[x].Password))
- {
- found = true;
- sr.Seek(pos, SeekOrigin.Begin);
- bf.Serialize(sr, playerdetails);
- MessageBox.Show("Successful login");
- Frmmainmenu mainmenu = new Frmmainmenu();
- this.Hide();
- mainmenu.ShowDialog();
- this.Close();
- }
- else
- {
- MessageBox.Show("Unsuccessful match");
- }
- }
- }
- sr.Close();
- }
- catch (Exception g)
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement