Ejemplo n.º 1
0
        private void allocateButton_Click(object sender, EventArgs e)
        {
            int deptId = (int)deptComboBox.SelectedValue;
            int courseId = (int) courseComboBox.SelectedValue;
            int roomId = (int)roomComboBox.SelectedValue;
            string day = dayComboBox.Text;
            DateTime fromTime = fromDateTimePicker.Value;
            DateTime toTime = toDateTimePicker.Value;
            RoomAllocation roomAllocation=new RoomAllocation(deptId,courseId,roomId,day,fromTime,toTime);
            RoomAllocationManager manager=new RoomAllocationManager();
            try
            {
                if (manager.IsRoomAvailable(roomId, day, fromTime, toTime))
                {

                    if (manager.Save(roomAllocation))
                    {
                        MessageBox.Show("Room Allocated");

                    }
                    else
                    {
                        MessageBox.Show("Room Allocation Failed");
                    }
                }
            }
            catch (Exception exception)
            {

                MessageBox.Show(exception.Message);
            }
        }
Ejemplo n.º 2
0
        public List<RoomAllocation> GetAllAllocatedRooms()
        {
            List<RoomAllocation> allocatedRoomList = new List<RoomAllocation>();
            string query = "SELECT * FROM t_room_allocation";
            aSqlCommand = new SqlCommand(query, aSqlConnection);
            aSqlConnection.Open();
            SqlDataReader aSqlDataReader = aSqlCommand.ExecuteReader();

            while (aSqlDataReader.Read())
            {
                RoomAllocation roomAllocation = new RoomAllocation();
                roomAllocation.Id = (int)aSqlDataReader["id"];
                roomAllocation.DeptId =(int) aSqlDataReader["dept_id"];
                roomAllocation.CourseId = (int)aSqlDataReader["course_id"];
                roomAllocation.RoomId = (int)aSqlDataReader["room_id"];
                roomAllocation.Day = aSqlDataReader["day"].ToString();
                roomAllocation.FromTime = (DateTime)aSqlDataReader["from_time"];
                roomAllocation.ToTime = (DateTime)aSqlDataReader["to_time"];

                allocatedRoomList.Add(roomAllocation);
            }
            aSqlDataReader.Close();
            aSqlConnection.Close();

            return allocatedRoomList;
        }
Ejemplo n.º 3
0
 public bool Save(RoomAllocation roomAllocation)
 {
     if (IsCourseAlreadyExist(roomAllocation.CourseId))
     {
         throw new Exception("Course Already Allocated");
     }
     return gateway.Save(roomAllocation) > 0;
 }
Ejemplo n.º 4
0
 public int Save(RoomAllocation roomAllocation)
 {
     string query = "INSERT INTO t_room_allocation VALUES('" + roomAllocation.DeptId + "', '" + roomAllocation.CourseId + "', '" + roomAllocation.RoomId + "', '" + roomAllocation.Day + "', '" + roomAllocation.FromTime + "', '" + roomAllocation.ToTime + "')";
     aSqlConnection.Open();
     aSqlCommand = new SqlCommand(query, aSqlConnection);
     int rowAffected = aSqlCommand.ExecuteNonQuery();
     aSqlConnection.Close();
     return rowAffected;
 }