// 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);
        }
        // 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);
        }