basic ui created

This commit is contained in:
2021-02-04 23:40:08 +01:00
parent bf57e3a983
commit 47310b17dc
4 changed files with 225 additions and 17 deletions

View File

@@ -1,18 +1,22 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace Massmailer.Shared.Model
{
public class MassmailerProject
public class MassmailerProject : INotifyPropertyChanged
{
public MassmailerProject()
{
this.Recipients = new List<MassmailerRecipient>();
this.Recipients = new ObservableCollection<MassmailerRecipient>();
}
public List<MassmailerRecipient> Recipients { get; set; }
public ObservableCollection<MassmailerRecipient> Recipients { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@@ -1,13 +1,44 @@
using System;
using System.ComponentModel;
namespace Massmailer.Shared.Model
{
public class MassmailerRecipient
public class MassmailerRecipient : INotifyPropertyChanged
{
public string Address { get; set; }
private string address;
private bool isSent;
private DateTime sentDate;
public bool IsSent { get; set; }
public string Address
{
get { return this.address; }
set
{
this.address = value;
this.PropertyChanged(this, new PropertyChangedEventArgs(nameof(this.Address)));
}
}
public DateTime SentDate { get; set; }
public bool IsSent
{
get { return this.isSent; }
set
{
this.isSent = value;
this.PropertyChanged(this, new PropertyChangedEventArgs(nameof(this.IsSent)));
}
}
public DateTime SentDate
{
get { return this.sentDate; }
set
{
this.sentDate = value;
this.PropertyChanged(this, new PropertyChangedEventArgs(nameof(this.SentDate)));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@@ -5,8 +5,74 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Massmailer.UI"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
Title="Massmailer" Height="450" Width="800" Loaded="Window_Loaded">
<Grid>
<Button x:Name="BtnSend" Click="Button_Click" Content="Send"/>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Menu IsMainMenu="True" Grid.Row="0" Grid.ColumnSpan="2">
<Menu.Items>
<MenuItem Header="Datei">
<MenuItem.Items>
<MenuItem Header="Neu..." Click="MnuFileNew_Click"/>
<MenuItem Header="Öffnen..." Click="MnuFileOpen_Click"/>
<Separator/>
<MenuItem Header="Speichern" Click="MnuFileSave_Click"/>
<MenuItem Header="Speichern unter..." Click="MnuFileSaveAs_Click"/>
<Separator/>
<MenuItem Header="Beenden" Click="MnuFileQuit_Click"/>
</MenuItem.Items>
</MenuItem>
<MenuItem Header="Hilfe">
<MenuItem.Items>
<MenuItem Header="Über..." Click="MnuHelpAbout_Click"/>
</MenuItem.Items>
</MenuItem>
</Menu.Items>
</Menu>
<GroupBox Header="Empfänger" Grid.Row="1" Grid.RowSpan="3" Grid.Column="0" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button Content="Hinzufügen..." Margin="2,5,5,5" Width="80"/>
<Button Content="Bearbeiten..." Margin="5" Width="80"/>
<Button Content="Löschen..." Margin="5" Width="80"/>
</StackPanel>
<ListView x:Name="LvwRecipients" Grid.Row="1" Margin="2">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Empfänger" DisplayMemberBinding="{Binding Recipient}"/>
<GridViewColumn Header="Versendent am" DisplayMemberBinding="{Binding SentDate}"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Grid>
</GroupBox>
<GroupBox Header="Betreff" Grid.Row="1" Grid.Column="1" Margin="2">
<TextBox x:Name="TxtSubject" Margin="2"/>
</GroupBox>
<GroupBox Header="Text" Grid.Row="2" Grid.Column="1" Margin="2">
<TextBox x:Name="TxtBody" Margin="2"/>
</GroupBox>
<Button Content="Abschicken" Grid.Row="3" Grid.Column="1" Margin="10" Height="30" Click="BtnSend_Click"/>
</Grid>
</Window>

View File

@@ -1,6 +1,7 @@
using Massmailer.Shared.Events;
using Massmailer.Shared.Logic;
using Massmailer.Shared.Model;
using Microsoft.Win32;
using PubSub;
using System;
using System.Collections.Generic;
@@ -23,8 +24,9 @@ namespace Massmailer.UI
{
private readonly Hub hub = new Hub();
private SmtpSettings smtpSettings;
private MassmailerProject project;
private MassmailerProject project = new MassmailerProject();
private string selectedFilePath = string.Empty;
private bool isDirty = false;
public MainView()
{
@@ -32,7 +34,106 @@ namespace Massmailer.UI
this.hub.Subscribe<MailSentEvent>(this.MailSentEventHandler);
}
private async void Button_Click(object sender, RoutedEventArgs e)
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
this.smtpSettings = await SmtpSettingsLogic.Load(Path.Combine(Environment.CurrentDirectory, Constants.SmtpSettingsFileName));
}
private void MailSentEventHandler(MailSentEvent mailSentEvent)
{
//this.BtnSend.Content = $"mail sent: {mailSentEvent.Recipient} at {mailSentEvent.Timestamp}";
}
private void MnuFileNew_Click(object sender, RoutedEventArgs e)
{
if (this.isDirty)
{
var result = MessageBox.Show("Aktuelle Änderungen speichern?", "Massmailer", MessageBoxButton.YesNoCancel);
if (result == MessageBoxResult.Cancel)
{
return;
}
if (result == MessageBoxResult.Yes)
{
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath());
}
// TODO untested
this.project = new MassmailerProject();
this.DataContext = this.project;
this.Title = "Massmailer";
}
}
private async void MnuFileOpen_Click(object sender, RoutedEventArgs e)
{
if (this.isDirty)
{
var result = MessageBox.Show("Aktuelle Änderungen speichern?", "Massmailer", MessageBoxButton.YesNoCancel);
if (result == MessageBoxResult.Cancel)
{
return;
}
if (result == MessageBoxResult.Yes)
{
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath(false));
}
}
// TODO untested
var openFileDialog = new OpenFileDialog();
openFileDialog.DefaultExt = $".{Constants.ProjectFileExtension}";
openFileDialog.Filter = $"Massmailer Projekte|*.{Constants.ProjectFileExtension}|Alle Dateien|*.*";
if (openFileDialog.ShowDialog() == true)
{
this.project = await MassmailerProjectLogic.Load(openFileDialog.FileName);
this.DataContext = this.project;
this.selectedFilePath = openFileDialog.FileName;
this.Title = $"Massmailer - {openFileDialog.FileName}";
}
}
private void MnuFileSave_Click(object sender, RoutedEventArgs e)
{
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath(false));
}
private void MnuFileSaveAs_Click(object sender, RoutedEventArgs e)
{
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath(true));
}
private void MnuFileQuit_Click(object sender, RoutedEventArgs e)
{
if (this.isDirty)
{
var result = MessageBox.Show("Aktuelle Änderungen speichern?", "Massmailer", MessageBoxButton.YesNoCancel);
if (result == MessageBoxResult.Cancel)
{
return;
}
if (result == MessageBoxResult.Yes)
{
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath(false));
}
}
Application.Current.Shutdown();
}
private void MnuHelpAbout_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("todo");
}
private async void BtnSend_Click(object sender, RoutedEventArgs e)
{
var smtpSettings = new SmtpSettings
{
@@ -87,14 +188,20 @@ namespace Massmailer.UI
MessageBox.Show(result);
}
private void MailSentEventHandler(MailSentEvent mailSentEvent)
private string GetSaveFilePath(bool force)
{
this.BtnSend.Content = $"mail sent: {mailSentEvent.Recipient} at {mailSentEvent.Timestamp}";
}
if (string.IsNullOrEmpty(this.selectedFilePath) || force)
{
var savefileDialog = new SaveFileDialog();
savefileDialog.DefaultExt = $".{Constants.ProjectFileExtension}";
savefileDialog.Filter = $"Massmailer Projekte|*.{Constants.ProjectFileExtension}|Alle Dateien|*.*";
if (savefileDialog.ShowDialog() == true)
{
this.selectedFilePath = savefileDialog.FileName;
}
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
this.smtpSettings = await SmtpSettingsLogic.Load(Path.Combine(Environment.CurrentDirectory, Constants.SmtpSettingsFileName));
return this.selectedFilePath;
}
}
}