Version 1.0.3
Some checks failed
Gitea/WheresMyMoney/pipeline/head There was a failure building this commit

- Modify planned payment
- minor bug fixes
This commit is contained in:
2025-01-26 14:53:16 +01:00
parent 34098c9757
commit 2d69a4b018
22 changed files with 618 additions and 107 deletions

View File

@@ -81,7 +81,40 @@ public class Repository
reoccurenceType is null ? DBNull.Value : (int)reoccurenceType.Value);
command.ExecuteNonQuery();
DataChanged(this, EventArgs.Empty);
}
public void UpdatePlannedPayment(PlannedPayment plannedPayment)
{
using var command = _connection.CreateCommand();
command.CommandText = """
UPDATE planned_payment
SET amount = @amount,
name = @name,
date_start = @date_start,
date_end = @date_end,
is_subscription = @is_subscription,
reoccurences = @reoccurences,
reoccurence_type = @reoccurence_type
WHERE
id = @id;
""";
command.Parameters.AddWithValue("@id", plannedPayment.Id);
command.Parameters.AddWithValue("@amount", (int)(plannedPayment.Amount * 100));
command.Parameters.AddWithValue("@name", plannedPayment.Name);
command.Parameters.AddWithValue("@date_start", plannedPayment.DateStart);
command.Parameters.AddWithValue("@date_end",
plannedPayment.DateEnd.HasValue ? plannedPayment.DateEnd.Value : DBNull.Value);
command.Parameters.AddWithValue("@is_subscription", plannedPayment.IsSubscription);
command.Parameters.AddWithValue("@reoccurences",
plannedPayment.Reoccurences is null ? DBNull.Value : plannedPayment.Reoccurences.Value);
command.Parameters.AddWithValue("@reoccurence_type",
plannedPayment.ReoccurenceType is null ? DBNull.Value : (int)plannedPayment.ReoccurenceType.Value);
command.ExecuteNonQuery();
DataChanged(this, EventArgs.Empty);
}
@@ -97,7 +130,7 @@ public class Repository
command.Parameters.AddWithValue("@date", date);
command.ExecuteNonQuery();
DataChanged(this, EventArgs.Empty);
}
@@ -149,7 +182,7 @@ public class Repository
command.Parameters.AddWithValue("@payday", newPayday);
command.ExecuteNonQuery();
DataChanged(this, EventArgs.Empty);
}
@@ -248,6 +281,32 @@ public class Repository
command.ExecuteNonQuery();
DataChanged(this, EventArgs.Empty);
}
public event EventHandler DataChanged;
public PlannedPayment? GetPlannedPayment(int id)
{
using var command = _connection.CreateCommand();
command.CommandText = """
SELECT id, amount, name, date_start, date_end, is_subscription, reoccurences, reoccurence_type
FROM planned_payment
WHERE id = @id
""";
command.Parameters.AddWithValue("@id", id);
using var reader = command.ExecuteReader();
if (reader.Read())
{
return new PlannedPayment(reader.GetInt32(0),
reader.GetDecimal(1) / 100m,
reader.GetString(2),
reader.GetDateTime(3),
reader.IsDBNull(4) ? null : reader.GetDateTime(4),
reader.GetBoolean(5),
reader.IsDBNull(6) ? null : reader.GetInt32(6),
reader.IsDBNull(7) ? null : (ReoccurenceType)reader.GetInt32(7));
}
return null;
}
}