public int SaveItem(ExercisesTimeTable item) { if (item.ID != 0) { database.Update(item); return(item.ID); } else { count++; return(database.Insert(item)); } }
private StackLayout AddStatisticByExercise(MainTable mainTable) { int progress = 0; double percent = 0.0; if (mainTable.Type == (byte)App.TypeExercises.Count) { ExercisesCountTableRepository exercisesCountTableRepository = new ExercisesCountTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); int exercisesTableLength = exercisesCountTableRepository.Count; if (exercisesTableLength == 0) { return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, 0, 0.0, "count.jpg")); } ExercisesCountTable lastItem = exercisesCountTableRepository.GetItem(exercisesCountTableRepository.StartPosition + exercisesTableLength - 1); double purpose = double.Parse(mainTable.Purpose); if (exercisesTableLength >= 2) { ExercisesCountTable penultItem = exercisesCountTableRepository.GetItem(exercisesCountTableRepository.StartPosition + exercisesTableLength - 2); progress = lastItem.Count - penultItem.Count; percent = (double)lastItem.Count / purpose * 100.0; } if (exercisesTableLength == 1) { percent = (double)lastItem.Count / purpose * 100.0; } } else if (mainTable.Type == (byte)App.TypeExercises.Approach) { ExercisesApproachTableRepository exercisesApproachTableRepository = new ExercisesApproachTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); int exercisesTableLength = exercisesApproachTableRepository.Count; if (exercisesTableLength == 0) { return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, 0, 0.0, "approach.jpg")); } int lastItem = (from item in exercisesApproachTableRepository.GetItem(exercisesApproachTableRepository.StartPosition + exercisesTableLength - 1).Count.Split('/') select int.Parse(item)).Sum(); double purpose = (from item in mainTable.Purpose.Split('/') select double.Parse(item)).Sum(); if (exercisesTableLength >= 2) { int penultItem = (from item in exercisesApproachTableRepository.GetItem(exercisesApproachTableRepository.StartPosition + exercisesTableLength - 2).Count.Split('/') select int.Parse(item)).Sum(); progress = lastItem - penultItem; percent = (double)lastItem / purpose * 100.0; } if (exercisesTableLength == 1) { percent = (double)lastItem / purpose * 100.0; } } else if (mainTable.Type == (byte)App.TypeExercises.Time) { ExercisesTimeTableRepository exercisesTimeTableRepository = new ExercisesTimeTableRepository(Path.Combine(DBSaverLoader.documentsPath, mainTable.StringID + ".db")); int exercisesTableLength = exercisesTimeTableRepository.Count; TimeSpan progressTime = new TimeSpan(0, 0, 0); if (exercisesTableLength == 0) { return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, 0, 0.0, "timer.jpg")); } ExercisesTimeTable lastItem = exercisesTimeTableRepository.GetItem(exercisesTimeTableRepository.StartPosition + exercisesTableLength - 1); double purpose = double.Parse(mainTable.Purpose); if (exercisesTableLength >= 2) { ExercisesTimeTable penultItem = exercisesTimeTableRepository.GetItem(exercisesTimeTableRepository.StartPosition + exercisesTableLength - 2); progressTime = lastItem.Count - penultItem.Count; percent = (double)lastItem.Count.TotalSeconds / purpose * 100.0; } if (exercisesTableLength == 1) { percent = (double)lastItem.Count.TotalSeconds / purpose * 100.0; } return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, (int)progressTime.TotalSeconds, percent, "timer.jpg", true)); } string photo = ""; if (mainTable.Type == (byte)App.TypeExercises.Time) { photo = "timer.jpg"; } if (mainTable.Type == (byte)App.TypeExercises.Approach) { photo = "approach.jpg"; } if (mainTable.Type == (byte)App.TypeExercises.Count) { photo = "count.jpg"; } return(AddStatisticFromScreen(mainTable.Name, mainTable.ID, progress, percent, photo)); }