Skip to content

Commit

Permalink
ACP 0.3.0
Browse files Browse the repository at this point in the history
[IMPR] When editing a ToDo depending on the category either Kosten or Zeit will get focus
[NEW] CheckBox to set a ToDo as done
[IMPR] Done percentages will be saved and loaded now
  • Loading branch information
AokiMiku committed May 7, 2020
1 parent b2aa8dc commit 80da8dd
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 8 deletions.
27 changes: 20 additions & 7 deletions ACP/Core.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace ACP
{
using ApS;
public class Core
{
#region Felder
Expand Down Expand Up @@ -169,16 +170,16 @@ public void DeleteBild(int nummer)
#endregion

#region ToDos
public void SaveToDo(string bezeichnung, int cosplan_nr, int prozentErledigt, decimal kosten, ApS.Time zeit, int nummer = 0)
public void SaveToDo(string bezeichnung, int cosplan_nr, int? prozentErledigt, decimal? kosten, Time zeit, int nummer = 0)
{
using (ToDos toDos = new ToDos())
{
if (nummer == 0)
{
toDos.Bezeichnung = bezeichnung;
toDos.Cosplan_Nr = cosplan_nr;
toDos.ProzentErledigt = prozentErledigt;
toDos.Kosten = kosten;
toDos.ProzentErledigt = prozentErledigt.ToInt();
toDos.Kosten = kosten.ToDecimal();
toDos.Zeit = zeit;

toDos.Save(ApS.Databases.SqlAction.Insert);
Expand All @@ -188,10 +189,22 @@ public void SaveToDo(string bezeichnung, int cosplan_nr, int prozentErledigt, de
toDos.Where = "Nummer = " + nummer;
toDos.Read();

toDos.Bezeichnung = bezeichnung;
toDos.ProzentErledigt = prozentErledigt;
toDos.Kosten = kosten;
toDos.Zeit = zeit;
if (!string.IsNullOrEmpty(bezeichnung))
{
toDos.Bezeichnung = bezeichnung;
}
if (prozentErledigt != null)
{
toDos.ProzentErledigt = prozentErledigt.ToInt();
}
if (kosten != null)
{
toDos.Kosten = kosten.ToDecimal();
}
if (zeit != null)
{
toDos.Zeit = zeit;
}

toDos.Save(ApS.Databases.SqlAction.Update);
}
Expand Down
47 changes: 46 additions & 1 deletion ACP_GUI/Cosplan.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ private void ActualizeSingleToDoRow(GridExtended grid, ToDos toDos)
{
grid.Children.Clear();
grid.DataObject = new ToDos4Grid(toDos);
grid.FocusElementInEditMode = 2;

TextBlock labelNummer = new TextBlock
{
Expand All @@ -404,7 +405,7 @@ private void ActualizeSingleToDoRow(GridExtended grid, ToDos toDos)
{
TextBlock labelKosten = new TextBlock
{
Text = toDos.Kosten.ToString("#.##") + "",
Text = toDos.Kosten.ToString("C"),
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Center,
Foreground = Layout.WindowForeground
Expand All @@ -413,6 +414,18 @@ private void ActualizeSingleToDoRow(GridExtended grid, ToDos toDos)
Grid.SetColumn(labelKosten, 5);
Grid.SetColumnSpan(labelKosten, 2);
grid.Add2Children(labelKosten);

BaseCheckBox chkErledigt = new BaseCheckBox
{
IsChecked = toDos.ProzentErledigt == 100,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
chkErledigt.CheckedChanged += ChkErledigt_CheckedChanged;

Grid.SetColumn(chkErledigt, 7);
Grid.SetColumnSpan(chkErledigt, 2);
grid.Add2Children(chkErledigt);
}
else if (this.core.GetKategorie(toDos.Kategorie_Nr) == "Machen")
{
Expand All @@ -435,9 +448,15 @@ private void ActualizeSingleToDoRow(GridExtended grid, ToDos toDos)
VerticalAlignment = VerticalAlignment.Center,
Foreground = Layout.WindowForeground
};
comboProzentErledigt.SelectionChanged += ComboProzentErledigt_SelectionChanged;

for (int i = 0; i <= 100; i = i + 5)
{
comboProzentErledigt.Items.Add(new ComboBoxItem { Content = i + "%" });
if (i == toDos.ProzentErledigt)
{
comboProzentErledigt.SelectedIndex = comboProzentErledigt.Items.Count - 1;
}
}

Grid.SetColumn(comboProzentErledigt, 7);
Expand All @@ -457,6 +476,32 @@ private void ActualizeSingleToDoRow(GridExtended grid, ToDos toDos)
grid.Children.Add(buttonDelToDo);
}

private void ChkErledigt_CheckedChanged(object sender, EventArgs e)
{
BaseCheckBox chk = (BaseCheckBox)sender;
ToDos4Grid toDos4Grid = (ToDos4Grid)((GridExtended)chk.Parent).DataObject;
if (chk.IsChecked)
{
this.core.SaveToDo(null, toDos4Grid.Cosplan_Nr, 100, null, null, toDos4Grid.Nummer);
}
else
{
this.core.SaveToDo(null, toDos4Grid.Cosplan_Nr, 0, null, null, toDos4Grid.Nummer);
}
}

private void ComboProzentErledigt_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
ComboBox combo = (ComboBox)sender;
ToDos4Grid toDos4Grid = (ToDos4Grid)((GridExtended)combo.Parent).DataObject;
this.core.SaveToDo(null, toDos4Grid.Cosplan_Nr, ((ComboBoxItem)combo.SelectedItem).Content.ToString().Replace("%", "").ToInt(), null, null, toDos4Grid.Nummer);
}
catch (NullReferenceException)
{ /* combo.Parent is null, if window isn't loaded yet */ }
}

private void Grid_MouseLeave(object sender, MouseEventArgs e)
{
Grid grid = (Grid)sender;
Expand Down

0 comments on commit 80da8dd

Please sign in to comment.