private void SetExerciseOrders(object sender, ReorderExercisesEventArgs e) { bool moveUp = (e.NewPosition < e.OldPosition); ucExercise exSender = (ucExercise) sender; List<ucExercise> tempList = new List<ucExercise>(); if (moveUp) { foreach (ucExercise ex in Exercises) { if ((ex.SortOrder + 1) == exSender.SortOrder) { ex.SortOrder = exSender.SortOrder; exSender.SortOrder -= 1; tempList.Add(ex); ex.SaveSortOrder(ex.SortOrder); exSender.SaveSortOrder(exSender.SortOrder); } else if (ex == exSender) tempList.Insert(ex.SortOrder - 1, ex); else { tempList.Add(ex); } } } else { foreach (ucExercise ex in Exercises) { if ((ex.SortOrder) == exSender.SortOrder + 1) { exSender.SortOrder = ex.SortOrder; ex.SortOrder -= 1; tempList.Insert(ex.SortOrder, ex); ex.SaveSortOrder(ex.SortOrder); exSender.SaveSortOrder(exSender.SortOrder); } else if (ex == exSender) if (ex.SortOrder == 0) tempList.Add(ex); else tempList.Add(ex); else { tempList.Add(ex); } } } SortExercises(tempList); }
private void btnDown_Click(object sender, EventArgs e) { ReorderExercisesEventArgs args = new ReorderExercisesEventArgs(); args.OldPosition = SortOrder; args.NewPosition = SortOrder + 1; ExerciseReordered(args); }
private void btnUp_Click(object sender, EventArgs e) { ReorderExercisesEventArgs args = new ReorderExercisesEventArgs(); args.OldPosition = SortOrder; args.NewPosition = SortOrder - 1; if (args.NewPosition == 1) btnUp.Enabled = false; btnDown.Enabled = true; ExerciseReordered(args); }
protected virtual void ExerciseReordered(ReorderExercisesEventArgs e) { EventHandler<ReorderExercisesEventArgs> handler = ExerciseReorderedEvent; if (handler != null) handler(this, e); }