200831PX frmPaymentReceipts: Added controls for email sending and member selection. Disabled OK button for invalid date settings

This commit is contained in:
phantomix 2020-08-31 17:57:17 +02:00
parent c12e86fbd2
commit bebb27a786
5 changed files with 88 additions and 60 deletions

View File

@ -44,7 +44,7 @@ namespace dezentrale
{
public class Program
{
public static uint VersionNumber { get; private set; } = 0x20082500;
public static uint VersionNumber { get; private set; } = 0x20083100;
public static string VersionString { get; private set; } = $"{VersionNumber:x}";
public static string AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

View File

@ -26,52 +26,6 @@ namespace dezentrale.model
}
}
/*public FormMail ReplaceReflect(object o)
{
FormMail ret = new FormMail(this);
PropertyInfo[] objProperties = o.GetType().GetProperties();
foreach (var mailProperty in ret.GetType().GetProperties())
{
if (mailProperty.PropertyType != typeof(string)) continue;
if (!mailProperty.CanRead) continue;
if (!mailProperty.CanWrite) continue;
string propVal = (string)mailProperty.GetValue(ret, null);
if (propVal == null) continue;
bool changed = false;
foreach (var objProperty in objProperties)
{
if (!objProperty.CanRead) continue;
//check if objProperty occurs in mailProperty contents, then replace
string token = $"{{{objProperty.Name}}}";
string tokenValue;
try
{
tokenValue = objProperty.GetValue(o, null).ToString();
} catch(NullReferenceException)
{
//Console.WriteLine($"FormMail.ReplaceReflect({o}): property {token}: {ex.Message}");
continue;
}
if (propVal.Contains(token))
{
//NOTE: This is problematic because it allows the user to generate recursive replacements by setting e.g. the Nickname to "{PgpFingerprint}"
propVal = propVal.Replace(token, tokenValue);
changed = true;
}
}
if (changed)
{
mailProperty.SetValue(ret, propVal, null);
}
}
return ret;
}*/
public LogSubEvent Send(object replaceReflect = null, List<string> files = null)
{
FormMail src = replaceReflect == null ? this : ReplaceReflect(replaceReflect);

View File

@ -18,27 +18,29 @@ namespace dezentrale.view
protected const int labelHeight = 14;
protected const int labelOffs = 3;
protected Button btnOk, btnCancel;
protected void AddOkCancel(Control parent, EventHandler okEvent, EventHandler cancelEvent, bool writeEnabled = true)
{
//Console.WriteLine($"frmMoneyTransfer.AddOkCancel(writeEnabled={writeEnabled})");
Button ok = new Button()
btnOk = new Button()
{
Text = "OK",
Location = new System.Drawing.Point(parent.Width - 160 - rm, parent.Height - 57),
Anchor = AnchorStyles.Right | AnchorStyles.Bottom,
Enabled = writeEnabled,
};
if (writeEnabled) ok.Click += okEvent;
if (writeEnabled) btnOk.Click += okEvent;
Button cancel = new Button()
btnCancel = new Button()
{
Text = "Cancel",
Location = new System.Drawing.Point(parent.Width - 75 - rm, parent.Height - 57),
Anchor = AnchorStyles.Right | AnchorStyles.Bottom,
};
cancel.Click += cancelEvent;
parent.Controls.Add(ok);
parent.Controls.Add(cancel);
btnCancel.Click += cancelEvent;
parent.Controls.Add(btnOk);
parent.Controls.Add(btnCancel);
}
}
}

View File

@ -246,13 +246,16 @@ namespace dezentrale.view
List<Member> sel = lstMembers.GetSelectedItems();
frmPaymentReceipts receipts = new frmPaymentReceipts()
{
//Defaults that will be edited by the user
MemberList = (sel != null && sel.Count > 0) ? sel : null,
DataTemplate = "dezentrale-beitragsquittung-template.svg",
DataFormat = IntermediateFormat.SvgInkscape092,
StartDate = new DateTime(year, 01, 01),
EndDate = new DateTime(year, 12, 31),
FileNamePattern = "Member{MemberNumber}-{ValutaDateString}-{AmountString}{Currency}",
OutputDirectory="."
OutputDirectory=".",
SendEmail = false
};
DialogResult dr = receipts.ShowDialog();
if(dr == DialogResult.OK)

View File

@ -9,6 +9,26 @@ using dezentrale.model.money;
namespace dezentrale.view
{
class DateTimePickerWithBg : DateTimePicker
{
const int WM_ERASEBKGND = 0x14;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == WM_ERASEBKGND)
{
using (var g = Graphics.FromHdc(m.WParam))
{
using (var b = new SolidBrush(this.BackColor))
{
g.FillRectangle(b, ClientRectangle);
}
}
return;
}
base.WndProc(ref m);
}
}
public class frmPaymentReceipts : FormWithOkCancel, IPaymentReceiptProcessData
{
public List<Member> MemberList { get; set; } = null;
@ -26,8 +46,8 @@ namespace dezentrale.view
private ComboBox cbDataFormat;
private TextBox tbOutputDirectory;
private TextBox tbFileNamePattern;
private DateTimePicker dtStartDate;
private DateTimePicker dtEndDate;
private DateTimePickerWithBg dtStartDate;
private DateTimePickerWithBg dtEndDate;
private RadioButton optAllMembers;
private RadioButton optSelectedMembers;
private CheckBox chkSendEmail;
@ -36,8 +56,8 @@ namespace dezentrale.view
{
DialogResult = DialogResult.Cancel;
this.StartPosition = FormStartPosition.CenterParent;
this.Size = new System.Drawing.Size(483, 245);
this.MinimumSize = new System.Drawing.Size(455, 245);
this.Size = new System.Drawing.Size(483, 310);
this.MinimumSize = new System.Drawing.Size(455, 310);
this.Text = "Generate payment receipts";
this.Controls.Add(new Label()
{
@ -124,7 +144,7 @@ namespace dezentrale.view
Size = new Size(110, labelHeight),
TextAlign = ContentAlignment.BottomRight,
});
this.Controls.Add(dtStartDate = new DateTimePicker()
this.Controls.Add(dtStartDate = new DateTimePickerWithBg()
{
Location = new Point(lm + 113, 4 * line + tm),
Width = 100,
@ -137,6 +157,8 @@ namespace dezentrale.view
Size = new Size(110, labelHeight),
TextAlign = ContentAlignment.BottomRight,
});
dtStartDate.ValueChanged += dt_Changed;
this.Controls.Add(new Label()
{
@ -145,7 +167,7 @@ namespace dezentrale.view
Size = new Size(110, labelHeight),
TextAlign = ContentAlignment.BottomRight,
});
this.Controls.Add(dtEndDate = new DateTimePicker()
this.Controls.Add(dtEndDate = new DateTimePickerWithBg()
{
Location = new Point(lm + 113, 5 * line + tm),
Width = 100,
@ -158,6 +180,27 @@ namespace dezentrale.view
Size = new Size(110, labelHeight),
TextAlign = ContentAlignment.BottomRight,
});
dtEndDate.ValueChanged += dt_Changed;
this.Controls.Add(optAllMembers = new RadioButton()
{
Text = "Für alle Mitglieder durchführen",
Width = 300,
Location = new Point(lm + 113, 6 * line + tm),
});
this.Controls.Add(optSelectedMembers = new RadioButton()
{
Text = "Für die ausgewählten Mitglieder durchführen",
Width = 300,
Location = new Point(lm + 113, 7 * line + tm),
});
this.Controls.Add(chkSendEmail = new CheckBox()
{
Text = "Die erstellten Dateien per E-Mail senden",
Width = 300,
Location = new Point(lm + 113, 8 * line + tm),
});
AddOkCancel(this, btnOK_Click, btnCancel_Click);
@ -171,6 +214,14 @@ namespace dezentrale.view
tbFileNamePattern.Text = FileNamePattern;
dtStartDate.Value = StartDate;
dtEndDate.Value = EndDate;
if (MemberList != null && MemberList.Count > 0)
optSelectedMembers.Checked = true;
else
{
optAllMembers.Checked = true;
optSelectedMembers.Enabled = false;
}
chkSendEmail.Checked = SendEmail;
};
}
@ -194,6 +245,22 @@ namespace dezentrale.view
}
}
private void dt_Changed(object sender, EventArgs e)
{
if(dtStartDate.Value.CompareTo(dtEndDate.Value) > 0)
{
dtStartDate.BackColor = Color.LightYellow;
dtEndDate.BackColor = Color.LightYellow;
btnOk.Enabled = false;
} else
{
dtStartDate.BackColor = Color.White;
dtEndDate.BackColor = Color.White;
btnOk.Enabled = true;
}
}
private void btnOK_Click(object sender, EventArgs e)
{
DataTemplate = tbTemplate.Text;
@ -202,6 +269,8 @@ namespace dezentrale.view
FileNamePattern = tbFileNamePattern.Text;
StartDate = dtStartDate.Value;
EndDate = dtEndDate.Value.AddSeconds(24*60*60 - 1);
if (optSelectedMembers.Checked != true) MemberList = null;
SendEmail = chkSendEmail.Checked;
DialogResult = DialogResult.OK;
this.Close();
}