Fixed insert/update/stop/start
This commit is contained in:
parent
b42f4ec03e
commit
f28a0c4f10
@ -3,7 +3,9 @@
|
||||
|
||||
|
||||
string uid { get; set; }
|
||||
DateTime time { get; set; }
|
||||
string name { get; set; }
|
||||
string start { get; set; }
|
||||
string end { get; set; }
|
||||
string text { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
46
TimeTable/view/Main.Designer.cs
generated
46
TimeTable/view/Main.Designer.cs
generated
@ -1,5 +1,6 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SQLite;
|
||||
@ -224,19 +225,17 @@ namespace TimeTable {
|
||||
}
|
||||
|
||||
private void DeleteRow(object sender, EventArgs e) {
|
||||
DataGridViewRow row = timeTableGridView.Rows[0];
|
||||
string currentId = row.Cells[0].Value.ToString();
|
||||
SqliteTimeTableCommands.DeleteTableRow(currentId, sqlConnectionString);
|
||||
SqliteTimeTableCommands.DeleteTableRow(uid, sqlConnectionString);
|
||||
bindingSource.DataSource = createDataTable();
|
||||
}
|
||||
|
||||
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 start = row.Cells[0].Value.ToString();
|
||||
string end = row.Cells[1].Value.ToString();
|
||||
string text = row.Cells[2].Value.ToString();
|
||||
|
||||
this.uid = uid;
|
||||
RowEdit rowEdit = new RowEdit();
|
||||
rowEdit.Data(uid, start, end, text, this);
|
||||
|
||||
@ -244,7 +243,7 @@ namespace TimeTable {
|
||||
}
|
||||
|
||||
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();
|
||||
uidLbl.Text = uid;
|
||||
this.uid = uid;
|
||||
@ -265,15 +264,50 @@ namespace TimeTable {
|
||||
con.Open();
|
||||
sqliteCmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
UpdateTimes();
|
||||
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) {
|
||||
UidCommand uidCmd = SqliteTimeTableCommands.InsertCmd(DateTime.Now);
|
||||
uid = uidCmd.uid;
|
||||
uidLbl.Text = uidCmd.uid;
|
||||
executeSql(uidCmd.command);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user