Пример #1
0
 public CalendarPageDetail()
 {
     this.InitializeComponent();
     caldata = new ObservableCollection<Calendar>();
     mapIconAddress = "";
     mlibrary = new methodLibrary();
     rmemGoing = new ObservableCollection<MemberAvailabilityStatus>();
     rmemMaybe = new ObservableCollection<MemberAvailabilityStatus>();
     rmemNotGoing = new ObservableCollection<MemberAvailabilityStatus>();
     rmemUnknown = new ObservableCollection<MemberAvailabilityStatus>();
     reventavail = new RootObjectEventAvailability();
     status_code = -1;
     eventMemberAvailability_pos = 0;
     memberAvailable_pos = 0;
     teamid = 0;
     eventid = 0;
     hrefForAvailabilityRequest = null;
     currentUserMemberID = 0;
     //caldata = new Calendar();
     this.NavigationCacheMode = NavigationCacheMode.Required;
 }
Пример #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Calendar cald = (Calendar)e.Parameter;
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame.CanGoBack)
            {
                // If we have pages in our in-app backstack and have opted in to showing back, do so
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            }
            else
            {
                // Remove the UI from the title bar if there are no pages in our in-app back stack
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            }
            Hashtable reventmember_ht = new Hashtable();
            //RootObjectEventAvailability reventavail = new RootObjectEventAvailability();
            string eventAvailRes = await mlibrary.readFile("EventsMemberAvailability" + ((long)ApplicationData.Current.LocalSettings.Values["currentTeamID"]).ToString());
            if (eventAvailRes != null)
            {                
                reventavail = AvailabilityAPI.eventAvailabilityDataDeserializer(eventAvailRes);
                if (reventavail != null)
                {
                    if (reventavail.eventMemberAvailability != null)
                    {
                        for (int i = 0; i < reventavail.eventMemberAvailability.Count; i++)
                        {
                            reventmember_ht.Add(reventavail.eventMemberAvailability[i].eventid, i);
                        }
                    }
                }
            }

            /// Adding objects to the ObservableCollection.
            try
            {
                if (reventavail != null)
                {
                    if (reventavail.eventMemberAvailability != null)
                    {
                        //ApplicationData.Current.LocalSettings.Values["currentMemberIDforLoggedInUser"]
                        Hashtable rmemberavailable_ht = new Hashtable();
                        for (int i = 0; i < reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable.Count; i++)
                        {
                            if(reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable[i].member_id == (long)ApplicationData.Current.LocalSettings.Values["currentMemberIDforLoggedInUser"])
                            {
                                hrefForAvailabilityRequest = reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable[i].updateMemberAvailabilityhref;
                                memberAvailable_pos = i;
                                if (reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable[i].status_code == 0)
                                {
                                    notGoingHighlighter.Visibility = Visibility.Visible;
                                    goingHighlighter.Visibility = Visibility.Collapsed;
                                    maybeHighlighter.Visibility = Visibility.Collapsed;
                                    status_code = 0;
                                }
                                else if (reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable[i].status_code == 1)
                                {
                                    notGoingHighlighter.Visibility = Visibility.Collapsed;
                                    goingHighlighter.Visibility = Visibility.Visible;
                                    maybeHighlighter.Visibility = Visibility.Collapsed;
                                    status_code = 1;
                                }
                                else if (reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable[i].status_code == 2)
                                {
                                    notGoingHighlighter.Visibility = Visibility.Collapsed;
                                    goingHighlighter.Visibility = Visibility.Collapsed;
                                    maybeHighlighter.Visibility = Visibility.Visible;
                                    status_code = 2;
                                }
                                else
                                {
                                    notGoingHighlighter.Visibility = Visibility.Collapsed;
                                    goingHighlighter.Visibility = Visibility.Collapsed;
                                    maybeHighlighter.Visibility = Visibility.Collapsed;
                                }

                                if (!String.IsNullOrEmpty(reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable[i].notes))
                                {
                                    availabilityNoteTextBox.Visibility = Visibility.Collapsed;
                                    addAvailabilityNoteButton.Visibility = Visibility.Collapsed;
                                    availabilityNoteTextBlockGrid.Visibility = Visibility.Visible;
                                    availabilityNoteTextBlock.Text = reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable[i].notes;
                                    saveAvailability.Visibility = Visibility.Collapsed;
                                }
                                else
                                {
                                    availabilityNoteTextBox.Visibility = Visibility.Collapsed;
                                    //addAvailabilityNoteButton.Visibility = Visibility.Visible;
                                    addAvailabilityNoteButton.Visibility = Visibility.Collapsed;
                                    availabilityNoteTextBlockGrid.Visibility = Visibility.Collapsed;
                                    saveAvailability.Visibility = Visibility.Collapsed;
                                }
                            }
                        }


                        eventMemberAvailability_pos = (int)reventmember_ht[cald.id];
                        var rmemberstatus = reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].memberAvailable;
                        teamid = reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].team_id;
                        eventid = reventavail.eventMemberAvailability[(int)reventmember_ht[cald.id]].eventid;
                        
                        if (rmemberstatus != null)
                        {
                            rmemGoing.Clear();
                            rmemMaybe.Clear();
                            rmemNotGoing.Clear();
                            rmemUnknown.Clear();
                            foreach (var rmemstat in rmemberstatus)
                            {
                                if (rmemstat.status_code == 1)
                                {
                                    rmemGoing.Add(rmemstat);
                                }
                                else if (rmemstat.status_code == 2)
                                {
                                    rmemMaybe.Add(rmemstat);
                                }
                                else if (rmemstat.status_code == 0)
                                {
                                    rmemNotGoing.Add(rmemstat);
                                }
                                else
                                {
                                    rmemUnknown.Add(rmemstat);
                                }
                            }

                            if (rmemGoing != null)
                            {
                                if (rmemGoing.Count > 0)
                                {
                                    NumGoing.Text = (rmemGoing.Count).ToString();
                                    goingEmailButton.Visibility = Visibility.Visible;
                                }                             
                            }
                            if (rmemMaybe != null)
                            {
                                if (rmemMaybe.Count > 0)
                                {
                                    NumMaybeGoing.Text = (rmemMaybe.Count).ToString();
                                    maybeGoingEmailButton.Visibility = Visibility.Visible;
                                }                               
                            }
                            if (rmemNotGoing != null)
                            {
                                if (rmemNotGoing.Count > 0)
                                {
                                    NumNotGoing.Text = (rmemNotGoing.Count).ToString();
                                    notGoingEmailButton.Visibility = Visibility.Visible;
                                }
                            }
                            if (rmemUnknown != null)
                            {
                                if (rmemUnknown.Count > 0)
                                {
                                    unknown.Text = (rmemUnknown.Count).ToString();
                                    unknownGoingEmailButton.Visibility = Visibility.Visible;
                                }
                            }
                        }
                        else
                        {
                            availabilityData.Visibility = Visibility.Collapsed;
                            noAvailabilityData.Visibility = Visibility.Visible;
                            availabilityGrid.Visibility = Visibility.Collapsed;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception in CalendarPageDetail.xaml.cs right after setting eventMemberAvailability : " + ex);
                availabilityData.Visibility = Visibility.Collapsed;
                noAvailabilityData.Visibility = Visibility.Visible;
                availabilityGrid.Visibility = Visibility.Collapsed;
            }
            
            //CollectionEventAvailabilityMembers reventavailmember
            caldata.Clear();
            caldata.Add(cald);
            if(String.IsNullOrEmpty(cald.name))
            {
                name.Visibility = Visibility.Collapsed;
            }
            else
            {
                name.Text = cald.name;
                //CalendarDetailTitle.Text = cald.name;
                name.Visibility = Visibility.Visible;
            }
            if(String.IsNullOrEmpty(cald.game_title))
            {
                game_title.Visibility = Visibility.Collapsed;
            }
            else
            {
                game_title.Text = cald.game_title;
                //CalendarDetailTitle.Text = cald.game_title;
                game_title.Visibility = Visibility.Visible;
            }
            if (String.IsNullOrEmpty(cald.locationName))
            {
                locationName.Text = await mlibrary.reverseGeocode(Constants.CurrentTeamLatitude, Constants.CurrentTeamLongitude);
                locationNameN.Text =  await mlibrary.reverseGeocode(Constants.CurrentTeamLatitude, Constants.CurrentTeamLongitude);
            }
            
            if(String.IsNullOrEmpty(cald.additional_location_details))
            {
                LocationDetailsTitle.Visibility = Visibility.Collapsed;
                location_details.Visibility = Visibility.Collapsed;
                locationNameDetailsGrid.Visibility = Visibility.Collapsed;
            }
            else
            {
                location_details.Visibility = Visibility.Visible;
                LocationDetailsTitle.Visibility = Visibility.Visible;
                locationNameDetailsGrid.Visibility = Visibility.Visible;
                location_details.Text = cald.additional_location_details;
            }
            if(String.IsNullOrEmpty(cald.locationAddress))
            {
                address.Text = "No address available";
                Debug.WriteLine((string)ApplicationData.Current.LocalSettings.Values["team_latitude"]);
                double latitude = Convert.ToDouble((string)ApplicationData.Current.LocalSettings.Values["team_latitude_" + cald.team_id]);
                double longitude = Convert.ToDouble((string)ApplicationData.Current.LocalSettings.Values["team_longitude_" + cald.team_id]);

                setMapControlCenter(latitude, longitude);
            }
            else
            {
                address.Text = cald.locationAddress;
                mapIconAddress = cald.locationAddress;
                MapLocationFinderResult res = await convertAddressToCoordinates(cald.locationAddress, double.Parse((string)ApplicationData.Current.LocalSettings.Values["team_latitude_" + cald.team_id], System.Globalization.CultureInfo.InvariantCulture), double.Parse((string)ApplicationData.Current.LocalSettings.Values["team_longitude_" + cald.team_id], System.Globalization.CultureInfo.InvariantCulture));
                if (res.Status == MapLocationFinderStatus.Success)
                {
                    double lat = Math.Round(res.Locations[0].Point.Position.Latitude, 4);
                    double lon = Math.Round(res.Locations[0].Point.Position.Longitude, 4);
                    setMapControlCenter(lat, lon);
                }
                else
                {
                    setMapControlCenter(double.Parse((string)ApplicationData.Current.LocalSettings.Values["team_latitude_" + cald.team_id], System.Globalization.CultureInfo.InvariantCulture), double.Parse((string)ApplicationData.Current.LocalSettings.Values["team_longitude_" + cald.team_id], System.Globalization.CultureInfo.InvariantCulture));
                }
            }
            if (String.IsNullOrEmpty(cald.uniform))
            {
                uniformDetailsGrid.Visibility = Visibility.Collapsed;
            }
            else
            {
                uniformDetailsGrid.Visibility = Visibility.Visible;
                uniform_details.Text = cald.uniform;
            }
            if (String.IsNullOrEmpty(cald.game_type) || (cald.game_type).Equals("Not Specified"))
            {
                game_type_border.Visibility = Visibility.Collapsed;
                game_type_textblock.Visibility = Visibility.Collapsed;
            }
            else
            {
                game_type_border.Visibility = Visibility.Visible;
                game_type_textblock.Visibility = Visibility.Visible;
                game_type_textblock.Text = cald.game_type;
            }
            start_date.Text = String.Format("{0:dddd, MMMM d, yyyy}", cald.start_date);
            if(cald.is_tbd == true)
            {
                start_time.Text = "TBD";
                arrival_time.Visibility = Visibility.Collapsed;
                arrivalTimeGrid.Visibility = Visibility.Collapsed;
            }
            else if (cald.end_Date != DateTime.MinValue)
            {
                start_time.Text = cald.eventTime + " - " + String.Format("{0:t}", cald.end_Date);
                arrival_time.Text = cald.arrival_time;
                arrival_time.Visibility = Visibility.Visible;
                arrivalTimeGrid.Visibility = Visibility.Visible;               
            }
            else
            {
                start_time.Text = cald.eventTime;
                arrival_time.Text = cald.arrival_time;
                arrival_time.Visibility = Visibility.Visible;
                arrivalTimeGrid.Visibility = Visibility.Visible;
            }

            if (!String.IsNullOrEmpty(cald.notes))
            {
                notesTextBlock.Text = cald.notes;
                NotesGrid.Visibility = Visibility.Visible;
            }
            else
            {
                NotesGrid.Visibility = Visibility.Collapsed;
            }
        }
Пример #3
0
        public static async Task<bool> updateAvailability(RootObjectUsers rusers)
        {
            methodLibrary mlib = new methodLibrary();
            Hashtable rteams_ht = new Hashtable();
            if (rusers.teams != null)
            {
                for (int i = 0; i < rusers.teams.Count; i++)
                {
                    if (!rteams_ht.Contains(rusers.teams[i].id))
                    {
                        rteams_ht.Add(rusers.teams[i].id, i);
                    }
                }
            }
            RootObjectEventAvailability reventavailability = new RootObjectEventAvailability();
            for (int teami = 0; teami < rusers.teams.Count; teami++)
            {
                try
                {
                    string response = await mlib.readFile("teamAvailabilityAPI" + rusers.teams[teami].id);
                    long manager_memberid = 0;
                    long owner_memberid = 0;
                    RootObjectAvailabilityAPI ravailbilityAPI = AvailabilityAPI.availabilityAPIDataDeserializer(response);
                    RootObjectEventAvailability reventavail = new RootObjectEventAvailability();
                    reventavail.eventMemberAvailability = new ObservableCollection<CollectionEventAvailabilityMembers>();
                    if (ravailbilityAPI.collection.items != null)  //meaning there is some availability defined in there
                    {
                        Hashtable ravailibityAPI_items_ht = new Hashtable();
                        for (int i = 0; i < ravailbilityAPI.collection.items[0].data.Count; i++)
                        {
                            if (!ravailibityAPI_items_ht.Contains(ravailbilityAPI.collection.items[0].data[i].name))
                            {
                                ravailibityAPI_items_ht.Add(ravailbilityAPI.collection.items[0].data[i].name, i);
                            }
                        }
                        Hashtable ravailabilityAPI_events_ht = new Hashtable();
                        int pos = 0;
                        for (int i = 0; i < ravailbilityAPI.collection.items.Count; i++)
                        {
                            if (!ravailabilityAPI_events_ht.ContainsKey(ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value))
                            {
                                ravailabilityAPI_events_ht.Add(ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value, pos);
                                CollectionEventAvailabilityMembers reventavailmembers = new CollectionEventAvailabilityMembers();
                                //reventavailmembers.hrefForThisEvent = ravailbilityAPI.collection.items[i].href;
                                reventavailmembers.eventid = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value == null ? 0 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value;
                                reventavailmembers.team_id = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["team_id"]].value == null ? 0 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["team_id"]].value;
                                reventavailmembers.manager_memberID = rusers.teams[(int)rteams_ht[reventavailmembers.team_id]].teamManagerMemberId;
                                manager_memberid = reventavailmembers.manager_memberID;
                                reventavailmembers.owner_memberID = rusers.teams[(int)rteams_ht[reventavailmembers.team_id]].teamOwnerMemberId;
                                owner_memberid = reventavailmembers.owner_memberID;
                                reventavailmembers.currentUser_memberID = rusers.teams[(int)rteams_ht[reventavailmembers.team_id]].loggedInUsersmemberID;
                                reventavail.eventMemberAvailability.Add(reventavailmembers);
                                pos++;
                            }
                            MemberAvailabilityStatus rmemstatus = new MemberAvailabilityStatus();
                            try
                            {
                                rmemstatus.updateMemberAvailabilityhref = ravailbilityAPI.collection.items[i].href;
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine("Exception in storing the availability API of a member : " + ex);
                                await mlb.writeToLogFile("xception in storing the availability API of a member : " + ex, false);
                            }
                            rmemstatus.member_id = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["member_id"]].value == null ? 0 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["member_id"]].value;
                            rmemstatus.notes = (string)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["notes"]].value;
                            rmemstatus.notes_author_member_id = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["notes_author_member_id"]].value == null ? -1 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["notes_author_member_id"]].value;
                            rmemstatus.status_code = ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["status_code"]].value == null ? -1 : (long)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["status_code"]].value;
                            rmemstatus.status_string = (string)ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["status"]].value;
                            if (rmemstatus.member_id == manager_memberid)
                            {
                                rmemstatus.is_teammamager = true;
                            }
                            else
                            {
                                rmemstatus.is_teammamager = false;
                            }

                            if (rmemstatus.member_id == owner_memberid)
                            {
                                rmemstatus.is_teamowner = true;
                            }
                            else
                            {
                                rmemstatus.is_teamowner = false;
                            }
                            int event_pos = (int)ravailabilityAPI_events_ht[ravailbilityAPI.collection.items[i].data[(int)ravailibityAPI_items_ht["event_id"]].value];
                            if (reventavail.eventMemberAvailability[event_pos].memberAvailable == null)
                            {
                                reventavail.eventMemberAvailability[event_pos].memberAvailable = new ObservableCollection<MemberAvailabilityStatus>();
                            }
                            reventavail.eventMemberAvailability[event_pos].memberAvailable.Add(rmemstatus);
                        }
                        ravailabilityAPI_events_ht.Clear();
                        ravailibityAPI_items_ht.Clear();
                    }
                    for (int i = 0; i < reventavail.eventMemberAvailability.Count; i++)
                    {
                        if (rteams_ht.Contains(reventavail.eventMemberAvailability[i].team_id))
                        {
                            var teams = rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]];
                            Hashtable rteamMember_ht = new Hashtable();
                            int numOfMembersInTeam = rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]].members.Count;
                            for (int j = 0; j < numOfMembersInTeam; j++)
                            {
                                if (!rteamMember_ht.Contains(rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]].members[j].member_id))
                                {
                                    rteamMember_ht.Add(rusers.teams[(int)rteams_ht[reventavail.eventMemberAvailability[i].team_id]].members[j].member_id, j);
                                }
                            }
                            for (int j = 0; j < reventavail.eventMemberAvailability[i].memberAvailable.Count; j++)
                            {
                                if (rteamMember_ht.Contains(reventavail.eventMemberAvailability[i].memberAvailable[j].member_id))
                                {
                                    // int event_member_pos = (int)reventavail.eventMemberAvailability[i].memberAvailable[j].member_id;
                                    // bool tr = rteamMember_ht.Contains(event_member_pos);
                                    int member_pos = (int)rteamMember_ht[reventavail.eventMemberAvailability[i].memberAvailable[j].member_id];
                                    reventavail.eventMemberAvailability[i].memberAvailable[j].member_name = teams.members[member_pos].fullname;
                                    reventavail.eventMemberAvailability[i].memberAvailable[j].member_photo = teams.members[member_pos].member_photo;
                                }
                            }
                            rteamMember_ht.Clear();
                        }
                    }
                    
                    string res = AvailabilityAPI.eventAvailabilityDataSerializer(reventavail);
                    await mlib.writeFile("EventsMemberAvailability" + rusers.teams[teami].id, res);
                    Debug.WriteLine(res);
                }
                catch (Exception ex)
                {
                    await mlib.writeToLogFile("Exception in updateAvailability() : " + ex, true);
                }
            }
            rteams_ht.Clear();
            return true;
        }
Пример #4
0
 public static string eventAvailabilityDataSerializer(RootObjectEventAvailability reventavailability)
 {
     string response = JsonConvert.SerializeObject(reventavailability);
     return response;
 }