} // WriteFile() private void btnSignUp_Click(object sender, EventArgs e) { // Will take the M# and Name entered into the text boxes and create a // data file as "M#_Name.dat", this will later be used to check if the // login credentials are valid. UserClass.User userObj = new UserClass.User(); userObj.userID = tbMNumber.Text; userObj.userName = tbName.Text; WriteFile(userObj.userID, userObj.userName); if (valid == true) { //THIS event opens another form // Hide "this" current form this.Hide(); // Create a new object that will represent the next form. frmUser frm = new frmUser(); // Displays the other form using its object instance frm.Show(); frm = null; } // endif } // btnSignUp_Click()
private static void ReadFile(string ID, string name) { string line = "x"; //string[] arrayField; TextReader streamData = null; string file = "../../Data/" + ID + "_" + name; // will store the file name as M#_Name.dat UserClass.User userObj = new UserClass.User(); if (File.Exists(file + ".dat")) { try { streamData = new StreamReader(file + ".dat"); while (streamData.Peek() > -1) { line = streamData.ReadLine(); userObj.userID = line.Trim(); line = streamData.ReadLine(); userObj.userName = line.Trim(); } // while() } // try catch (IOException err) { MessageBox.Show(err.Message); valid = false; } // catch finally { if (streamData != null) { streamData.Close(); } MessageBox.Show("Login successful!"); valid = true; } // finally } // endif else { MessageBox.Show("Invalid M# or Name."); valid = false; } // else } // ReadFile()