|
using System;
using System.Drawing;
using System.Windows.Forms;
using Sedge.Core;
using Sedge.Core.Globalization;
using Sedge.Core.Utils;
using Sedge.UI.ViewModel;
namespace Sedge.UI.View
{
public partial class MasterForm : Form
{
#region Private Fields
public delegate void NavigationEventHandler();
private event NavigationEventHandler NextViewEvent;
private readonly MasterViewModel _viewModel;
private Control _currentView;
private bool _finish;
#endregion //Private Fields
#region Constructors
public MasterForm()
{
InitializeComponent();
}
public MasterForm(MasterViewModel viewModel)
: this()
{
_viewModel = viewModel;
NextViewEvent = ShowNextView;
SetupWindow();
ShowNextView();
}
#endregion Constructors
#region Private Methods
private void SetupWindow()
{
Services.ViewManager.LockingChanged += ViewManager_LockingChanged;
buttonBack.Text = Locale.Strings.ButtonBack;
buttonNext.Text = Locale.Strings.ButtonNext;
buttonCancel.Text = Locale.Strings.ButtonCancel;
Text = _viewModel.GetCaption();
if (!String.IsNullOrEmpty(Locale.Banner))
{
try
{
Image image = Image.FromFile(Locale.Banner);
Image background = new Bitmap(panelBanner.Width, panelBanner.Height);
using (Graphics g = Graphics.FromImage(background))
{
g.DrawImage(image, background.Width - image.Width, background.Height - image.Height);
}
panelBanner.BackgroundImage = background;
}
catch (Exception)
{
ErrorHandler.Warning(Locale.Strings.EFileNotFound, Locale.Banner);
}
}
}
private void ViewManager_LockingChanged(bool isLocked)
{
SetupButtons();
}
private void SetupButtons()
{
if (!_viewModel.HasNextView())
{
buttonNext.Text = Locale.Strings.ButtonFinish;
NextViewEvent = Finish;
buttonCancel.Enabled = Services.ViewManager.IsLocked;
}
else
{
buttonNext.Text = Locale.Strings.ButtonNext;
NextViewEvent = ShowNextView;
buttonCancel.Enabled = true;
}
buttonBack.Enabled = _viewModel.HasPrevView() && !Services.ViewManager.IsLocked;
buttonNext.Enabled = !Services.ViewManager.IsLocked;
}
#endregion //Private Methods
#region Private Navigation Methods
private void ShowPrevView()
{
ShowView(_viewModel.GetPrevView());
}
private void ShowNextView()
{
ShowView(_viewModel.GetNextView());
}
private void ShowView(Control view)
{
if (_currentView != null)
{
panelMain.Controls.Remove(_currentView);
}
_currentView = view;
labelCaption.Text = _viewModel.GetViewCaption();
if (_currentView != null)
{
panelMain.Controls.Add(_currentView);
_currentView.Dock = DockStyle.Fill;
_currentView.Show();
}
SetupButtons();
}
private void Finish()
{
if (Services.ViewManager.CleanOnExit)
_viewModel.Clean();
_finish = true;
Close();
}
#endregion //Private Navigation Methods
#region Event handlers
private void MasterForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (_finish)
return;
if (e.CloseReason == CloseReason.UserClosing)
{
if (!Services.Communications.Question(Locale.Strings.MFormCancel, Locale.Strings.MFormCaption))
{
e.Cancel = true;
}
}
if (!e.Cancel)
{
_viewModel.Cancel();
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
Close();
}
private void buttonNext_Click(object sender, EventArgs e)
{
NextViewEvent();
}
private void buttonBack_Click(object sender, EventArgs e)
{
ShowPrevView();
}
#endregion Event handlers
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a software developer from Toronto with 15 years of experience in software design and development. My major professional area is the development of highly customized software solutions, including desktop and web applications. Industrial process automation and hardware-related software development are among my favorite projects and I enjoyed developing several applications for semiconductor manufacturing companies.
My blog: http://LunarFrog.com/blog