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 updatePrefix = "update tasks set ";
private static string updateIntermediate = " where uid = ";
private static string updatePostfix = ";";
private static string updateIntermediate = " where uid = '";
private static string updatePostfix = "';";
public static void CreateTableIfNotExists(string sqlConnection) {

View File

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

View File

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

View File

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