168 lines
8.1 KiB
C#
168 lines
8.1 KiB
C#
using MVPLearning.BaseLibrary;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace MVPLearning.RecordKeeping.SermonFiler
|
|
{
|
|
public partial class MaintainSermonFilerView : BaseForm, IMaintainSermonFilerView
|
|
{
|
|
public MaintainSermonFilerView()
|
|
{
|
|
InitializeComponent();
|
|
_model = new() { Title = "Constructor value"};
|
|
_model.PropertyChanged += ModelChanged;
|
|
BindControls();
|
|
//TextBoxFileName.TextChanged += TextBoxFileName_TextChanged ;
|
|
//ButtonLaunch.Enabled = !string.IsNullOrEmpty(_model.Filename);
|
|
}
|
|
public void LoadData(MaintainSermonFilerModel model)
|
|
{
|
|
if (model == null) { return; }
|
|
_loadedModel = model;
|
|
_model.Seid = model.Seid;
|
|
_model.Title = model.Title;
|
|
_model.Scripture = model.Scripture;
|
|
_model.When = model.When;
|
|
_model.Subject = model.Subject;
|
|
_model.Minister = model.Minister;
|
|
_model.Where = model.Where;
|
|
_model.Ref_No = model.Ref_No;
|
|
_model.Notes = model.Notes;
|
|
_model.Filename = model.Filename;
|
|
_model.Web = model.Web;
|
|
//EnableButtonLaunch();
|
|
|
|
Title = _model.Title;
|
|
Scripture = _model.Scripture;
|
|
When = _model.When;
|
|
Subject = _model.Subject;
|
|
Minister = _model.Minister;
|
|
Where = _model.Where;
|
|
Ref_No = _model.Ref_No;
|
|
Notes = _model.Notes;
|
|
Filename = _model.Filename;
|
|
Web = _model.Web;
|
|
}
|
|
public void BindControls()
|
|
{
|
|
TextBoxTitle.Bind(this, nameof(Title));
|
|
TextBoxTitle.GotFocus += TextBoxTitle_GotFocus;
|
|
TextBoxTitle.LostFocus += TextBoxTitle_LostFocus;
|
|
TextBoxScriptureReference.Bind(this, nameof(Scripture));
|
|
DatePickerWhenDelivered.Bind(this, nameof(When));
|
|
TextBoxSubject.Bind(this, nameof(Subject));
|
|
TextBoxWhoDelivered.Bind(this, nameof(Minister));
|
|
TextBoxWhereDelivered.Bind(this, nameof(Where));
|
|
TextBoxReferenceNumber.Bind(this, nameof(Ref_No));
|
|
TextBoxNotes.Bind(this, nameof(Notes));
|
|
TextBoxFileName.Bind(this, nameof(Filename));
|
|
TextBoxWebUrl.Bind(this, nameof(Web));
|
|
|
|
}
|
|
private string _title = string.Empty;
|
|
public string Title { get => _title; set { if (SetProperty(ref _title, value)) { _model.Title = value; } } }
|
|
private string _scripture = string.Empty;
|
|
public string Scripture { get => _scripture; set { if (SetProperty(ref _scripture, value)) { _model.Scripture= value; } } }
|
|
private DateTime? _when = null;
|
|
public DateTime? When { get => _when; set { if (SetProperty(ref _when, value)) { _model.When = value; } } }
|
|
private string _subject = string.Empty;
|
|
public string Subject { get => _subject; set { if (SetProperty(ref _subject, value)) { _model.Subject = value; } } }
|
|
private string _minister = string.Empty;
|
|
public string Minister { get => _minister; set { if (SetProperty(ref _minister, value)) { _model.Minister = value; } } }
|
|
private string _where = string.Empty;
|
|
public string Where { get => _where; set { if (SetProperty(ref _where, value)) { _model.Where = value; } } }
|
|
private string _ref_no = string.Empty;
|
|
public string Ref_No { get => _ref_no; set { if (SetProperty(ref _ref_no, value)) { _model.Ref_No = value; } } }
|
|
private string _notes = string.Empty;
|
|
public string Notes { get => _notes; set { if (SetProperty(ref _notes, value)) { _model.Notes = value; } } }
|
|
private string _filename = string.Empty;
|
|
public string Filename { get => _filename; set { if (SetProperty(ref _filename, value)) { _model.Filename = value; } } }
|
|
private string _web = string.Empty;
|
|
public string Web { get => _web; set { if (SetProperty(ref _web, value)) { _model.Web = value; } } }
|
|
private void TextBoxTitle_LostFocus(object? sender, EventArgs e)
|
|
{
|
|
WarnTitleIsEmpty();
|
|
}
|
|
|
|
private void TextBoxTitle_GotFocus(object? sender, EventArgs e)
|
|
{
|
|
LabelTitleWarning.Visible = false;
|
|
}
|
|
|
|
private void ModelChanged(object? sender, PropertyChangedEventArgs e)
|
|
{
|
|
if (e.PropertyName == nameof(_model.Filename)) { EnableButtonLaunch(); }
|
|
if (e.PropertyName == nameof(_model.Title)) { WarnTitleIsEmpty(); }
|
|
bool enableButtons = !_model.Equals(_loadedModel);
|
|
ButtonSave.Enabled = enableButtons;
|
|
ButtonCancel.Enabled = enableButtons;
|
|
}
|
|
private void WarnTitleIsEmpty()
|
|
{
|
|
// This is business logic, should these only happen when the user clicks Save?
|
|
if (string.IsNullOrEmpty(_model.Title)) { LabelTitleWarning.Visible = true; }
|
|
}
|
|
private void EnableButtonLaunch()
|
|
{
|
|
//_view.LaunchButtonWrapper.Enabled = !string.IsNullOrEmpty(_view.FileNameTextWrapper.Text);
|
|
ButtonLaunch.Enabled = !string.IsNullOrEmpty(_model.Filename);
|
|
}
|
|
|
|
private readonly MaintainSermonFilerModel _model = new();
|
|
private MaintainSermonFilerModel? _loadedModel;
|
|
public event EventHandler? AddButtonClicked;
|
|
public event EventHandler<int>? DeleteButtonClicked;
|
|
public event EventHandler<int>? LocateButtonClicked;
|
|
public event EventHandler<int>? NextButtonClicked;
|
|
public event EventHandler<int>? PreviousButtonClicked;
|
|
public event EventHandler? CloseButtonClicked;
|
|
public event EventHandler? BrowseButtonClicked;
|
|
public event EventHandler<string>? LaunchButtonClicked;
|
|
public event EventHandler<MaintainSermonFilerModel>? SaveButtonClicked;
|
|
public event EventHandler? CancelButtonClicked;
|
|
|
|
private void AddButton_Click(object sender, EventArgs _) { if (CheckForChangedData()) { AddButtonClicked?.Invoke(sender, EventArgs.Empty); } }
|
|
private void DeleteButton_Click(object sender, EventArgs _) { DeleteButtonClicked?.Invoke(sender, _model.Seid); }
|
|
private void LocateButton_Click(object sender, EventArgs _) { if (CheckForChangedData()) { LocateButtonClicked?.Invoke(sender, _model.Seid); } }
|
|
private void NextButton_Click(object sender, EventArgs _) { if (CheckForChangedData()) { NextButtonClicked?.Invoke(sender, _model.Seid); } }
|
|
private void PreviousButton_Click(object sender, EventArgs _) { if (CheckForChangedData()) { PreviousButtonClicked?.Invoke(sender, _model.Seid); } }
|
|
private void CloseButton_Click(object sender, EventArgs _) { if (CheckForChangedData()) { CloseButtonClicked?.Invoke(sender, EventArgs.Empty); } }
|
|
private void BrowseButton_Click(object sender, EventArgs _) { if (CheckForChangedData()) { BrowseButtonClicked?.Invoke(sender, EventArgs.Empty); } }
|
|
private void LaunchButton_Click(object sender, EventArgs _) { LaunchButtonClicked?.Invoke(sender, _model.Filename); }
|
|
private void SaveButton_Click(object sender, EventArgs _) { SaveButtonClicked?.Invoke(sender, _model); }
|
|
private void CancelButton_Click(object sender, EventArgs _) { if (_loadedModel != null) { LoadData(_loadedModel); } }
|
|
|
|
|
|
|
|
|
|
private bool CheckForChangedData()
|
|
{
|
|
if (_loadedModel == null) { return true; }
|
|
if (!_loadedModel.Equals(_model))
|
|
{
|
|
DialogResult saveChanges = MessageBox.Show("Do you want to save the changes made?", this.Text, MessageBoxButtons.YesNoCancel);
|
|
if (saveChanges == DialogResult.Cancel) { return false; }
|
|
if (saveChanges == DialogResult.Yes) { SaveButtonClicked?.Invoke(this, _model); }
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
BindControls();
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
this.Refresh();
|
|
}
|
|
}
|
|
}
|