public static void AddToCharts(Consumer c) { if(c.ListedInCharts) { c.MakeTotalChartDrinks(); AddToSubList(c.TotalChartDrinks, c); } }
public static int GetRank(Consumer c) { int rank = chartList.Count; foreach(List<Consumer> subList in chartList.Values) { if(subList.Contains(c)) return rank; rank--; } throw new Exception("User not listed in Charts!"); }
private static void AddToSubList(int key, Consumer c) { List<Consumer> subList; if(chartList.TryGetValue(key, out subList)) subList.Add(c); else { subList = new List<Consumer>(); subList.Add(c); chartList.Add(key, subList); } }
public static int GetTotalChartDrinks(Consumer c) { int i = 0; foreach(Consumed con in c.History) { try { Item itm = Items.Find(x => x.ID == con.ItemID); if (itm!=null&&itm.Coleurfaehig) i++; } catch { } } return i; }
public static int GetDeficite(Consumer consumer) { int key = consumer.TotalChartDrinks; int place = chartList.IndexOfKey(key); int advancedDrinks = chartList.Keys[place+1]; return advancedDrinks - key; }
private void AddPersonToPresentList(Consumer c, DateTime logoutDate = default(DateTime)) { if (c.Gesperrt) { LoginBox lb = new LoginBox(c.Name); if (!lb.ShowDialog() == true) return; } PresentPersons.Add(c); AllPersons.Remove(c); if(logoutDate == default(DateTime)) logoutDate = SetLogoutTime(c); Bierstrichler.Properties.Settings.Default.LoggedInUsers.Add(c.ID.ToString() + ";" + logoutDate.ToString()); CreateLogoutTimer(c.ID, logoutDate); Bierstrichler.Properties.Settings.Default.Save(); Log.WriteInformation(App.CurrentVendor.Name + " moved " + c.Name + " to Present List."); }
public static int GetAdvance(Consumer consumer) { int key = consumer.TotalChartDrinks; int place = chartList.IndexOfKey(key); int advancedDrinks = chartList.Keys[place - 1]; return key - advancedDrinks; }
/// <summary> /// Legt den Logoutzeitpunkt für den Nutzer anhand seiner Einstellungen fest. /// </summary> /// <param name="lout"></param> public static DateTime SetLogoutTime(Consumer c) { DateTime lout = DateTime.Now; switch (c.LogoutBehavior) { case Enums.LogoutBehavior.Never: return DateTime.MaxValue; case Enums.LogoutBehavior.OneHour: return lout.AddHours(1); case Enums.LogoutBehavior.TenMinutes: return lout.AddMinutes(10); case Enums.LogoutBehavior.TheNextMorning: return new DateTime(lout.Year, lout.Month, lout.Hour >= 8 ? lout.Day + 1 : lout.Day, 8, 0, 0); case Enums.LogoutBehavior.ThirtyMinutes: return lout.AddMinutes(30); case Enums.LogoutBehavior.ThreeHours: return lout.AddHours(3); default: throw new ArgumentException("No valid Logout Behavior"); } }
private static string SetValuesInPlaceHolders(string s, Consumer c, DateTime invoiceDate, List<Data.Items.Consumed> conList) { s = regRegion.Replace(s, delegate(Match m) { try { if (m.Groups["tag"].Value.Equals("ConsumedItems")) { string historyPart = m.Groups["inner"].Value; return AddHistoryToMail(historyPart.Trim(), conList); } return ""; } catch (Exception e) { return "MAKE HISTORY FAILED!"; } }); return SetValuesInPlaceHolders(s, c); }
/// <summary> /// Creates the invoice mail to the Consumer c using the invoiceDate. /// </summary> /// <param name="c"></param> /// <param name="invoiceDate"></param> /// <returns>null if the user did not have any consumed items</returns> private static MailMessage CreateInvoiceMail(Consumer c, DateTime invoiceDate) { MailMessage m = new MailMessage(); m.From = new MailAddress(MailAddress); m.To.Add(new MailAddress(c.Email)); m.Subject = "Deine Bierrechnung vom " + DateTime.Now.ToString("dd. M. yyyy"); m.IsBodyHtml = true; List<Data.Items.Consumed> conList = c.History.FindAll(x => x.Date > invoiceDate); if (conList.Count > 0) { Log.WriteDebug("Sending invoice to " + c.Email + "with " + conList.Count + " entries."); m.Body = SetValuesInPlaceHolders(File.ReadAllText(MailFolder + @"\standardInvoice.html", Encoding.Default), c, invoiceDate, conList); } else { Log.WriteDebug("Nothing to send to " + c.Email + "."); m = null; } return m; }
public static void SendInvoiceAsync(Consumer c, DateTime invoiceDate) { MailMessage m = CreateInvoiceMail(c, invoiceDate); if (m != null) SendMailScheduled(m); }
public static void SendInvoice(Consumer c, DateTime invoiceDate) { MailMessage m = CreateInvoiceMail(c, invoiceDate); SendMailNow(m); }