Ejemplo n.º 1
0
        // Her laves liste LessThanThree med klasselokaler hentet fra DB. Denne liste bruges til
        // algoritmesammenligningen. LessThanThree refererer til at objekterne kun skal blive på
        // listen så længe groupCount er under 3.
        public List <ClassRoom> LessThanThree()
        {
            List <ClassRoom> LessThanThree = new List <ClassRoom>();

            using (var con = new DBCon())
            {
                SqlDataReader rs = con.ExecuteStringGet("SELECT * FROM ClassRoom");

                int    tempId        = 0;
                string tempName      = null;
                int    tempSize      = 0;
                bool   bitWhiteboard = false;
                bool   bitMonitor    = false;
                bool   bitProjector  = false;
                int    requestMatch  = 0;
                int    groupCount    = 0;
                int    spaceLeft     = 0;

                if (rs.HasRows)
                {
                    while (rs.Read())
                    {
                        tempId        = (int)rs.GetValue(0);
                        tempName      = rs.GetString(1);
                        tempSize      = (int)rs.GetValue(2);
                        bitWhiteboard = (bool)rs.GetValue(3);
                        bitMonitor    = (bool)rs.GetValue(4);
                        bitProjector  = (bool)rs.GetValue(5);

                        requestMatch = CreateBinaryCode(bitWhiteboard, bitMonitor, bitProjector);

                        ClassRoom classroom = new ClassRoom(tempId, tempSize, tempName, requestMatch, spaceLeft, groupCount);
                        LessThanThree.Add(classroom);
                    }
                }
            }
            return(LessThanThree);
        }
Ejemplo n.º 2
0
        public bool HasGroupRooms()
        {
            bool hasRooms = false;

            using (var con = new DBCon())
            {
                string        dbCommand = "SELECT GroupRoom.id FROM GroupRoom LEFT JOIN Rent ON GroupRoom.id = Rent.GroupRoomId WHERE Rent.GroupRoomId IS NULL";
                SqlDataReader rs        = con.ExecuteStringGet(dbCommand);

                while (rs.Read())
                {
                    if (rs.HasRows)
                    {
                        hasRooms = true;
                    }
                    else
                    {
                        hasRooms = false;
                    }
                }
            }
            return(hasRooms);
        }
Ejemplo n.º 3
0
        public Class GetClassFromStudentId(int id)
        {
            Class tempClass = null;

            using (var con = new DBCon())
            {
                SqlDataReader rs = con.ExecuteStringGet("SELECT * FROM Class where id=(SELECT classId FROM Student where id=" + id + ");");

                int    tempId   = 0;
                string tempName = null;
                if (rs.HasRows)
                {
                    while (rs.Read())
                    {
                        tempId   = (int)rs.GetValue(0);
                        tempName = rs.GetString(1);
                    }
                }

                tempClass = new Class(tempId, tempName);
            }
            return(tempClass);
        }
Ejemplo n.º 4
0
        public int CreateBinaryCode(bool whiteboard, bool monitor, bool projector)
        {
            int requestCode = 0;

            using (var con = new DBCon())
            {
                if (whiteboard)
                {
                    requestCode += 4;
                }

                if (monitor)
                {
                    requestCode += 2;
                }

                if (projector)
                {
                    requestCode += 1;
                }
            }
            return(requestCode);
        }
Ejemplo n.º 5
0
        internal bool UpdateGroupRoom(string name, bool whiteboard, bool monitor)
        {
            bool didUpdate = false;

            using (var con = new DBCon())
            {
                int whiteboardBit = 0;
                int monitorBit    = 0;

                if (whiteboard)
                {
                    whiteboardBit = 1;
                }
                if (monitor)
                {
                    monitorBit = 1;
                }

                string sqlCommand = string.Format("UPDATE GroupRoom SET whiteboard={0}, monitor={1} WHERE name='{2}'", whiteboardBit, monitorBit, name);
                didUpdate = con.ExecuteStringPut(sqlCommand);
            }
            return(didUpdate);
        }
Ejemplo n.º 6
0
        public bool RentClassRoom(int classRoomId, int groupId, DateTime startDate, DateTime endDate)
        {
            bool rentCreated = false;

            using (var con = new DBCon())
            {
                string sqlCmd = string.Format(
                    "INSERT INTO Rent(ClassRoomID, GroupID, StartDate, EndDate) " +
                    "OUTPUT INSERTED.id " +
                    "VALUES('{0}', '{1}', '{2}', '{3}');", classRoomId, groupId, startDate.ToString("s"), endDate.ToString("s"));

                SqlDataReader rs = con.ExecuteStringGet(sqlCmd);

                while (rs.Read())
                {
                    if (rs.GetValue(0) != null)
                    {
                        rentCreated = true;
                    }
                }
            }
            return(rentCreated);
        }
Ejemplo n.º 7
0
        public bool RentGroupRoom(int grouproomId, int groupId, DateTime dateStart, DateTime dateEnd)
        {
            bool isRented = false;

            using (var con = new DBCon())
            {
                string sqlCmd = string.Format(
                    "INSERT INTO Rent(GroupRoomID, GroupID, StartDate, EndDate) " +
                    "OUTPUT INSERTED.id " +
                    "VALUES('{0}', '{1}', '{2}', '{3}');", grouproomId, groupId, dateStart, dateEnd);

                SqlDataReader rs = con.ExecuteStringGet(sqlCmd);

                while (rs.Read())
                {
                    if (rs.GetValue(0) != null)
                    {
                        isRented = true;
                    }
                }
            }
            return(isRented);
        }
Ejemplo n.º 8
0
        //takes boolbits from DB and creates a binary code to int... Denne metode skal bruges når DB-table
        // over classRoomWaitingList skal omskrives til objekter. Objektet skal dannes som et
        //  RequestClassroom med denne property requestCode.
        public List <RequestClassroom> GetAllRequests()
        {
            List <RequestClassroom> stillNotFulfilled = new List <RequestClassroom>();

            using (var con = new DBCon())
            {
                SqlDataReader rs = con.ExecuteStringGet("SELECT * FROM ClassRoomWaitinglist");

                int  tempId        = 0;
                int  tempGroupId   = 0;
                int  tempSize      = 0;
                int  requestCode   = 0;
                bool bitWhiteboard = false;
                bool bitMonitor    = false;
                bool bitProjector  = false;

                if (rs.HasRows)
                {
                    while (rs.Read())
                    {
                        tempId        = (int)rs.GetValue(0);
                        tempGroupId   = (int)rs.GetValue(1);
                        tempSize      = (int)rs.GetValue(2);
                        bitWhiteboard = (bool)rs.GetValue(3);
                        bitMonitor    = (bool)rs.GetValue(4);
                        bitProjector  = (bool)rs.GetValue(5);

                        requestCode = CreateBinaryCode(bitWhiteboard, bitMonitor, bitProjector);

                        RequestClassroom requestClassroom = new RequestClassroom(tempGroupId, tempSize, requestCode);
                        stillNotFulfilled.Add(requestClassroom);
                    }
                }
            }
            return(stillNotFulfilled);
        }
Ejemplo n.º 9
0
        public bool CanTheyRent(int groupId, DateTime dateStart, DateTime dateEnd)
        {
            bool canTheyRent = true;

            using (var con = new DBCon())
            {
                string sqlCmd = string.Format(
                    "SELECT GroupID FROM Rent " +
                    "WHERE(StartDate BETWEEN '{1}' AND '{2}' " +
                    "OR EndDate BETWEEN '{1}' AND '{2}' " +
                    "AND GroupId = '{0}');", groupId, dateStart, dateEnd);

                SqlDataReader rs = con.ExecuteStringGet(sqlCmd);

                while (rs.Read())
                {
                    if (rs.GetInt32(0) == groupId)
                    {
                        canTheyRent = false;
                    }
                }
            }
            return(canTheyRent);
        }