public void SaveItemInList(string n, float v, int ms, int ys, bool exavg, bool merge) { if (merge) { int index = CheckForDuplicateName(n); if (index != -1) { //merge float previousValue = curList[index].value; curList[index] = lvlOne.NewMoneyEntry(n, v + previousValue, ms, ys, exavg); } //TODO its the same as below we might be better off with just one else { //there is no other item with the same name on the list just save it. Structs.MoneyEntry newEntry = lvlOne.NewMoneyEntry(n, v, ms, ys, exavg); curList.Add(newEntry); } } else { //not on list Structs.MoneyEntry newEntry = lvlOne.NewMoneyEntry(n, v, ms, ys, exavg); curList.Add(newEntry); } ClearList(); nav.PickListClick(curListName); lvlOne.SaveData(); }
void SaveQuickExpense() { if (String.IsNullOrEmpty(nField)) { return; } if (hideMoneyButtons) { //new tag if (String.IsNullOrEmpty(lvlOne.tagList.Find(i => i.name == nField).name)) { Structs.Tag newTag = new Structs.Tag() { name = nField + "-tag", value = totalValue }; lvlOne.AddToList("tagList", new Structs.MoneyEntry(), newTag); //if (totalValue > 0) { Structs.MoneyEntry newRand = lvlOne.NewMoneyEntry(nField + "-tag", totalValue, -1, 0, false); lvlOne.AddToList("randomExpenses", newRand, new Structs.Tag()); //} } //tag exists else { Structs.MoneyEntry newRand = lvlOne.selectedMonth.randomExpenses.Find(i => i.name == nField); newRand.value += totalValue; lvlOne.selectedMonth.randomExpenses.Remove(lvlOne.selectedMonth.randomExpenses.Find(i => i.name == nField)); lvlOne.selectedMonth.randomExpenses.Add(newRand); lvlOne.tagList.Remove(lvlOne.tagList.Find(i => i.name == nField)); Structs.Tag newTag = new Structs.Tag() { name = newRand.name, value = newRand.value }; lvlOne.tagList.Add(newTag); lvlOne.SaveData(); Debug.Log(lvlOne.selectedMonth); } } else { if (nameField.transform.Find("Text").gameObject.GetComponent <Text>().text == "") { nField = nameField.GetComponent <InputField>().text = DateTime.Now.ToString(); } if (moneyField.GetComponent <InputField>().text == "") { totalValue = 0; } Structs.MoneyEntry newRand = lvlOne.NewMoneyEntry(nField, totalValue, -1, 0, false); lvlOne.AddToList("randomExpenses", newRand, new Structs.Tag()); } lvlOne.SaveData(); ResetQuickExpenses(); }