· web viewthe program is of very good quality as it’s extremely easy to use with clear...

18
Technical Document for MHR Unit 325 By Josh Gibson

Upload: vannhi

Post on 07-Mar-2018

218 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

Technical Document for MHRUnit 325 By Josh Gibson

Page 2: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

MHRThe purpose of the program is to calculate someone’s maximum and target heart rate it does this by storing personal information like age, gender and resting heart rate. It will find the target heart rate by getting the persons age and resting heart rate and adding them together

(targetheartrate = (age + resting);) and then to find out the maximum heart rate it will check what gender you are as it is pre-set to 220 for a male and 212 for a female and it will take away their age by them numbers depending on their gender ( maximumheartrate = (gendercheck - age) - resting;). To pre-set we had to create a variable called gendercheck and depending on what they answered for gender and it will override the normal value of 0 to 220 or 212 (public void methodgender(){

if (gender.Equals("Male")) gendercheck = 220;

}else if (gender.Equals("Female")) {

gendercheck = 212; } })

Page 3: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program
Page 4: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

COPY OF THE CODEMHRusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;

namespace MHRV1{ public partial class MHRCalc : Form { public byte age = 0; public byte resting = 0; public byte max = 0;//Decimal numbers public String username = "";//letter and numbers public String gen = "Male"; public byte genhr = 0; //Numercial Numbers public double target = 0; public int count = 0; // SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\College\MHR\MHR\Newmember.mdf;Integrated Security=True");

SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=G:\Computing\City & Guilds\Level 3\Unit 325\Ben Wright NEW Code\MHRV1\MHRV1\Member.mdf;Integrated Security=True"); Details details; List<Details> detailsList = new List<Details>();

public MHRCalc() { InitializeComponent(); }

private void lblPassword_Click(object sender, EventArgs e) {

}

private void btnBack_Click(object sender, EventArgs e) { Form1 formBK = new Form1(); this.Hide(); formBK.Show(); }

private void MHRCalc_Load(object sender, EventArgs e) {

}

private void lblRestingHeartRate_Click(object sender, EventArgs e) {

Page 5: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

}

private void btnCalculate_Click(object sender, EventArgs e) { setup(); } private void txtOutput_TextChanged(object sender, EventArgs e) {

} // the method below is changing the value of genhr for each user as every user will be either female or male public void genCalc() { if (gen.Equals("Male")) { genhr = 220; } else { genhr = 212; } } //this method calculates the maximum heart rate by checking what gender the persons is and take away their age from the heart rate depending on their gender and then it will take away the resting // heart rate public void mhrCalc() { max = Convert.ToByte((genhr - age) - resting); }

// this is the code to calculate the tagert heart rate and to do that you need to add their age to the resting heart rate public void targetClac() { target = Convert.ToByte((max * 0.8) + resting); max =Convert.ToByte( max + resting); }

//this is a diplay method to display your maximum and target heart rate to two text boxes on the interface public void display() { txtOutput.Text = "Your target heart rate is:" + target.ToString() + " Your maximum heart rate is:" + max.ToString(); } public void setup() { age = Program.detailsGlobal.getage(); gen = Program.detailsGlobal.getgender(); resting = Program.detailsGlobal.getresting(); genCalc(); mhrCalc(); targetClac(); display(); }

private void btnHelp_Click(object sender, EventArgs e) {

Page 6: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

//help.Show(); //this.Hide(); }

} }

HELPusing System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;

namespace MHRV1{ public partial class Help : Form { // MHRCalc heart = new MHRCalc(); public Help() { InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) { // heart.Show(); // this.Hide(); }

private void textBox1_TextChanged(object sender, EventArgs e) {

}

private void Help_Load(object sender, EventArgs e) {

} }}

REGusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;

Page 7: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

namespace MHRV1{ public partial class Reg : Form {

SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\MHR josh gibson\Ben Wright NEW Code\MHRV1\MHRV1\Member.mdf;Integrated Security=True");

//the Line below creates something called a variable //this is used to store data. it will be stored in memory //string says the type of data that the variable will hold private String username = ""; private String password = ""; private String forename = ""; private String surname = ""; private byte age = 0; private byte restingheartrate = 0; private String gender = "";

Details details; //the line below creates a special type of list called and arraylist. this has been set up to hold objects of the details class. // Remember this class is where we placed the set and get methods. //use the list to write info from and to the database List<Details> detailsList = new List<Details>();

public Reg() { InitializeComponent(); }

private void Reg_Load(object sender, EventArgs e) {

}

private void rbtnMale_CheckedChanged(object sender, EventArgs e) { gender = "Male"; }

private void label1_Click(object sender, EventArgs e) { gender = "Female"; }

private void btnBack_Click(object sender, EventArgs e) { Form1 formBK = new Form1(); this.Hide(); formBK.Show(); }

private void btnRegister_Click(object sender, EventArgs e) { try { password = txtPassword.Text; username = (txtUsername.Text).ToLower(); forename = (txtForename.Text).ToLower(); surname = (txtSurname.Text).ToLower();

Page 8: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

age = Convert.ToByte(txtAge.Text); restingheartrate = Convert.ToByte(txtResting.Text);

if (char.IsLetter(username[0]) || char.IsLetter(password[0]) || char.IsLetter(forename[0]) || char.IsLetter(surname[0])) // talk about data validation { //the line below creates an object that is called details. An object can be seen as a copy of class details. //when we make a copy we have to give it some infromation. The information required is forename, surname, username, password, gender, age and resting heart rate. //the values held in the object variables will pass on the new details to the new detaiils object. this keeps all the info together //the code below stores data into the variables provided (simple) details = new Details(username, forename, surname, password, gender, age, restingheartrate); //the code below will find a piece of the code and then run the lines of instructions that it contains. It is known as a message call. addDatabase(); } else { MessageBox.Show("Please enter a valid input"); }

} catch (Exception) {

MessageBox.Show("Please enter all fields");

} }

private void btnUpdate_Click(object sender, EventArgs e) {

} public void addDatabase() { Console.WriteLine("Open connection"); try //explain how the try and catch work, try tests several lines of code { using (SqlCommand com = new SqlCommand("INSERT INTO MemberDetails (Forename, Surname, Username, Password, Age, RestingHeartRate, Gender) Values (@forename, @surname, @username1, @password1, @age1, @resting, @gender1)", cn)) { //the lines below will get the data that will passed to the values command. It //gets the data from an object called details. this object is a copy of the class called details. //we use the object to accessa methods such as getname and this will get the stored data such as name //from the details object. this is then passed to the values command. the con.parameters.addwithvalue is a command // that makes this possible cn.Open();

Page 9: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

com.Parameters.AddWithValue("forename", details.getforename()); com.Parameters.AddWithValue("surname", details.getsurname()); com.Parameters.AddWithValue("username1", details.getusername()); com.Parameters.AddWithValue("password1", details.getpassword()); com.Parameters.AddWithValue("age1", details.getage()); com.Parameters.AddWithValue("resting", details.getresting()); com.Parameters.AddWithValue("gender1", details.getgender()); //this line then runs the insert command as it calls the command executellonQuery com.ExecuteNonQuery(); // this line closes the the connection string cn.Close(); } } // this line catches any errors that could occur when opening or writing to the database. catch (Exception e) // Catch will catch any errors { //this line will display a message to the user saying it cannot add new memer to database as a problem has occured //the e.Message is command that will retrieve the error and display it the screen MessageBox.Show("Cannot add new member to database" + e.Message); } } public void readIn() { cn.Open(); Console.WriteLine("Open connection");

using (SqlCommand command = new SqlCommand("SELECT * FROM MemberDetails", cn)) { SqlDataReader reader = command.ExecuteReader();

while (reader.Read()) { string forename = reader.GetString(1); string surname = reader.GetString(2); string username = reader.GetString(3); string password = reader.GetString(4); byte age = reader.GetByte(5); byte resting = reader.GetByte(6); string gender = reader.GetString(7);

// public Details(String username1, String forename1, String surname1, String password1, String gen, byte age1, byte heart) detailsList.Add(new Details(username, forename, surname, password, gender, age, resting)); } cn.Close(); } }

private void txtResting_TextChanged(object sender, EventArgs e) {

Page 10: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

} }}

FORM 1using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;

namespace MHRV1{ public partial class Form1 : Form { //the line below creates something called an object //this is a copy of reg form class Reg registration = new Reg(); MHRCalc login = new MHRCalc(); SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\MHR josh gibson\Ben Wright NEW Code\MHRV1\MHRV1\Member.mdf;Integrated Security=True"); Details details; List<Details> detailsList = new List<Details>(); //this is used to keep related data together, like a shopping list. It holds data from the details class //below are variables that are used in the program private String username = ""; private String password = ""; public int count = 0;

public Form1() { InitializeComponent(); }

private void button2_Click(object sender, EventArgs e) { registration.Show(); this.Hide(); }

private void button1_Click(object sender, EventArgs e) { try { username = txtUsername.Text; //this takes the username that the user has entered into the text box and puts it into the username variable password = txtPassword.Text; //this takes the password that the user has entered into the text box and puts it into the password variable

//validating the input to check that the user has entered something, if true call method if (char.IsLetter(username[0]) && char.IsLetter(password[0])) { chkLogin(); //this line runs the code }

Page 11: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

else //if no true then run else code and display the message below { MessageBox.Show("Please enter a valid input"); } } catch (Exception) {

MessageBox.Show("Please enter all values");

} }

private void lblUsername_Click(object sender, EventArgs e) {

}

private void lblPassword_Click(object sender, EventArgs e) {

}

private void Form1_Load(object sender, EventArgs e) {

}

public void readIn() { // opens a connection to the database so that we can read and write from. cn.Open(); //the line will verify that the connection has been opened and will write an output to the screen Console.WriteLine("Open connection"); //This line creates a query. this is a request to the database to do something. The select is asking //the database to get something from the table in the database called mhr. the * says get everything in the table //the cn is the connect to the database and the query is sent to the //database using cn. using (SqlCommand command = new SqlCommand("SELECT * FROM MemberDetails", cn)) { //next we create the reader who will read the data from the database //the reader is created from a special sql class called SQLDataReader SqlDataReader reader = command.ExecuteReader(); //we now use the reader to read the in. We do this by creating a while loop. //The condition of the something to be read in. whilst this is true the next //piece od data is read from the database, It will read a row of data every time it loops. while (reader.Read()) //The reader will read the first collumn in the row. The command GetString will retrieve the data from the reader // and passess it to the variable forename {

Page 12: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

string forename = reader.GetString(1); // the process is then repeated string surname = reader.GetString(2); string username = reader.GetString(3); string password = reader.GetString(4); byte age = Convert.ToByte(reader.GetInt32(5)); byte resting =Convert.ToByte(reader.GetDecimal(6)); string gender = reader.GetString(7); //when all the data from one row is retrieved and placed into a variable, the variables are put together to form one object (this can be seen as a zip file where we put all the related data together in one place and allow the program keep // age = Convert.ToByte(age); detailsList.Add(new Details(username, forename, surname, password, gender, age, resting)); } cn.Close(); } } public void chkLogin() { //makes a call to the read in method. the method will read all the data from the database. readIn(); //this line will extract the user name from the object held be details and stores it into tempname string tempUsername =""; // This line will create a temp variable called tempPassword string tempPassword =""; //The next line will use a while loop to retrieve an object that has been placed into the //list (this is like a table) which is called detailslist. //the condition in the loop uses the variable count to count the number of loops. It then checks to see //if the count is equal or is less than the number of the rows in the detailslist //uses the command. Count. if true it will continue to loop, if the condition is no longer met ie //false the loop will break while ( count < detailsList.Count) //This next line checks to see if the username that has been extracted from the object matches //The username that has been entered into the username textbox and it will then checks to see if password also meets //the extracted password.If both are true then the next line is ran otherwise it will go to the else statement { details = detailsList.ElementAt(count); // this next line will extract the username from the object held by details and store it into tempUsername tempUsername = details.getusername(); // the process is then repeated for password tempPassword = details.getpassword(); // the next line below checks to see if the username that has been extracted from the object matches the username that has been entered into the textbox. It then checks to see if the password also matches in the same way. if both are true then the next line is run, otherwise it goes on to the else statement if (tempUsername.Equals(username) && tempPassword.Equals(password)) {

Page 13: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

// Program.detailsGlobal = details; // this shows the mhr form Program.detailsGlobal = details; login.Show(); // this hides the current form this.Hide(); // this breaks the loop break; // if not true then the else statement will run } else { // if count equals the number of rows in details list ie if there are 10 rows and count reaches 10 then the messagebox line will run. this is to prevent the messagebox displaying until each row has been checked for a match. if (count == detailsList.Count-1) { MessageBox.Show("You cannot login"); } } // count is incremented ie 1 is added to the it on each loop. count ++; } } }}

REVIEW

The program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next

Page 14: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

to it, so the program is easy to use for everyone as I have made the writing and everything else on the program very easy to see. The code is very easy to see as I have left spaces between pieces of code so I can see if I’ve made a mistake in my code also I have left comments in the code to explain certain parts that might be complicated or difficult to understand, it would be simple to add new features into the code as I’ve laid it out with a simplicity in mind.

Indentation is very useful in coding as if allows pieces of code to be easily seen and also let us know what brackets connect and which don’t and without this it could get very difficult to read the program. It improves the quality of the program as it looks nicer than a wall of straight text, in my program I have got indentation and will not have to add more. The Variables and Methods are provided with relatable name because it is easier for the programmer to know what they are called when writing the code and it is so that if a new programmer took over the work they will not what the variables are for and what the method does, inserting comments into your code is for the same reason and so when people read your code they know what that piece of code does and why it is in the program.

Data Validation is very important in code as it prevents errors in your code by checks for example a presence check will check if they the textbox isn’t left empty and that the user has to fill it in, a range check will check if a value of for example a numeric up and down is between the certain numbers and if it isn’t it will tell the user to input a correct input, Type check is where it will check if a certain characters of an input is the correct amount for example a pin number is four digits and it would allow more or less than four.A check digit is calculated from the numbers to be entered and added to the end and it can be checked anytime and it can be re-calculated so it is checked if it is correct.

Test No.

Test Test Data Expected Actual Screen shot with comments

1 Loads screen

None Loads It loads

2 Can you change to registration screen

None Registration to load

It changes to reg form

3 On Registration add new member

Name:FredSurname: SmithGender:MaleAge: 22UserName:GeekPassword:12

Expect to be able to add new member

It will add the new member

Page 15: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

3Resting Heart: 80

4 ErrorLeft age empty

Name: FredSurname: SmithGender:MaleAge: (empty)UserName:GeekPassword:123Resting Heart: 80

Capture error and not crash

Capture the error

5 login Username:GeekPassword 1232

Don’t login in

Didn’t login

6 Can enter a female into the database

Name: KellySurname: SmithGender: FemaleAge: 18UserName:kel123Password:123Resting Heart: 80

Will allow reg

7 Can login UserName:kel123Password:123

Will allow to login

Logged in

8 Help button

Click the help button

Will come up with help information

Didn’t come up with help information

1. Loads screenThis test will make sure that the program loads up so when you run the program it will run correctly

2. Can you change to registration screen?This test will make sure that from the main loading page and when you click the register button it will go to the registration screen

3. On Registration add new member

Page 16: · Web viewThe program is of very good quality as it’s extremely easy to use with clear big buttons and easy to see textboxes and what you have to input next to it, so the program

This test will make sure when you have added in all the details and you click register than it will register you as a new member and you will be able to log in

4. Error Left age emptyThis will test that when you leave a box empty it will catch that you haven’t put in it and will come up with an error message

5. LoginThis will test to make sure that you cannot login in the account with the wrong password so that every user will have an individual password to their accounts.

6. Can enter a female into the databaseThis is to test that you can make an account for a female instead of a female.

7. Can loginThis test is to make sure that you can login with the account you have created and it did let me

8. Help buttonThis is to make sure that the help button works and it does, the help button is to make sure that the users knows what to do.