task sqls angepasst, insert/update vom rowedit angepasst

This commit is contained in:
Kuro 2025-03-22 23:17:26 +01:00
parent 112b1a968c
commit b42f4ec03e
4 changed files with 54 additions and 48 deletions

View File

@ -11,8 +11,8 @@ namespace TimeTable.controll {
private static string insertPostfix = ");"; private static string insertPostfix = ");";
private static string updatePrefix = "update tasks set "; private static string updatePrefix = "update tasks set ";
private static string updateIntermediate = " where uid = "; private static string updateIntermediate = " where uid = '";
private static string updatePostfix = ";"; private static string updatePostfix = "';";
public static void CreateTableIfNotExists(string sqlConnection) { public static void CreateTableIfNotExists(string sqlConnection) {

View File

@ -12,8 +12,8 @@ namespace TimeTable.controll {
private static string insertPostfix = ");"; private static string insertPostfix = ");";
private static string updatePrefix = "update timetable set "; private static string updatePrefix = "update timetable set ";
private static string updateIntermediate = " where uid = "; private static string updateIntermediate = " where uid = '";
private static string updatePostfix = ";"; private static string updatePostfix = "';";
public static UidCommand InsertCmd(DateTime start) { public static UidCommand InsertCmd(DateTime start) {
string uid = Guid.NewGuid().ToString(); string uid = Guid.NewGuid().ToString();
@ -58,12 +58,12 @@ namespace TimeTable.controll {
public static string UpdateCmd(string uid, DateTime start, DateTime end, string text) { public static string UpdateCmd(string uid, DateTime start, DateTime end, string text) {
string[] keys = new string[3]; string[] keys = new string[4];
keys[0] = "uid"; keys[0] = "uid";
keys[1] = "start"; keys[1] = "start";
keys[2] = "end"; keys[2] = "end";
keys[3] = "text"; keys[3] = "text";
string[] values = new string[3]; string[] values = new string[4];
values[0] = uid; values[0] = uid;
values[1] = start.ToString(); values[1] = start.ToString();
values[2] = end.ToString(); values[2] = end.ToString();
@ -83,7 +83,7 @@ namespace TimeTable.controll {
} }
public static string UpdateEndCmd(string uid, DateTime end) { public static string UpdateEndCmd(string uid, DateTime end) {
string[] keys = new string[2]; string[] keys = new string[2];
keys[0] = uid; keys[0] = "uid";
keys[1] = "end"; keys[1] = "end";
string[] values = new string[2]; string[] values = new string[2];
values[0] = uid; values[0] = uid;
@ -94,7 +94,7 @@ namespace TimeTable.controll {
public static string UpdateTextCmd(string uid, string text) { public static string UpdateTextCmd(string uid, string text) {
string[] keys = new string[2]; string[] keys = new string[2];
keys[0] = uid; keys[0] = "uid";
keys[1] = "text"; keys[1] = "text";
string[] values = new string[2]; string[] values = new string[2];
values[0] = uid; values[0] = uid;
@ -129,7 +129,7 @@ namespace TimeTable.controll {
public static string UpdateTimeCmd(string uid, TimeSpan timespan) { public static string UpdateTimeCmd(string uid, TimeSpan timespan) {
string[] keys = new string[2]; string[] keys = new string[2];
keys[0] = uid; keys[0] = "uid";
keys[1] = "time"; keys[1] = "time";
string[] values = new string[2]; string[] values = new string[2];
values[0] = uid; values[0] = uid;

View File

@ -32,17 +32,17 @@ namespace TimeTable {
btnDelete = new Button(); btnDelete = new Button();
btnTaskStop = new Button(); btnTaskStop = new Button();
btnTaskStart = new Button(); btnTaskStart = new Button();
btnStopResume = new Button(); btnStop = new Button();
btnStart = new Button(); btnStart = new Button();
tableView = new Panel(); tableView = new Panel();
taskTimeGridView = new DataGridView(); timeTableGridView = new DataGridView();
bindingSource = new BindingSource(components); bindingSource = new BindingSource(components);
con = new SQLiteConnection(); con = new SQLiteConnection();
dataAdapter = new SQLiteDataAdapter(); dataAdapter = new SQLiteDataAdapter();
taskTableGridView = new DataGridView(); taskTableGridView = new DataGridView();
btnPanel.SuspendLayout(); btnPanel.SuspendLayout();
tableView.SuspendLayout(); tableView.SuspendLayout();
((System.ComponentModel.ISupportInitialize)taskTimeGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)timeTableGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)bindingSource).BeginInit(); ((System.ComponentModel.ISupportInitialize)bindingSource).BeginInit();
((System.ComponentModel.ISupportInitialize)taskTableGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)taskTableGridView).BeginInit();
SuspendLayout(); SuspendLayout();
@ -55,7 +55,7 @@ namespace TimeTable {
btnPanel.Controls.Add(btnDelete); btnPanel.Controls.Add(btnDelete);
btnPanel.Controls.Add(btnTaskStop); btnPanel.Controls.Add(btnTaskStop);
btnPanel.Controls.Add(btnTaskStart); btnPanel.Controls.Add(btnTaskStart);
btnPanel.Controls.Add(btnStopResume); btnPanel.Controls.Add(btnStop);
btnPanel.Controls.Add(btnStart); btnPanel.Controls.Add(btnStart);
btnPanel.Dock = DockStyle.Left; btnPanel.Dock = DockStyle.Left;
btnPanel.Location = new Point(0, 0); btnPanel.Location = new Point(0, 0);
@ -108,16 +108,17 @@ namespace TimeTable {
btnTaskStart.TabIndex = 2; btnTaskStart.TabIndex = 2;
btnTaskStart.Text = "Task Start"; btnTaskStart.Text = "Task Start";
btnTaskStart.UseVisualStyleBackColor = true; btnTaskStart.UseVisualStyleBackColor = true;
btnTaskStart.Click += btnStopResumeClick;
// //
// btnStopResume // btnStop
// //
btnStopResume.Location = new Point(103, 3); btnStop.Location = new Point(103, 3);
btnStopResume.Name = "btnStopResume"; btnStop.Name = "btnStop";
btnStopResume.Size = new Size(114, 29); btnStop.Size = new Size(114, 29);
btnStopResume.TabIndex = 1; btnStop.TabIndex = 1;
btnStopResume.Text = "Stop"; btnStop.Text = "Stop";
btnStopResume.UseVisualStyleBackColor = true; btnStop.UseVisualStyleBackColor = true;
btnStop.Click += btnStopClick;
// //
// btnStart // btnStart
// //
@ -133,27 +134,27 @@ namespace TimeTable {
// //
tableView.AutoSizeMode = AutoSizeMode.GrowAndShrink; tableView.AutoSizeMode = AutoSizeMode.GrowAndShrink;
tableView.Controls.Add(taskTableGridView); tableView.Controls.Add(taskTableGridView);
tableView.Controls.Add(taskTimeGridView); tableView.Controls.Add(timeTableGridView);
tableView.Dock = DockStyle.Fill; tableView.Dock = DockStyle.Fill;
tableView.Location = new Point(233, 0); tableView.Location = new Point(233, 0);
tableView.Name = "tableView"; tableView.Name = "tableView";
tableView.Size = new Size(631, 378); tableView.Size = new Size(631, 378);
tableView.TabIndex = 1; tableView.TabIndex = 1;
// //
// taskTimeGridView // timeTableGridView
// //
taskTimeGridView.AutoGenerateColumns = false; timeTableGridView.AutoGenerateColumns = false;
taskTimeGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; timeTableGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
taskTimeGridView.DataSource = bindingSource; timeTableGridView.DataSource = bindingSource;
taskTimeGridView.Dock = DockStyle.Fill; timeTableGridView.Dock = DockStyle.Fill;
taskTimeGridView.EditMode = DataGridViewEditMode.EditProgrammatically; timeTableGridView.EditMode = DataGridViewEditMode.EditProgrammatically;
taskTimeGridView.Location = new Point(0, 0); timeTableGridView.Location = new Point(0, 0);
taskTimeGridView.Name = "taskTimeGridView"; timeTableGridView.Name = "timeTableGridView";
taskTimeGridView.RowHeadersWidth = 51; timeTableGridView.RowHeadersWidth = 51;
taskTimeGridView.Size = new Size(631, 378); timeTableGridView.Size = new Size(631, 378);
taskTimeGridView.TabIndex = 0; timeTableGridView.TabIndex = 0;
taskTimeGridView.CellClick += TimeTableClick; timeTableGridView.CellClick += TimeTableClick;
taskTimeGridView.CellDoubleClick += TimetableEditDoubleClick; timeTableGridView.CellDoubleClick += TimetableEditDoubleClick;
// //
// con // con
// //
@ -196,7 +197,7 @@ namespace TimeTable {
btnPanel.ResumeLayout(false); btnPanel.ResumeLayout(false);
btnPanel.PerformLayout(); btnPanel.PerformLayout();
tableView.ResumeLayout(false); tableView.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)taskTimeGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)timeTableGridView).EndInit();
((System.ComponentModel.ISupportInitialize)bindingSource).EndInit(); ((System.ComponentModel.ISupportInitialize)bindingSource).EndInit();
((System.ComponentModel.ISupportInitialize)taskTableGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)taskTableGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
@ -204,9 +205,13 @@ namespace TimeTable {
private void OtherTasks() { private void OtherTasks() {
SqliteTimeTableCommands.CreateTableIfNotExists(sqlConnectionString); SqliteTimeTableCommands.CreateTableIfNotExists(sqlConnectionString);
taskTimeGridView.AutoGenerateColumns = true; timeTableGridView.AutoGenerateColumns = true;
con.ConnectionString = sqlConnectionString; con.ConnectionString = sqlConnectionString;
bindingSource.DataSource = createDataTable(); bindingSource.DataSource = createDataTable();
SqliteTaskCommands.CreateTableIfNotExists(sqlConnectionString);
taskTableGridView.AutoGenerateColumns = true;
} }
public DataTable createDataTable() { public DataTable createDataTable() {
@ -219,18 +224,18 @@ namespace TimeTable {
} }
private void DeleteRow(object sender, EventArgs e) { private void DeleteRow(object sender, EventArgs e) {
DataGridViewRow row = taskTimeGridView.Rows[0]; DataGridViewRow row = timeTableGridView.Rows[0];
string currentId = row.Cells[0].Value.ToString(); string currentId = row.Cells[0].Value.ToString();
SqliteTimeTableCommands.DeleteTableRow(currentId, sqlConnectionString); 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 = taskTimeGridView.Rows[0]; DataGridViewRow row = timeTableGridView.Rows[0];
string uid = row.Cells[0].Value.ToString(); string uid = row.Cells[4].Value.ToString();
string start = row.Cells[1].Value.ToString(); string start = row.Cells[0].Value.ToString();
string end = row.Cells[2].Value.ToString(); string end = row.Cells[1].Value.ToString();
string text = row.Cells[3].Value.ToString(); string text = row.Cells[2].Value.ToString();
RowEdit rowEdit = new RowEdit(); RowEdit rowEdit = new RowEdit();
rowEdit.Data(uid, start, end, text, this); rowEdit.Data(uid, start, end, text, this);
@ -239,7 +244,7 @@ namespace TimeTable {
} }
private void TimeTableClick(object sender, DataGridViewCellEventArgs e) { private void TimeTableClick(object sender, DataGridViewCellEventArgs e) {
DataGridViewRow row = taskTimeGridView.Rows[0]; DataGridViewRow row = timeTableGridView.Rows[0];
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;
@ -247,7 +252,7 @@ namespace TimeTable {
BindingSource bindingSource = new BindingSource(); BindingSource bindingSource = new BindingSource();
DataTable table = new DataTable(); DataTable table = new DataTable();
table.Locale = new System.Globalization.CultureInfo("de-de"); table.Locale = new System.Globalization.CultureInfo("de-de");
SQLiteCommand sqlCommand = new SQLiteCommand("select * from tasks where uid = " + uid + ";", con); SQLiteCommand sqlCommand = new SQLiteCommand("select * from tasks where uid = '" + uid + "';", con);
dataAdapter.SelectCommand = sqlCommand; dataAdapter.SelectCommand = sqlCommand;
dataAdapter.Fill(table); dataAdapter.Fill(table);
taskTableGridView.DataSource = table; taskTableGridView.DataSource = table;
@ -276,7 +281,7 @@ namespace TimeTable {
} }
private void btnStopResumeClick(object sender, EventArgs e) { private void btnStopClick(object sender, EventArgs e) {
String cmd = SqliteTimeTableCommands.UpdateEndCmd(uid, DateTime.Now); String cmd = SqliteTimeTableCommands.UpdateEndCmd(uid, DateTime.Now);
executeSql(cmd); executeSql(cmd);
@ -292,10 +297,10 @@ namespace TimeTable {
private Panel btnPanel; private Panel btnPanel;
private Button btnTaskStop; private Button btnTaskStop;
private Button btnTaskStart; private Button btnTaskStart;
private Button btnStopResume; private Button btnStop;
private Button btnStart; private Button btnStart;
private Panel tableView; private Panel tableView;
private DataGridView taskTimeGridView; private DataGridView timeTableGridView;
private string uid; private string uid;
private BindingSource bindingSource; private BindingSource bindingSource;
private SQLiteConnection con; private SQLiteConnection con;

View File

@ -162,6 +162,7 @@ namespace TimeTable.view {
private void btnSaveCmd(object sender, EventArgs e) { private void btnSaveCmd(object sender, EventArgs e) {
string cmd = SqliteTimeTableCommands.UpdateCmd(uidLbl.Text, startDatePicker.Value, endDatePicker.Value, textBox.Text); string cmd = SqliteTimeTableCommands.UpdateCmd(uidLbl.Text, startDatePicker.Value, endDatePicker.Value, textBox.Text);
main.executeSql(cmd); main.executeSql(cmd);
this.Close();
} }
#endregion #endregion