|
using System;
using System.IO;
using System.Windows.Controls;
using System.Windows.Data;
using System.ComponentModel.Composition;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using IssueVision.Common;
namespace IssueVision.Client
{
public partial class IssueEditor : UserControl, ICleanup
{
#region "Private Data Members"
private Lazy<ViewModelBase> _viewModelExport;
#endregion "Private Data Members"
#region "Constructor"
public IssueEditor()
{
InitializeComponent();
if (!ViewModelBase.IsInDesignModeStatic)
{
// Use MEF To load the View Model
_viewModelExport = App.Container.GetExport<ViewModelBase>(
ViewModelTypes.IssueEditorViewModel);
this.DataContext = _viewModelExport.Value;
}
// register for ReadOnlyIssueMessage
AppMessages.ReadOnlyIssueMessage.Register(this, OnReadOnlyIssueMessage);
// register for OpenFileMessage
AppMessages.OpenFileMessage.Register(this, OnOpenFileMessage);
// register for SaveFileMessage
AppMessages.SaveFileMessage.Register(this, OnSaveFileMessage);
}
#endregion "Constructor"
#region "ReadOnlyIssueMessage"
private void OnReadOnlyIssueMessage(Boolean readOnly)
{
if (readOnly)
{
// prepare the screen for read-only issue
this.textBox_IssueTitle.IsReadOnly = true;
this.comboBox_Type.IsEnabled = false;
this.comboBox_Priority.IsEnabled = false;
this.comboBox_Severity.IsEnabled = false;
this.comboBox_Status.IsEnabled = false;
this.comboBox_Substatus.IsEnabled = false;
this.dataGrid_Platform.IsEnabled = false;
this.comboBox_AssignedTo.IsEnabled = false;
this.comboBox_Resolution.IsEnabled = false;
this.textBox_Description.IsReadOnly = true;
this.textBox_ReproSteps.IsReadOnly = true;
this.listBox_Files.IsEnabled = false;
this.button_Add.IsEnabled = false;
this.button_Remove.IsEnabled = false;
this.button_Save.IsEnabled = false;
this.dataGrid_Attributes.IsEnabled = false;
this.button_AddAttribute.IsEnabled = false;
this.button_RemoveAttribute.IsEnabled = false;
}
else
{
// prepare the screen for read/update issue
this.textBox_IssueTitle.IsReadOnly = false;
this.comboBox_Type.IsEnabled = true;
this.comboBox_Priority.IsEnabled = true;
this.comboBox_Severity.IsEnabled = true;
this.comboBox_Status.IsEnabled = true;
this.comboBox_Substatus.IsEnabled = true;
this.dataGrid_Platform.IsEnabled = true;
this.comboBox_AssignedTo.IsEnabled = true;
this.comboBox_Resolution.IsEnabled = true;
this.textBox_Description.IsReadOnly = false;
this.textBox_ReproSteps.IsReadOnly = false;
this.listBox_Files.IsEnabled = true;
this.button_Add.IsEnabled = true;
this.button_Remove.IsEnabled = true;
this.button_Save.IsEnabled = true;
this.dataGrid_Attributes.IsEnabled = true;
this.button_AddAttribute.IsEnabled = true;
this.button_RemoveAttribute.IsEnabled = true;
}
}
#endregion "ReadOnlyIssueMessage"
#region "OpenFileMessage"
private void OnOpenFileMessage(NotificationMessageAction<FileInfo> message)
{
try
{
OpenFileDialog ofDialog = new OpenFileDialog();
ofDialog.Filter = "All Files (*.*)|*.*";
ofDialog.Multiselect = false;
// show the dialog box
if (ofDialog.ShowDialog().GetValueOrDefault(false))
{
// send the file selected back
message.Execute(ofDialog.File);
}
}
catch (Exception ex)
{
// notify user if there is any error
AppMessages.RaiseErrorMessage.Send(ex);
}
}
#endregion "OpenFileMessage"
#region "SaveFileMessage"
private void OnSaveFileMessage(IssueVision.Data.Web.File saveFile)
{
try
{
SaveFileDialog sfDialog = new SaveFileDialog();
// set Filter
sfDialog.Filter = "All Files (*.*)|*.*";
// set DefaultExt
sfDialog.DefaultExt = saveFile.FileName.Contains(".") ? saveFile.FileName.Substring(saveFile.FileName.LastIndexOf('.')) : saveFile.FileName;
// show the dialog box
if (sfDialog.ShowDialog().GetValueOrDefault(false))
{
using (Stream stream = sfDialog.OpenFile())
{
stream.Write(saveFile.Data, 0, saveFile.Data.Length);
}
}
}
catch (Exception ex)
{
// notify user if there is any error
AppMessages.RaiseErrorMessage.Send(ex);
}
}
#endregion "SaveFileMessage"
#region "ICleanup interface implementation"
public void Cleanup()
{
// call Cleanup on its ViewModel
((ICleanup)this.DataContext).Cleanup();
// cleanup itself
Messenger.Default.Unregister(this);
// set DataContext to null and call ReleaseExport()
this.DataContext = null;
App.Container.ReleaseExport<ViewModelBase>(_viewModelExport);
_viewModelExport = null;
}
#endregion "ICleanup interface implementation"
}
}
|
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.
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET