99 lines
3.0 KiB
C#
99 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
namespace Test_ChangeOrder
|
|
{
|
|
internal class MoveDown
|
|
{
|
|
//public List<string> Values { get; set; }
|
|
//public int NumberSelectedValue { get; set; }
|
|
public int SelectedRow { get; set; }
|
|
|
|
public List<string> Move(List<string> values, int selectedRow)
|
|
{
|
|
SelectedRow = selectedRow;
|
|
//Wenn die Ausgewählte Position nicht größer als die Anzahl der Werte und nicht die erste Position ist, dann verschiebe den ausgewählten Wert eine Position nach oben
|
|
if (ValidSelection(values, selectedRow))
|
|
{
|
|
//values.Clear();
|
|
values = NewValues(ValuesBefore(values, selectedRow), values[selectedRow], ValuesAfter(values, selectedRow));
|
|
|
|
var renameFiles = new RenameFiles();
|
|
values = renameFiles.Rename(values);
|
|
|
|
SetSelectedRow(selectedRow);
|
|
}
|
|
|
|
return values;
|
|
}
|
|
|
|
private List<string> ValuesBefore(List<string> values, int selectedRow)
|
|
{
|
|
List<string> valuesBefore = new List<string>();
|
|
valuesBefore.Clear();
|
|
|
|
for (int i = 0; i < selectedRow; i++)
|
|
{
|
|
valuesBefore.Add(values[i]);
|
|
}
|
|
|
|
return valuesBefore;
|
|
}
|
|
|
|
private List<string> ValuesAfter(List<string> values, int selectedRow)
|
|
{
|
|
List<string> valuesAfter = new List<string>();
|
|
valuesAfter.Clear();
|
|
|
|
for (int i = selectedRow + 1; i < values.Count; i++)
|
|
{
|
|
valuesAfter.Add(values[i]);
|
|
}
|
|
|
|
return valuesAfter;
|
|
}
|
|
|
|
protected virtual List<string> NewValues(List<string> valuesBefore, string selectedValue, List<string> valuesAfter)
|
|
{
|
|
List<string> newValue = new List<string>();
|
|
newValue.Clear();
|
|
|
|
newValue.AddRange(valuesBefore);
|
|
newValue.Add(valuesAfter[0]);
|
|
newValue.Add(selectedValue);
|
|
|
|
for (int i = 1; i < valuesAfter.Count; i++)
|
|
{
|
|
newValue.Add(valuesAfter[i]);
|
|
}
|
|
|
|
return newValue;
|
|
}
|
|
|
|
protected virtual bool ValidSelection(List<string> values, int selectedRow)
|
|
{
|
|
//Die ausgewählte Position muss min. 1 sein, weil sie sonst nicht nach vorne geschoben werden kann und
|
|
//die Position darf nicht größer als die max. Anzahl der Elemnte sein
|
|
if (selectedRow >= 0 && selectedRow < values.Count - 1)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
protected virtual void SetSelectedRow(int selectedRow)
|
|
{
|
|
SelectedRow = selectedRow + 1;
|
|
}
|
|
}
|
|
}
|