public static bool appHasConflict(DateTime startTime, DateTime endTime) { foreach (var app in SqlUpdater.getAppointments().Values) { if (startTime < DateTime.Parse(app["end"].ToString()) && DateTime.Parse(app["start"].ToString()) < endTime) { return(true); } } return(false); }
public static Array getReport() { List <AppReport> appReports = new List <AppReport>(); List <Hashtable> appTypes = new List <Hashtable>(); SortedList months = new SortedList(); months.Add(1, "Janurary"); months.Add(2, "Feburary"); months.Add(3, "March"); months.Add(4, "April"); months.Add(5, "May"); months.Add(6, "June"); months.Add(7, "July"); months.Add(8, "August"); months.Add(9, "September"); months.Add(10, "October"); months.Add(11, "November"); months.Add(12, "December"); foreach (var app in SqlUpdater.getAppointments().Values) { int appMonth = DateTime.Parse(app["start"].ToString()).Month; bool duplicate = false; foreach (AppReport r in appReports) { if (r.month == months[appMonth].ToString() && r.appType == app["type"].ToString()) { duplicate = true; } } if (!duplicate) { AppReport appReport = new AppReport(); appReport.month = months[appMonth].ToString(); appReport.appType = app["type"].ToString(); appReport.quantity = SqlUpdater.getAppointments().Where(i => i.Value["type"].ToString() == app["type"].ToString() && DateTime.Parse(i.Value["start"].ToString()).Month == appMonth).Count(); appReports.Add(appReport); } } var appointmentArray = from row in appReports select new { Month = row.month, Type = row.appType, Quantity = row.quantity }; return(appointmentArray.ToArray()); }
public static Array getReport() { Dictionary <int, Hashtable> userReport = SqlUpdater.getAppointments(); var appointmentArray = from row in userReport select new { UserName = row.Value["username"], Type = row.Value["type"], StartTime = SqlUpdater.convertToTimezone(row.Value["start"].ToString()), EndTime = SqlUpdater.convertToTimezone(row.Value["start"].ToString()), Customer = row.Value["customerName"] }; return(appointmentArray.ToArray()); }
public static DataTable getReport() { Dictionary <int, Hashtable> appointments = SqlUpdater.getAppointments(); DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add("customer"); dt.Columns.Add("appointments"); IEnumerable <string> customers = appointments.Select(i => i.Value["customerName"].ToString()).Distinct(); foreach (string customer in customers) { DataRow row = dt.NewRow(); row["customer"] = customer; row["appointments"] = appointments.Where(i => i.Value["customerName"].ToString() == customer.ToString()).Count().ToString(); dt.Rows.Add(row); } return(dt); }
static public Array getCalendar(bool weekView) { MySqlConnection c = new MySqlConnection(SqlUpdater.conString); c.Open(); string query = $"SELECT customerId, type, start, end, appointmentId, userId FROM appointment WHERE userid = '{SqlUpdater.getCurrentUserID()}'"; MySqlCommand cmd = new MySqlCommand(query, c); MySqlDataReader rdr = cmd.ExecuteReader(); Dictionary <int, Hashtable> appointments = SqlUpdater.getAppointments();//new Dictionary<int, Hashtable>(); while (rdr.Read()) { Hashtable appointment = new Hashtable(); appointment.Add("customerId", rdr[0]); appointment.Add("type", rdr[1]); appointment.Add("start", rdr[2]); appointment.Add("end", rdr[3]); appointment.Add("userId", rdr[5]); appointment.Add(Convert.ToInt32(rdr[4]), appointment); } rdr.Close(); foreach (var app in appointments.Values) { query = $"SELECT userName FROM user WHERE userId = '{app["userId"]}'"; cmd = new MySqlCommand(query, c); rdr = cmd.ExecuteReader(); rdr.Read(); app.Add("userName", rdr[0]); rdr.Close(); } foreach (var app in appointments.Values) { query = $"SELECT customerName FROM customer WHERE customerId = '{app["customerId"]}'"; cmd = new MySqlCommand(query, c); rdr = cmd.ExecuteReader(); rdr.Read(); app.Add("customerName", rdr[0]); rdr.Close(); } Dictionary <int, Hashtable> parsedAppointments = new Dictionary <int, Hashtable>(); foreach (var app in appointments) { DateTime startTime = DateTime.Parse(app.Value["start"].ToString()); DateTime endTime = DateTime.Parse(app.Value["end"].ToString()); DateTime today = DateTime.UtcNow; if (weekView) { DateTime sunday = today.AddDays(-(int)today.DayOfWeek); DateTime saturday = today.AddDays(-(int)today.DayOfWeek + (int)DayOfWeek.Saturday); if (startTime >= sunday && endTime < saturday) { parsedAppointments.Add(app.Key, app.Value); } } else { DateTime firstDayOfMonth = new DateTime(today.Year, today.Month, 1); DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); if (startTime >= firstDayOfMonth && endTime < lastDayOfMonth) { parsedAppointments.Add(app.Key, app.Value); } } } SqlUpdater.setAppointments(appointments); var appointmentArray = from row in parsedAppointments select new { ID = row.Key, Type = row.Value["type"], StartTime = SqlUpdater.convertToTimezone(row.Value["start"].ToString()), EndTime = SqlUpdater.convertToTimezone(row.Value["end"].ToString()), Customer = row.Value["customerName"] }; c.Close(); return(appointmentArray.ToArray()); }