public RoomOccupiedStatus GetOccupiedStatusById(int id) { //MySqlConnection con = // new MySqlConnection( // "Server=roomcheckaurora.cluster-cshbhaowu4cu.eu-west-1.rds.amazonaws.com;Port=3306;database=RoomCheckDB;User Id=s00142227;Password=Lollipop12;charset=utf8"); RoomOccupiedStatus occStatus = new RoomOccupiedStatus(); try { if (con.State == ConnectionState.Closed) { con.Open(); using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM RoomOccupiedStatusTbl where ID = @id;", con)) { cmd.Parameters.AddWithValue("@id", id); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { occStatus.Description = (string)reader["Description"]; occStatus.IconPath = (string)reader["IconPath"]; } } } } } catch (MySqlException ex) { //Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show(); } finally { con.Close(); } return(occStatus); }
public override View GetView(int position, View convertView, ViewGroup parent) { var item = items[position]; View view = convertView ?? context.LayoutInflater.Inflate(Resource.Layout.MyRooms, null); //TODO: see how often this method is getting called and if there are any changes i can make to optimise RoomOccupiedStatus roomOccStatus = item.OccupiedStatus; RoomCleanStatus roomCleanStatus = item.CleanStatus; RoomType roomType = item.RoomType; ImageView imgRoomIcon = view.FindViewById <ImageView>(Resource.Id.imgRoomIcon); //populate room number labels view.FindViewById <TextView>(Resource.Id.lblRoomNo).Text = item.RoomNo; //change icon to reflect occupied status var roomOccResourceId = (int)typeof(Resource.Drawable).GetField(roomOccStatus.IconPath).GetValue(null); imgRoomIcon.SetImageResource(roomOccResourceId); //change border colour to reflect cleaning status //var background = (int)typeof(Resource.Drawable).GetField(roomCleanStatus.BorderImage).GetValue(null); //view.FindViewById<ImageView>(Resource.Id.imgRoomIcon).SetBackgroundResource(background); //change background color to reflect cleaning status LinearLayout listItem = view.FindViewById <LinearLayout>(Resource.Id.llMyRoomsListItem); listItem.SetBackgroundColor(Android.Graphics.Color.ParseColor(roomCleanStatus.BorderImage)); //TODO: if room type is empty grey out the icon and border (room occupied status shoud alw-ays be unoccupied on empty rooms if (roomType.Description == "Empty") { roomOccResourceId = (int)typeof(Resource.Drawable).GetField("Unoccupied").GetValue(null); imgRoomIcon.SetImageResource(roomOccResourceId); view.FindViewById <TextView>(Resource.Id.lblRoomNo).SetTextColor(Android.Graphics.Color.ParseColor("#808080")); listItem.SetBackgroundColor(Android.Graphics.Color.ParseColor("#e6e6e6")); } //If there is a note on the room - show the note icon ImageView imgNote = view.FindViewById <ImageView>(Resource.Id.imgNote); //guest request overrides note - if there are both, the cleaner will have to //view details anyways and will see both if (!string.IsNullOrEmpty(item.GuestRequest)) { var resourceId = (int)typeof(Resource.Drawable).GetField("GuestRequest").GetValue(null); imgNote.SetImageResource(resourceId); imgNote.Visibility = ViewStates.Visible; } else { imgNote.Visibility = ViewStates.Invisible; if (!string.IsNullOrEmpty(item.Note)) { var resourceId = (int)typeof(Resource.Drawable).GetField("Info").GetValue(null); imgNote.SetImageResource(resourceId); imgNote.Visibility = ViewStates.Visible; } else { imgNote.Visibility = ViewStates.Invisible; } } //Check if there is currently an event for the room and show icon ImageView imgEventNotification = view.FindViewById <ImageView>(Resource.Id.imgEventNotification); if (item.Events.Count > 0) { List <Event> roomEvents = item.Events; foreach (Event e in roomEvents) { //TODO: remove .TimeOfDay (just there for test purposes) if (DateTime.Now.TimeOfDay >= e.StartTime.TimeOfDay && DateTime.Now.TimeOfDay < e.EndTime.TimeOfDay) { EventType et = e.EventType; //show the notification icon var eventNotifResourceId = (int)typeof(Resource.Drawable).GetField(et.IconPath + "Small").GetValue(null); imgEventNotification.SetImageResource(eventNotifResourceId); imgEventNotification.Visibility = ViewStates.Visible; //Guest is away at an event - we can change their occupied status to unoccupied //TODO: implement properly (actually update database here or else have a sql job to handle this) var roomOccResourceIdAway = (int)typeof(Resource.Drawable).GetField("Unoccupied").GetValue(null); imgRoomIcon.SetImageResource(roomOccResourceIdAway); } else { imgEventNotification.Visibility = ViewStates.Invisible; } } } return(view); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.RoomDetails); // Create your application here var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetActionBar(toolbar); ActionBar.Title = "Room Details"; roomID = Intent.GetIntExtra("RoomID", 0); room = dbr.GetRoomById(roomID); //Get all fields on screen TextView txtRoomNo = FindViewById <TextView>(Resource.Id.txtRoomNo); TextView txtRoomType = FindViewById <TextView>(Resource.Id.txtRoomType); TextView txtRoomOccStatus = FindViewById <TextView>(Resource.Id.txtRoomOccupiedStatus); EditText txtNote = FindViewById <EditText>(Resource.Id.txtNote); txtGuestRequest = FindViewById <EditText>(Resource.Id.txtGuestRequest); ImageView imgRoomType = FindViewById <ImageView>(Resource.Id.imgRoomType); ImageView imgRoomOccStatus = FindViewById <ImageView>(Resource.Id.imgRoomOccupiedStatus); TextView txtRoomClean = FindViewById <TextView>(Resource.Id.txtCleanStatus); //populate the spinner Spinner sprRoomClean = FindViewById <Spinner>(Resource.Id.sprRoomClean); cleanstatuses = dbr.GetAllCleaningStatuses(); RoomCleanSpinnerAdapter adapter = new RoomCleanSpinnerAdapter(this, cleanstatuses); sprRoomClean.Adapter = adapter; sprRoomClean.ItemSelected += SprRoomCleanOnItemSelected; //Get statuses RoomType roomType = dbr.GetRoomTypeById(room.RoomTypeID); RoomOccupiedStatus roomOccStatus = dbr.GetOccupiedStatusById(room.OccupiedStatusID); RoomCleanStatus roomCleanStatus = dbr.GetCleanStatusById(room.CleanStatusID); //Populate fields txtRoomType.Text = roomType.Description; txtRoomOccStatus.Text = roomOccStatus.Description; txtRoomNo.Text = "Room " + room.RoomNo; txtNote.Text = room.Note; txtGuestRequest.Text = room.GuestRequest; txtRoomClean.Text = roomCleanStatus.Description; //Attempts at getting the resource id from the string stored in the database: //Attempt 1: //int resourceId = Resources.GetIdentifier( // roomType.IconPath, "drawable", GetPackageName()); //imgRoomType.SetImageResource(resourceId); //Attempt 2 //int resImage = Resources.GetIdentifier(roomType.IconPath, "drawable", PackageName); //Attempt 3 //int id = Resources.GetIdentifier("drawable/" + roomType.IconPath, null, null); //Attempt 4 int roomTypeResourceId = (int)typeof(Resource.Drawable).GetField(roomType.IconPath).GetValue(null); imgRoomType.SetImageResource(roomTypeResourceId); int roomOccupiedResourceId = (int)typeof(Resource.Drawable).GetField(roomOccStatus.IconPath).GetValue(null); imgRoomOccStatus.SetImageResource(roomOccupiedResourceId); Button btnSave = FindViewById <Button>(Resource.Id.btnSave); btnSave.Click += BtnSaveOnClick; ImageButton btnCompleteRequest = FindViewById <ImageButton>(Resource.Id.btnCompleteRequest); btnCompleteRequest.Click += BtnCompleteRequestOnClick; //TODO: set room clean status spinner to have the rooms status selected rather than just the first value //sprCleanStat.SelectedItem = sprCleanStat RoomCleanStatus rc = dbr.GetCleanStatusById(room.CleanStatusID); sprRoomClean.SetSelection(room.CleanStatusID - 1); //TODO: move all this to a separate method with the room id //TODO: check if there is an event on the room today and display here with time //TODO: move database operations to main rooms page LinearLayout llEvent = FindViewById <LinearLayout>(Resource.Id.llEventLayout); TextView txtEvent = FindViewById <TextView>(Resource.Id.txtEventType); ImageView imgEventType = FindViewById <ImageView>(Resource.Id.imgEventType); TextView txtEventTime = FindViewById <TextView>(Resource.Id.txtEventTime); if (dbr.CheckEvents(room.ID)) { List <Event> events = dbr.EventsForRoom(room.ID); //TODO: check which event is happening right now or just use first in the list //TODO: maybe change the layout to an expandable list of events instead of just displaying one? Event currentEvent = events[0]; EventType eventType = dbr.GetEventTypeByID(currentEvent.EventTypeID); //set image, text for event int eventTypeResourceId = (int)typeof(Resource.Drawable).GetField(eventType.IconPath).GetValue(null); imgEventType.SetImageResource(eventTypeResourceId); txtEvent.Text = currentEvent.Description; txtEventTime.Text = string.Format("{0} - {1}", currentEvent.StartTime.TimeOfDay, currentEvent.EndTime.TimeOfDay); llEvent.Visibility = ViewStates.Visible; } }