// Gets the working hours for the user // in the interval from 'start' to 'end' date public int GetWorkingHoursForInterval(System.DateTime start, System.DateTime end) { string queryString = "SELECT * FROM ZeitBuchung WHERE MId = ? AND Datum >= ? AND Datum <= ? AND TypId = ? ORDER BY Datum ASC"; NPathQuery npathQuery = new NPathQuery(queryString, typeof(ZeitBuchung)); npathQuery.Parameters.Add(new QueryParameter(DbType.Int32, userId)); npathQuery.Parameters.Add(new QueryParameter(DbType.DateTime, start)); npathQuery.Parameters.Add(new QueryParameter(DbType.DateTime, end)); npathQuery.Parameters.Add(new QueryParameter(DbType.Int32, ZeitBuchung.ZBTypToInt(ZeitBuchung.ZBTyp.KOMMEN))); System.Collections.IList l = npcontext.GetObjectsByNPath(npathQuery); int h = 0; foreach (ZeitBuchung b in l) { ZeitBuchung a = GetCorrespondingZeitBuchungFor(b); if (a == null) { continue; } h += a.GetHourDiff(b); } return(h); }
// Creates a new Zeitbuchung for now. public void NewZeitBuchungForNow(ZeitBuchung.ZBTyp typ) { if (!userLoggedIn) { return; } ZeitBuchung a = GetLastZeitBuchung(); switch (typ) { case ZeitBuchung.ZBTyp.GEHEN: if (a == null || a.Typ != ZeitBuchung.ZBTyp.KOMMEN) { return; } break; case ZeitBuchung.ZBTyp.KOMMEN: if (a != null && a.Typ != ZeitBuchung.ZBTyp.GEHEN) { return; } break; } ZeitBuchung b = npcontext.CreateObject <ZeitBuchung>(); b.Mid = userId; b.Typ = typ; b.Datum = System.DateTime.Now; npcontext.CommitObject(b); }
// Gets the time difference in hours for the current and // a supplied ZeitBuchung public int GetHourDiff(ZeitBuchung b) { System.TimeSpan d; if (b.Datum > Datum) { d = b.Datum - Datum; } else { d = Datum - b.Datum; } return(d.Hours); }
// Gets the corresponding ZeitBuchung for the supplied parameter ZeitBuchung. // E.g. if the "Gehen" Buchung is supplied, the method returns // the corresponding "Kommen" Buchung and vice versa. public ZeitBuchung GetCorrespondingZeitBuchungFor(ZeitBuchung b) { if (!userLoggedIn) { return(null); } if (b == null) { return(null); } ZeitBuchung erg = null; string queryString = null; NPathQuery npathQuery = null; if (b.Typ == ZeitBuchung.ZBTyp.GEHEN) { queryString = "SELECT TOP 1 * FROM ZeitBuchung WHERE MId = ? AND Datum < ? AND TypId = ? ORDER BY Datum DESC"; npathQuery = new NPathQuery(queryString, typeof(ZeitBuchung)); npathQuery.Parameters.Add(new QueryParameter(DbType.Int32, userId)); npathQuery.Parameters.Add(new QueryParameter(DbType.DateTime, b.Datum)); npathQuery.Parameters.Add(new QueryParameter(DbType.Int32, ZeitBuchung.ZBTypToInt(ZeitBuchung.ZBTyp.KOMMEN))); } if (b.Typ == ZeitBuchung.ZBTyp.KOMMEN) { queryString = "SELECT TOP 1 * FROM ZeitBuchung WHERE MId = ? AND Datum > ? AND TypId = ? ORDER BY Datum ASC"; npathQuery = new NPathQuery(queryString, typeof(ZeitBuchung)); npathQuery.Parameters.Add(new QueryParameter(DbType.Int32, userId)); npathQuery.Parameters.Add(new QueryParameter(DbType.DateTime, b.Datum)); npathQuery.Parameters.Add(new QueryParameter(DbType.Int32, ZeitBuchung.ZBTypToInt(ZeitBuchung.ZBTyp.GEHEN))); } if (npathQuery == null) { return(null); } try { erg = (ZeitBuchung)npcontext.GetObjectByNPath(npathQuery); } catch (Exception e) { } return(erg); }
// Get the last 5 ZeitBuchungen for the user public ZeitBuchung[] GetRecentZeitBuchungen() { if (!userLoggedIn) { return(null); } string queryString = "SELECT * FROM Mitarbeiter WHERE MId = ? ORDER BY Datum DESC"; NPathQuery npathQuery = new NPathQuery(queryString, typeof(ZeitBuchung)); npathQuery.Parameters.Add(new QueryParameter(DbType.Int32, userId)); ZeitBuchung[] erg = null; try { System.Collections.IList l = npcontext.GetObjectsByNPath(npathQuery); erg = new ZeitBuchung[l.Count]; l.CopyTo(erg, 0); } catch (Exception e) { } return(erg); }
// Gets the last registered ZeitBuchung for the user public ZeitBuchung GetLastZeitBuchung() { if (!userLoggedIn) { return(null); } string queryString = "SELECT TOP 1 * FROM Mitarbeiter WHERE MId = ? ORDER BY Datum DESC"; NPathQuery npathQuery = new NPathQuery(queryString, typeof(ZeitBuchung)); npathQuery.Parameters.Add(new QueryParameter(DbType.Int32, userId)); ZeitBuchung erg = null; try { erg = (ZeitBuchung)npcontext.GetObjectByNPath(npathQuery); } catch (Exception e) { } return(erg); }