190525PX Workaround for DateTimePicker bug (not seeting MinDate/MaxDate), added fixed-point parse/gen for currency fields, removed "Finished" from LogEvent,
This commit is contained in:
parent
8b2b1f1c8f
commit
ceb8b552e9
33
Cronjob.cs
33
Cronjob.cs
|
@ -42,12 +42,34 @@ namespace dezentrale
|
|||
}
|
||||
private static void CheckSpawning(Member m)
|
||||
{
|
||||
if(m.Status == Member.eStatus.Greeted)
|
||||
if(m.Status != Member.eStatus.Greeted)
|
||||
{
|
||||
Console.WriteLine("status != GREETED");
|
||||
return;
|
||||
}
|
||||
{
|
||||
TimeSpan ts = DateTime.Now.Subtract(m.GreetedDate);
|
||||
if ((ts.TotalDays < 7) || (m.SpawnDate > DateTime.Now) || (m.PaymentsTotal < m.PaymentAmount) || (m.AccountBalance < 0))
|
||||
if (ts.TotalDays < 7)
|
||||
{
|
||||
Console.WriteLine("TotalDays < 7");
|
||||
return;
|
||||
|
||||
}
|
||||
if (m.SpawnDate > DateTime.Now)
|
||||
{
|
||||
Console.WriteLine("spawnDate > now");
|
||||
return;
|
||||
}
|
||||
if (m.PaymentsTotal < m.PaymentAmount)
|
||||
{
|
||||
Console.WriteLine("payments < paymentAmount");
|
||||
return;
|
||||
}
|
||||
if (m.AccountBalance < 0)
|
||||
{
|
||||
Console.WriteLine("accountbalance < 0");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Sending activation mail");
|
||||
m.StartLogEvent("Sending activation mail", LogEvent.eEventType.Activation, "automatic");
|
||||
//Send greetings mail, send mail to vorstand
|
||||
try
|
||||
|
@ -88,10 +110,11 @@ namespace dezentrale
|
|||
uint thisYear = (uint) DateTime.Now.Year;
|
||||
uint months = 0;
|
||||
DateTime lastDegrade = m.LastBalanceDegrade;
|
||||
if (lastDegrade < m.SpawnDate) lastDegrade = m.SpawnDate;
|
||||
while (lastDegrade.Month != thisMonth) { lastDegrade = lastDegrade.AddMonths(1); months++; }
|
||||
while(lastDegrade.Year < thisYear) { lastDegrade = lastDegrade.AddYears(1); months += 12; }
|
||||
m.StartLogEvent($"Membership fee: {months} Months * {m.PaymentAmount} EUR = {months * m.PaymentAmount} EUR", LogEvent.eEventType.MembershipFee, "automatic");
|
||||
m.AccountBalance -= (int) (((int) months) * m.PaymentAmount);
|
||||
m.StartLogEvent($"Membership fee: {months} Months * {m.PaymentAmount} EURcents = {months * m.PaymentAmount} EURcents", LogEvent.eEventType.MembershipFee, "automatic");
|
||||
m.AccountBalance -= (Int64) (((Int64) months) * (Int64) m.PaymentAmount);
|
||||
m.LastBalanceDegrade = DateTime.Now;
|
||||
m.SaveToFile();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace dezentrale
|
|||
{
|
||||
public class Program
|
||||
{
|
||||
public static uint VersionNumber { get; private set; } = 0x19052300;
|
||||
public static uint VersionNumber { get; private set; } = 0x19052500;
|
||||
public static string VersionString { get; private set; } = $"{VersionNumber:x}";
|
||||
|
||||
public static string AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace dezentrale.model
|
|||
+ "\n"
|
||||
+ "Hello {Nickname}!\n"
|
||||
+ "\n"
|
||||
+ "Welcome to the dezentrale Hackspace.\n"
|
||||
+ "Welcome to the dezentrale hackspace.\n"
|
||||
+ "Your membership number is {NumberString}.\n"
|
||||
+ "Please use this number in the topic of the bank wire transfers of your membership fees.\n"
|
||||
+ "Your membership account is active after 7 days, and after you paid the first membership fee.\n"
|
||||
|
|
|
@ -29,6 +29,5 @@ namespace dezentrale.model
|
|||
[XmlAttribute] public DateTime Timestamp { get; set; } = DateTime.Now;
|
||||
[XmlAttribute] public string LocalUser { get; set; } = Program.config.LocalUser;
|
||||
[XmlElement("SubEvent")] public List<LogSubEvent> SubEvents { get; set; } = new List<LogSubEvent>();
|
||||
[XmlAttribute] public bool Finished { get; set; } = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace dezentrale.model
|
|||
private eStatus status = eStatus.Uninitialized;
|
||||
private string remarks = "";
|
||||
private uint mvMiss = 0;
|
||||
private int accountBalance = 0;
|
||||
private Int64 accountBalance = 0;
|
||||
private string nickname = "";
|
||||
private string firstName = "";
|
||||
private string lastName = "";
|
||||
|
@ -59,7 +59,7 @@ namespace dezentrale.model
|
|||
private string pgpFingerprint = "";
|
||||
private bool mvInvitationByPost = false;
|
||||
private DateTime spawnDate;
|
||||
private uint paymentAmount = Program.config.RegularPaymentAmount;
|
||||
private UInt64 paymentAmount = Program.config.RegularPaymentAmount;
|
||||
private ePaymentClass paymentClass = ePaymentClass.Normal;
|
||||
private DateTime memberFormDate;
|
||||
|
||||
|
@ -73,7 +73,7 @@ namespace dezentrale.model
|
|||
[XmlElement] public eRole Role { get { return role; } set { LogPropertyChange("Role", role, value); role = value; } }
|
||||
[XmlElement] public string Remarks { get { return remarks; } set { LogPropertyChange("Remarks", remarks, value); remarks = value; } }
|
||||
[XmlElement] public uint MvMissCounter { get { return mvMiss; } set { LogPropertyChange("MvMissCounter", mvMiss, value); mvMiss = value; } }
|
||||
[XmlElement] public int AccountBalance { get { return accountBalance;}set{LogPropertyChange("AccountBalance",accountBalance,value);accountBalance=value;}}
|
||||
[XmlElement] public Int64 AccountBalance { get { return accountBalance;}set{LogPropertyChange("AccountBalance",accountBalance,value);accountBalance=value;}}
|
||||
|
||||
//personal data
|
||||
[XmlAttribute] public string Nickname { get { return nickname; } set { LogPropertyChange("NickName", nickname, value); nickname = value; } }
|
||||
|
@ -92,7 +92,7 @@ namespace dezentrale.model
|
|||
//membership organizational data
|
||||
[XmlElement] public bool MvInvitationByPost { get { return mvInvitationByPost; } set { LogPropertyChange("MvInvitationByPost", mvInvitationByPost, value); mvInvitationByPost = value; } }
|
||||
[XmlElement] public DateTime SpawnDate { get { return spawnDate; } set { LogPropertyChange("SpawnDate", spawnDate, value); spawnDate = value; } }
|
||||
[XmlElement] public uint PaymentAmount { get { return paymentAmount;} set { LogPropertyChange("PaymentAmount", paymentAmount, value); paymentAmount = value; } }
|
||||
[XmlElement] public UInt64 PaymentAmount { get { return paymentAmount;} set { LogPropertyChange("PaymentAmount", paymentAmount, value); paymentAmount = value; } }
|
||||
[XmlElement] public ePaymentClass PaymentClass { get { return paymentClass; } set { LogPropertyChange("PaymentClass", paymentClass, value); paymentClass = value; } }
|
||||
[XmlElement] public DateTime MemberFormDate { get { return memberFormDate; } set { LogPropertyChange("MemberFormDate", memberFormDate, value); memberFormDate = value;} }
|
||||
|
||||
|
@ -158,7 +158,6 @@ namespace dezentrale.model
|
|||
//if(CurrentLog == null) throw new Exception("Member.FinishLogEvent(): There is no log event open!");
|
||||
|
||||
this.LastChanged = CurrentLog.Timestamp;
|
||||
CurrentLog.Finished = true;
|
||||
CurrentLog = null;
|
||||
}
|
||||
public bool SaveToFile()
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace dezentrale.model
|
|||
{
|
||||
public class XmlData
|
||||
{
|
||||
[XmlElement] public DateTime LastChanged { get; set; } = DateTime.Now;
|
||||
[XmlAttribute] public DateTime LastChanged { get; set; } = DateTime.Now;
|
||||
/*
|
||||
[XmlIgnore]
|
||||
private static Type[] SerializeTypes =
|
||||
|
|
|
@ -110,7 +110,8 @@ namespace dezentrale.view
|
|||
subEvtList.ResumeLayout(true);
|
||||
ShowDetails(le);
|
||||
} else
|
||||
{
|
||||
{
|
||||
ShowDetails(null);
|
||||
subEvtList.Items.Clear();
|
||||
subEvtList.Enabled = false;
|
||||
}
|
||||
|
@ -135,6 +136,9 @@ namespace dezentrale.view
|
|||
ListViewItem lvi = sel[0];
|
||||
LogSubEvent se = (LogSubEvent)lvi.Tag;
|
||||
ShowDetails(se);
|
||||
} else
|
||||
{
|
||||
ShowDetails(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,8 +100,8 @@ namespace dezentrale.view
|
|||
Location = new Point(118, 2 * line),
|
||||
Width = 100,
|
||||
Format = DateTimePickerFormat.Short,
|
||||
MinDate = new DateTime(1900, 01, 01, 00, 00, 00),
|
||||
MaxDate = DateTime.Today,
|
||||
//MinDate = new DateTime(1900, 01, 01, 00, 00, 00),
|
||||
//MaxDate = DateTime.Today,
|
||||
});
|
||||
sc.Panel1.Controls.Add(new Label()
|
||||
{
|
||||
|
@ -221,8 +221,8 @@ namespace dezentrale.view
|
|||
Location = new Point(lm + 118, 6 * line + tm),
|
||||
Width = 100,
|
||||
Format = DateTimePickerFormat.Short,
|
||||
MinDate = new DateTime(1900, 01, 01, 00, 00, 00),
|
||||
MaxDate = DateTime.Today.AddYears(2),
|
||||
//MinDate = new DateTime(1900, 01, 01, 00, 00, 00),
|
||||
//MaxDate = DateTime.Today.AddYears(2),
|
||||
});
|
||||
parent.Controls.Add(new Label()
|
||||
{
|
||||
|
@ -257,8 +257,8 @@ namespace dezentrale.view
|
|||
Location = new Point(lm + 118, 8 * line + tm),
|
||||
Width = 100,
|
||||
Format = DateTimePickerFormat.Short,
|
||||
MinDate = new DateTime(1900, 01, 01, 00, 00, 00),
|
||||
MaxDate = DateTime.Today,
|
||||
//MinDate = new DateTime(1900, 01, 01, 00, 00, 00),
|
||||
//MaxDate = DateTime.Today,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -399,6 +399,29 @@ namespace dezentrale.view
|
|||
parent.Controls.Add(btnOk);
|
||||
}
|
||||
|
||||
private static string Int64FPToString(Int64 value)
|
||||
{
|
||||
|
||||
Int64 intPart = value / 100;
|
||||
Int64 decPart = (intPart < 0 ? -1 : 1) * (value % 100);
|
||||
return $"{intPart},{decPart:D2}";
|
||||
}
|
||||
private static Int64 StringToInt64FP(string value)
|
||||
{
|
||||
if (value == null) return 0;
|
||||
if (!value.Contains('.') && !value.Contains(','))
|
||||
{
|
||||
return Convert.ToInt64(value);
|
||||
}
|
||||
|
||||
int i = value.IndexOf('.');
|
||||
if (i < 0) i = value.IndexOf(',');
|
||||
string intPart = value.Substring(0, i);
|
||||
string decPart = value.Substring(i + 1);
|
||||
|
||||
Int64 ip64 = Convert.ToInt64(intPart);
|
||||
return (ip64 * 100) + (ip64 > 0 ? Convert.ToInt64(decPart) : -Convert.ToInt64(decPart));
|
||||
}
|
||||
public frmEditEntry(Member m, bool newMember = false)
|
||||
{
|
||||
|
||||
|
@ -449,7 +472,7 @@ namespace dezentrale.view
|
|||
}
|
||||
try { dateSpawn.Value = member.SpawnDate; }
|
||||
catch (Exception) { if (!newMember) { MessageBox.Show("Invalid SpawnDate: " + member.SpawnDate + "!"); } }
|
||||
tbPaymentAmount.Text = $"{member.PaymentAmount}";
|
||||
tbPaymentAmount.Text = Int64FPToString((Int64) member.PaymentAmount);
|
||||
chkPaymentReduced.Checked = member.PaymentClass == Member.ePaymentClass.Reduced;
|
||||
try { dateMemberForm.Value = member.MemberFormDate; }
|
||||
catch (Exception) { if (!newMember) { MessageBox.Show("Invalid MemberFormDate: " + member.MemberFormDate + "!"); } }
|
||||
|
@ -466,7 +489,7 @@ namespace dezentrale.view
|
|||
}
|
||||
|
||||
tbMvMiss.Text = $"{member.MvMissCounter}";
|
||||
tbAccountBalance.Text = $"{member.AccountBalance}";
|
||||
tbAccountBalance.Text = Int64FPToString(member.AccountBalance);
|
||||
tbRemarks.Text = member.Remarks;
|
||||
this.ResumeLayout(false);
|
||||
}
|
||||
|
@ -503,7 +526,14 @@ namespace dezentrale.view
|
|||
member.Type = (Member.eType)kv.Value;
|
||||
}
|
||||
member.SpawnDate = dateSpawn.Value;
|
||||
member.PaymentAmount = Convert.ToUInt32(tbPaymentAmount.Text);
|
||||
try
|
||||
{
|
||||
member.PaymentAmount = (UInt64) StringToInt64FP(tbPaymentAmount.Text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Cannot convert Payment Amount to fixed point value:\n{ex.Message}");
|
||||
}
|
||||
member.PaymentClass = chkPaymentReduced.Checked ? Member.ePaymentClass.Reduced : Member.ePaymentClass.Normal;
|
||||
member.MemberFormDate = dateMemberForm.Value;
|
||||
|
||||
|
@ -521,7 +551,13 @@ namespace dezentrale.view
|
|||
member.Role = (Member.eRole)kv.Value;
|
||||
}
|
||||
member.MvMissCounter = Convert.ToUInt32(tbMvMiss.Text);
|
||||
member.AccountBalance = Convert.ToInt32(tbAccountBalance.Text);
|
||||
try
|
||||
{
|
||||
member.AccountBalance = StringToInt64FP(tbAccountBalance.Text);//Convert.ToInt32(tbAccountBalance.Text);
|
||||
} catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Cannot convert Account balance to fixed point value:\n{ex.Message}");
|
||||
}
|
||||
member.Remarks = tbRemarks.Text;
|
||||
|
||||
member.FinishLogEvent();
|
||||
|
|
Loading…
Reference in New Issue