Sie sind auf Seite 1von 5

Task A 2 : Produce the program design language algorithms for the following:

operation of the Booking Seat Plan screen


creation of a new file
opening of an existing file.
Note that if date validation is required the company has a prewritten library
routine called DateCheck which can be used. This routine takes a date input and
returns a boolean value of true if the date is valid and false if the date is not
valid.

Answer :
Produce the program design language algorithms for the following:

Operation of the Booking Seat Plan screen

Its the same for each button:


//Checks what is written in the checkBox and then changes text to B or 1
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
checkBox1.Text = "B";
}
else
{
checkBox1.Text = "1";
}

Creation of a new file

private void newToolStripMenuItem_Click(object sender, EventArgs e)


{
//opens a new file
SaveFileDialog newFile = new SaveFileDialog();
newFile.Title = "Save Text File";
newFile.Filter = "TXT files|*.txt";
newFile.InitialDirectory = @"\courseBooking";
//details for the dialog box, title, filter, and which directory to open
if (newFile.ShowDialog() == DialogResult.OK) //waits for OK button to be clicked

{
if (Path.GetExtension(newFile.FileName) == ".txt") //checks that you
entered .txt extension, and then creates a new file
{
File.Create(newFile.FileName);
}
else //if extension is something different than .txt it's going to show
the message box
{
MessageBox.Show("File incorrect format or dialog cancelled",
"Error 001", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

Task A 3 :Specify any error handling needed to trap errors in the booking
screen, file creation and opening an existing file algorithms.

Error Code 001

if (newFile.ShowDialog() == DialogResult.OK) //waits for OK button to be clicked


{
if (Path.GetExtension(newFile.FileName) == ".txt") //checks that you entered .txt
extension, and then creates a new file
{
File.Create(newFile.FileName);
}
else //if extension is something different than .txt, or dialog is cancelled
it's going to show the error message box
{

MessageBox.Show("File incorrect format or dialog cancelled", "Error 001",

MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Error Code 002

if (myDialog.ShowDialog() == DialogResult.OK) //waits for OK button to be


clicked
{
...
}
else //if dialog is cancelled it will show message box
{
MessageBox.Show("File open error or dialog cancelled", "Error 002",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Error Code 003

private void saveToolStripMenuItem_Click(object sender, EventArgs e)


{
//to save new course when it's entered
try
{
//writting into the file which is already open
using (StreamWriter file = new StreamWriter(filename, false,
Encoding.Default))
{
foreach (string line in fileLines)
{
file.WriteLine('"' + line + '"');
}
file.Close();
}
}
catch (NullReferenceException) //if you didn't open a file before than it will

show message box


{
MessageBox.Show("No file to save.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
catch (FileNotFoundException) // if it cann't find the file to writte in
{
MessageBox.Show("File save error.", "Error 003", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}

Error Code 004

private void button1_Click(object sender, EventArgs e)


{
DateTime result;
CultureInfo provider = CultureInfo.InvariantCulture;

try
{
//checking that date is in format "dd/MM/yyyy"
result = DateTime.ParseExact(textBox2.Text, "dd/MM/yyyy", provider);
...
}
catch (FormatException) //if date is not in format that we gave it then it
shows the message box
{
MessageBox.Show("Invalid Date", "Error 004", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}

Task A 4 : Give a brief description of the importance of software design in the


Systems Development Life Cycle (SDLC).
Answer : Software design describes desired features and operations in detail,
including screen layouts, business rules, process diagrams, pseudocode and
other documentation. These design elements are intended to describe the
system in sufficient detail, such that skilled developers and engineers may
develop and deliver the system with minimal additional input design.

Das könnte Ihnen auch gefallen