Fixed insert/update/stop/start

This commit is contained in:
Kuro 2025-03-23 00:37:01 +01:00
parent b42f4ec03e
commit f28a0c4f10
2 changed files with 44 additions and 8 deletions

View File

@ -3,7 +3,9 @@
string uid { get; set; } string uid { get; set; }
DateTime time { get; set; } string start { get; set; }
string name { get; set; } string end { get; set; }
string text { get; set; }
} }
} }

View File

@ -1,5 +1,6 @@
using Microsoft.Data.SqlClient; using Microsoft.Data.SqlClient;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using System;
using System.Data; using System.Data;
using System.Data.Common; using System.Data.Common;
using System.Data.SQLite; using System.Data.SQLite;
@ -224,19 +225,17 @@ namespace TimeTable {
} }
private void DeleteRow(object sender, EventArgs e) { private void DeleteRow(object sender, EventArgs e) {
DataGridViewRow row = timeTableGridView.Rows[0]; SqliteTimeTableCommands.DeleteTableRow(uid, sqlConnectionString);
string currentId = row.Cells[0].Value.ToString();
SqliteTimeTableCommands.DeleteTableRow(currentId, sqlConnectionString);
bindingSource.DataSource = createDataTable(); bindingSource.DataSource = createDataTable();
} }
private void TimetableEditDoubleClick(object sender, DataGridViewCellEventArgs e) { private void TimetableEditDoubleClick(object sender, DataGridViewCellEventArgs e) {
DataGridViewRow row = timeTableGridView.Rows[0]; DataGridViewRow row = timeTableGridView.Rows[e.RowIndex];
string uid = row.Cells[4].Value.ToString(); string uid = row.Cells[4].Value.ToString();
string start = row.Cells[0].Value.ToString(); string start = row.Cells[0].Value.ToString();
string end = row.Cells[1].Value.ToString(); string end = row.Cells[1].Value.ToString();
string text = row.Cells[2].Value.ToString(); string text = row.Cells[2].Value.ToString();
this.uid = uid;
RowEdit rowEdit = new RowEdit(); RowEdit rowEdit = new RowEdit();
rowEdit.Data(uid, start, end, text, this); rowEdit.Data(uid, start, end, text, this);
@ -244,7 +243,7 @@ namespace TimeTable {
} }
private void TimeTableClick(object sender, DataGridViewCellEventArgs e) { private void TimeTableClick(object sender, DataGridViewCellEventArgs e) {
DataGridViewRow row = timeTableGridView.Rows[0]; DataGridViewRow row = timeTableGridView.Rows[e.RowIndex];
string uid = row.Cells[4].Value.ToString(); string uid = row.Cells[4].Value.ToString();
uidLbl.Text = uid; uidLbl.Text = uid;
this.uid = uid; this.uid = uid;
@ -265,15 +264,50 @@ namespace TimeTable {
con.Open(); con.Open();
sqliteCmd.ExecuteNonQuery(); sqliteCmd.ExecuteNonQuery();
con.Close(); con.Close();
UpdateTimes();
bindingSource.DataSource = createDataTable(); bindingSource.DataSource = createDataTable();
} }
private void UpdateTimes() {
SqliteConnection con = new SqliteConnection(sqlConnectionString);
SqliteCommand sqliteCmd = con.CreateCommand();
sqliteCmd.CommandText = "Select * from timetable";
con.Open();
SqliteDataReader result = sqliteCmd.ExecuteReader();
if (result.HasRows) {
while (result.Read()) {
string startTimeStrg = null;
string endTimeStrg = null;
try {
startTimeStrg = result.GetString(0);
endTimeStrg = result.GetString(1);
} catch (Exception e) {
Console.WriteLine(e);
}
if (startTimeStrg != null && endTimeStrg != null) {
DateTime startTime = DateTime.Parse(startTimeStrg);
DateTime endTime = DateTime.Parse(endTimeStrg);
TimeSpan timespan = new TimeSpan();
timespan = endTime - startTime;
SqliteCommand subsqliteCmd = con.CreateCommand();
subsqliteCmd.CommandText = SqliteTimeTableCommands.UpdateTimeCmd(result.GetString(4), timespan);
subsqliteCmd.ExecuteNonQuery();
}
}
}
con.Close();
}
private void btnStartClick(object sender, EventArgs e) { private void btnStartClick(object sender, EventArgs e) {
UidCommand uidCmd = SqliteTimeTableCommands.InsertCmd(DateTime.Now); UidCommand uidCmd = SqliteTimeTableCommands.InsertCmd(DateTime.Now);
uid = uidCmd.uid; uid = uidCmd.uid;
uidLbl.Text = uidCmd.uid;
executeSql(uidCmd.command); executeSql(uidCmd.command);
} }