PC Review


Reply
Thread Tools Rate Thread

This code is located in the GUI class and I think that it belongs there.

 
 
Tony Johansson
Guest
Posts: n/a
 
      26th Feb 2011
Helle!
Here is some code and all of these is locaded in the GUI class and I think
it belongs there because it it very tightly connected
to the OpenFileDialog and SaveFileDialog.
So I just want your opinion if you think that some of this should be moved
out og the GUI class.
I would say that if some of this code would be moved to the controller class
AnimalManager it would be a bad solution
because we still have the OpenFileDialog and SaveFileDialog which require
ShowDialog.

This event handler is called when you click the Open in the menu
private void MenuFileOpen_Click(object sender, EventArgs e)
{
try
{
openFileDialog.AddExtension = true;
openFileDialog.DefaultExt = "Data";
openFileDialog.Title = "Open File";
openFileDialog.ValidateNames = true;
openFileDialog.InitialDirectory =
Directory.GetCurrentDirectory();
openFileDialog.Filter = "Data files (*.data)|*.data|All
Files|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Utför binär Deserialisering av alla animal i filen
animalManager.AllAnimals =
BinarySerialization.BinaryFileDeserialize<Animal[]>(openFileDialog.FileName).ToList
();
UpdateGUI();
InitializeGUI();
}
}
catch (IOException ex)
{
MessageBox.Show("An IOException occured " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("An Exception occured " + ex.Message);
}
}

This event handler is called when you click the Save in the menu
private void MenuFileSave_Click(object sender, EventArgs e)
{
if (animalManager.Animals.Count == 0)
{
return;
}

try
{
if (chosenFileName == string.Empty)
{
SaveToFile();
}
else
{
BinarySerialization.BinaryFileSerialize(animalManager.Animals.ToArray(),
chosenFileName);

//Indikera att data är sparad
animalManager.DataSaved = true;
}
}
catch (IOException ex)
{
MessageBox.Show("An IOException occured " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("An Exception occured " + ex.Message);
}
}

//This helper method is called from MenuFileSave_Click and
MenuFileSaveAs_Click
private void SaveToFile()
{
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "Data";
saveFileDialog.Title = "Save File";
saveFileDialog.ValidateNames = true;
saveFileDialog.OverwritePrompt = true;
saveFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
saveFileDialog.Filter = "Data files (*.data)|*.data|All Files|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
chosenFileName = saveFileDialog.FileName;
BinarySerialization.BinaryFileSerialize(animalManager.Animals.ToArray(),
chosenFileName);

//Indikera att data är sparad
animalManager.DataSaved = true;
}
}

This event handler is called when you click the SaveAs in the menu
private void MenuFileSaveAs_Click(object sender, EventArgs e)
{
if (animalManager.Animals.Count == 0)
{
return;
}

try
{
SaveToFile();
}
catch (IOException ex)
{
MessageBox.Show("An IOException occured " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show("An Exception occured " + ex.Message);
}
}

private void MenuFileNew_Click(object sender, EventArgs e)
{
//Om collection är tom gör ingenting
if (animalManager.Animals.Count == 0)
return;

//On collection inte är sparad skrävs ett svar om du ska göra reset
eller inte
if (!animalManager.DataSaved)
{
DialogResult result = MessageBox.Show(this, "The Contents has
not been saved. Do you want to reset anyway: ", "Confirmation on resetting",
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (DialogResult.No == result)
{
return;
}
}
animalManager.Reset();
UpdateGUI();
InitializeGUI();
}

//Tony


 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      26th Feb 2011
On 26-02-2011 14:23, Tony Johansson wrote:
> Here is some code and all of these is locaded in the GUI class and I think
> it belongs there because it it very tightly connected
> to the OpenFileDialog and SaveFileDialog.
> So I just want your opinion if you think that some of this should be moved
> out og the GUI class.
> I would say that if some of this code would be moved to the controller class
> AnimalManager it would be a bad solution
> because we still have the OpenFileDialog and SaveFileDialog which require
> ShowDialog.


As far as I can see then almost every other line in this code
refer to instances of win forms classes.

Definitely GUI.

The only line I may wish to move was the serializer call.

Arne
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where should a boolean flag be located in the GUI class or controll class Tony Johansson Microsoft C# .NET 1 15th Feb 2011 02:03 PM
Where is message class located? Orionssong Microsoft Outlook 1 4th Dec 2007 12:56 PM
How to find the namespace a class belongs to? Doru Roman Microsoft C# .NET 9 9th Feb 2006 10:07 AM
How to reference a Class Module located in an add-in or another workbook? keithb Microsoft Excel Programming 1 10th Sep 2005 01:40 AM
DAO Code to remove ALL the groups that a user belongs to Tony_VBACoder Microsoft Access Security 1 1st Jul 2004 10:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:06 PM.