internal void NavigateSelection(EntryDisplay selection) { if (!this.IsCreate) { Entry nav = new Entry(); foreach (var entry in EntryCollection) { if (entry.Id == SelectedItem.Id) { nav = entry; } } SQLAccess.Clear(); SQLAccess.Procedure = "EntryCollectionByParentId"; SQLAccess.Parameters.Add(@"@parentId", nav.ParentId); DataTable _entryCollection = SQLAccess.ExecuteProcedure(); GenerateEntrCollectionyFromDataTable(_entryCollection); GenerateDisplayCollection(EntryCollection); Navigation.NavigationService.Navigate(new NewEntryView(Navigation, this)); IsCreate = true; } else { Entry selected = new Entry(); foreach (var entry in EntryCollection) { } } }
private void GenerateDisplayCollection(List <Entry> EntryCollection) { this.EntryDisplayCollection.Clear(); foreach (var entry in EntryCollection) { EntryDisplay tmp = new EntryDisplay(entry.DateCompleted.ToString("MM/dd/yyyy HH:mm"), entry.Header, entry.Id); this.EntryDisplayCollection.Add(tmp); } }
internal void Add() { if (string.IsNullOrEmpty(Name)) { Name = Header; } string _header = Header; string _parentId = string.Empty; string _name = string.Empty; string _comment = Comment; DateTime _dateCompleted = DateTime.Now; DateCompleted = _dateCompleted; Entry tmp = null; EntryDisplay tmpDisplay = null; if (EntryCollection.Count > 0) { Header = EntryCollection[0].Header; _parentId = EntryCollection[0].ParentId; _name = EntryCollection[0].Name; tmp = new Entry(_name, _dateCompleted, _header, _comment, _parentId, Guid.NewGuid().ToString()); tmpDisplay = new EntryDisplay(_dateCompleted.ToString("MM/dd/yyyy HH:mm"), FormatHeader(_header), tmp.Id); } else { tmp = new Entry(Name, _dateCompleted, _header, _comment, model.ParentId, Guid.NewGuid().ToString()); tmpDisplay = new EntryDisplay(_dateCompleted.ToString("MM/dd/yyyy HH:mm"), FormatHeader(_header), tmp.Id); } EntryDisplayCollection.Add(tmpDisplay); EntryCollection.Add(tmp); foreach (var entry in EntryCollection) { SQLAccess.Clear(); SQLAccess.Procedure = "CreateEntry"; SQLAccess.Parameters.Add(@"@name", entry.Name); SQLAccess.Parameters.Add(@"@header", entry.Header); SQLAccess.Parameters.Add(@"@comment", entry.Comment); SQLAccess.Parameters.Add(@"@dateCompleted", entry.DateCompleted); SQLAccess.Parameters.Add(@"@parentId", entry.ParentId); SQLAccess.Parameters.Add(@"@id", entry.Id); SQLAccess.Execute(); } Clear(); }
public EntryViewModel(bool create, Frame main) { Navigation = main; if (create) { this.IsCreate = create; model = new Entry(); EntryCollection = new List <Entry>(); EntryDisplayCollection = new ObservableCollection <EntryDisplay>(); AddCommand = new AddCommand(this); ModifyCommand = new ModifyCommand(this); RemoveCommand = new RemoveCommand(this); ClearCommand = new ClearCommand(this); ReportCommand = new ReportCommand(this); } else { this.IsCreate = false; model = new Entry(); EntryDisplayCollection = new ObservableCollection <EntryDisplay>(); EntryCollection = model.GetHeaders(); if (EntryCollection.Count > 0) { foreach (Entry e in EntryCollection) { EntryDisplay _entryDisplay = new EntryDisplay(e.DateCompleted.ToString("MM/dd/yyyy HH:mm"), e.Header, e.Id); EntryDisplayCollection.Add(_entryDisplay); AddCommand = new AddCommand(this); RemoveCommand = new RemoveCommand(this); SearchCommand = new SearchCommand(this); ClearCommand = new ClearCommand(this); ReportCommand = new ReportCommand(this); } } else { EntryCollection = new List <Entry>(); EntryDisplayCollection = new ObservableCollection <EntryDisplay>(); AddCommand = new AddCommand(this); RemoveCommand = new RemoveCommand(this); SearchCommand = new SearchCommand(this); ClearCommand = new ClearCommand(this); ReportCommand = new ReportCommand(this); } } }
void Start() { //Creates 5 entry displays for (int x = 0; x < 5; x++) { GameObject entry = Instantiate(entryPrefab, new Vector3(0, 0), Quaternion.identity, leaderboardDisplay.transform); EntryDisplay entryScript = entry.GetComponent <EntryDisplay> (); entryScript.rank.text = "?"; entryScript.nameText.text = "???"; entryScript.rating.text = "???"; displayValues.Add(entryScript); } //If a value changes in Scores, call the HandlValueChanged function FirebaseDatabase.DefaultInstance .GetReference("Leaderboard").Child("Scores") .ValueChanged += HandleValueChanged; }
void updateBoardDisplay() { //The first entry in the sorted list will always equ allEntries [0].setRank(1); /* * This loop is key for assigning ranks because it deals with ties. * If two ratings are equal, the next element in the list acquires rank of previous, else * then it equals rank of previous plus 1 */ for (int x = 1; x < allEntries.Count; x++) { if (allEntries [x - 1].rating == allEntries [x].rating) { allEntries [x].setRank(allEntries [x - 1].getRank()); } else { allEntries[x].setRank((allEntries [x - 1].getRank() + 1)); } } /* * This loop assigns the display values for the entry that matches your top submission. If your entry is a top 5, * then assign top 5 values regularly. If it isn't a top 5 and there are only 5 display elements, make another and * assign values. Else, just update 6th display value */ for (int x = 0; x < allEntries.Count; x++) { if (allEntries [x].name == GameControl.control.topGameIdentifier) { if (x < 5 && displayValues.Count < 6) { displayValues [x].rank.text = allEntries[x].getRank().ToString() + "."; displayValues [x].rank.color = Color.yellow; displayValues [x].nameText.text = allEntries [x].getName(); displayValues [x].nameText.color = Color.yellow; displayValues [x].rating.text = string.Format("{0:N1}", allEntries [x].getRating().ToString()) + "/10"; displayValues [x].rating.color = Color.yellow; } else if (displayValues.Count < 6) { GameObject entry = Instantiate(entryPrefab, new Vector3(0, 0), Quaternion.identity, leaderboardDisplay.transform); EntryDisplay entryScript = entry.GetComponent <EntryDisplay> (); entryScript.rank.text = allEntries[x].getRank().ToString(); entryScript.nameText.text = allEntries [x].name; entryScript.rating.text = string.Format("{0:N1}", allEntries [x].getRating().ToString()) + "/10"; displayValues.Add(entryScript); displayValues [displayValues.Count - 1].rank.color = Color.yellow; displayValues [displayValues.Count - 1].nameText.color = Color.yellow; displayValues [displayValues.Count - 1].rating.color = Color.yellow; } else { displayValues[displayValues.Count - 1].rank.text = allEntries[x].getRank().ToString() + "."; displayValues[displayValues.Count - 1].nameText.text = allEntries [x].name; displayValues [displayValues.Count - 1].rating.text = allEntries [x].getRating().ToString(); } } } /* * Assings values regularly for top 5 display values */ for (int x = 0; x < 5 && x < allEntries.Count; x++) { displayValues[x].rank.text = allEntries[x].getRank().ToString() + "."; displayValues[x].nameText.text = allEntries[x].getName(); Debug.Log(allEntries [x].rating); displayValues[x].rating.text = string.Format("{0:N1}", allEntries[x].getRating().ToString()) + "/10"; } text.alpha = 0; /* * This list searches through create games and finds which one matches your topgame submission, * and then asssign topGame to it */ CreatedGame topGame = new CreatedGame("NULL", -1); foreach (CreatedGame x in GameControl.control.allGames) { if (x.name == GameControl.control.topGameName) { topGame = x; } } /*This updates the score of top game entry by checking when gC = your top game index * if rating is not equal betweene entry pulled and your own, update it.*/ int gC = 0; if (allEntries [gC].name == GameControl.control.topGameIdentifier) { Debug.Log(GameControl.control.topGameIdentifier); Debug.Log(allEntries [gC].name); if (allEntries [gC].rating != topGame.rating) { FirebaseDatabase.DefaultInstance.GetReference("Leaderboard").Child("Scores").Child(gC.ToString()).Child("rating").SetValueAsync(topGame.rating); FirebaseDatabase.DefaultInstance.GetReference("Leaderboard").Child("Scores").Child("placeholder").SetValueAsync(topGame.rating); } } gC++; }