Major updates for saving and handling data

This commit is contained in:
Kuro 2025-03-21 21:18:04 +01:00
parent 3948a79e9c
commit 92d8af3f54
7 changed files with 376 additions and 38 deletions

View File

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
</ItemGroup>

View File

@ -17,7 +17,7 @@ namespace TimeTable.controll {
public static UidCommand InsertCmd(DateTime start) {
string uid = Guid.NewGuid().ToString();
return BuildInsertCommand(uid, "uid, start", uid + "," + start.ToString());
return BuildInsertCommand(uid, "uid, start", "'" + uid + "','" + start.ToString() + "'");
}
private static UidCommand BuildInsertCommand(string uid, string fields, string values) {
@ -47,7 +47,7 @@ namespace TimeTable.controll {
string fieldValues = "";
for (int i = 0; i < keys.Length; i++) {
fieldValues += keys[i] + " = " + values[i] + ",";
fieldValues += "'" + keys[i] + "' = '" + values[i] + "',";
}
fieldValues = fieldValues.TrimEnd(',');

View File

@ -1,30 +1,21 @@
using Microsoft.Data.SqlClient;
using Microsoft.Data.Sqlite;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
using System.Drawing;
using System.Windows.Forms;
using TimeTable.controll;
using TimeTable.model;
namespace TimeTable
{
namespace TimeTable {
partial class Main
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private string sqlConnectionString = "Data Source=" + Directory.GetCurrentDirectory() + "\\sqllite.db";
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
@ -33,6 +24,7 @@ namespace TimeTable
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
components = new System.ComponentModel.Container();
btnPanel = new Panel();
btnTaskStop = new Button();
btnTaskStart = new Button();
@ -40,16 +32,14 @@ namespace TimeTable
btnStart = new Button();
tableView = new Panel();
taskTimeGridView = new DataGridView();
bindingSource = new BindingSource(components);
con = new SQLiteConnection();
dataAdapter = new SQLiteDataAdapter();
btnPanel.SuspendLayout();
tableView.SuspendLayout();
((System.ComponentModel.ISupportInitialize)taskTimeGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)bindingSource).BeginInit();
SuspendLayout();
sqlConnectionString = "Data Source=" + Directory.GetCurrentDirectory() + "\\sqllite.db";
SqliteCommands.CreateTableIfNotExists(sqlConnectionString);
dataAdapter = new SqlDataAdapter("SELECT * from timetable", sqlConnectionString);
//
// btnPanel
//
@ -61,7 +51,7 @@ namespace TimeTable
btnPanel.Dock = DockStyle.Left;
btnPanel.Location = new Point(0, 0);
btnPanel.Name = "btnPanel";
btnPanel.Size = new Size(233, 171);
btnPanel.Size = new Size(233, 378);
btnPanel.TabIndex = 0;
//
// btnTaskStop
@ -72,8 +62,6 @@ namespace TimeTable
btnTaskStop.TabIndex = 3;
btnTaskStop.Text = "Task Stop";
btnTaskStop.UseVisualStyleBackColor = true;
btnTaskStart.Click += this.btnTaskStopClick;
//
// btnTaskStart
//
@ -83,7 +71,7 @@ namespace TimeTable
btnTaskStart.TabIndex = 2;
btnTaskStart.Text = "Task Start";
btnTaskStart.UseVisualStyleBackColor = true;
btnTaskStart.Click += this.btnTaskStartClick;
btnTaskStart.Click += btnStopResumeClick;
//
// btnStopResume
//
@ -93,7 +81,6 @@ namespace TimeTable
btnStopResume.TabIndex = 1;
btnStopResume.Text = "Stop/Resume";
btnStopResume.UseVisualStyleBackColor = true;
btnTaskStart.Click += this.btnStopResumeClick;
//
// btnStart
//
@ -103,34 +90,59 @@ namespace TimeTable
btnStart.TabIndex = 0;
btnStart.Text = "Start";
btnStart.UseVisualStyleBackColor = true;
btnStart.Click += this.btnStartClick;
btnStart.Click += btnStartClick;
//
// tableView
//
tableView.AutoSizeMode = AutoSizeMode.GrowAndShrink;
tableView.Controls.Add(taskTimeGridView);
tableView.Dock = DockStyle.Right;
tableView.Location = new Point(239, 0);
tableView.Dock = DockStyle.Fill;
tableView.Location = new Point(233, 0);
tableView.Name = "tableView";
tableView.Size = new Size(477, 171);
tableView.Size = new Size(631, 378);
tableView.TabIndex = 1;
//
// taskTimeGridView
//
taskTimeGridView.AutoGenerateColumns = true;
taskTimeGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
taskTimeGridView.DataSource = bindingSource;
taskTimeGridView.Dock = DockStyle.Fill;
taskTimeGridView.Location = new Point(0, 0);
taskTimeGridView.Name = "taskTimeGridView";
taskTimeGridView.RowHeadersWidth = 51;
taskTimeGridView.Size = new Size(477, 171);
taskTimeGridView.Size = new Size(631, 378);
taskTimeGridView.TabIndex = 0;
taskTimeGridView.DataSource = dataAdapter;
taskTimeGridView.CellContentDoubleClick += timetableEditDoubleClick;
//
// con
//
con.BusyTimeout = 0;
//con.ConnectionString = sqlConnectionString;
con.ConnectionString = sqlConnectionString;
con.DefaultDbType = null;
con.DefaultMaximumSleepTime = 150;
con.DefaultTimeout = 30;
con.DefaultTypeName = null;
con.Flags = SQLiteConnectionFlags.LogCallbackException | SQLiteConnectionFlags.LogModuleException | SQLiteConnectionFlags.BindInvariantDecimal | SQLiteConnectionFlags.GetInvariantDecimal | SQLiteConnectionFlags.AggressiveDisposal;
con.GetPasswordCallback = null;
con.ParseViaFramework = false;
con.PrepareRetries = 3;
con.ProgressOps = 0;
con.StepRetries = 40;
con.Tag = null;
con.TraceFlags = SQLiteTraceFlags.SQLITE_TRACE_NONE;
con.VfsName = null;
con.WaitTimeout = 30000;
// bindingSource.DataSource = createDataTable();
bindingSource.DataSource = createDataTable();
//
// Main
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(716, 171);
ClientSize = new Size(864, 378);
Controls.Add(tableView);
Controls.Add(btnPanel);
Name = "Main";
@ -138,9 +150,24 @@ namespace TimeTable
btnPanel.ResumeLayout(false);
tableView.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)taskTimeGridView).EndInit();
((System.ComponentModel.ISupportInitialize)bindingSource).EndInit();
ResumeLayout(false);
}
private DataTable createDataTable() {
DataTable table = new DataTable();
table.Locale = new System.Globalization.CultureInfo("de-de");
SQLiteCommand sqlCommand = new SQLiteCommand("select * from timetable;", con);
dataAdapter.SelectCommand = sqlCommand;
dataAdapter.Fill(table);
return table;
}
private void timetableEditDoubleClick(object sender, DataGridViewCellEventArgs e) {
DataGridViewRow row = taskTimeGridView.Rows[0];
string uid = row.Cells[0].Value();
}
private void executeSql(string command) {
SqliteConnection con = new SqliteConnection(sqlConnectionString);
SqliteCommand sqliteCmd = con.CreateCommand();
@ -151,6 +178,8 @@ namespace TimeTable
}
private void btnStartClick(object sender, EventArgs e) {
UidCommand uidCmd = SqliteCommands.InsertCmd(DateTime.Now);
uid = uidCmd.uid;
@ -164,7 +193,6 @@ namespace TimeTable
private void btnStopResumeClick(object sender, EventArgs e) {
String cmd = SqliteCommands.UpdateEndCmd(uid, DateTime.Now);
executeSql(cmd);
taskTimeGridView.DataSource = dataAdapter;
}
private void btnTaskStopClick(object sender, EventArgs e) {
@ -183,7 +211,9 @@ namespace TimeTable
private Panel tableView;
private DataGridView taskTimeGridView;
private string uid;
string sqlConnectionString;
private SqlDataAdapter dataAdapter;
private BindingSource bindingSource;
private SQLiteConnection con;
private SQLiteDataAdapter dataAdapter;
private System.ComponentModel.IContainer components;
}
}

View File

@ -117,4 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="bindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>381, 17</value>
</metadata>
<metadata name="con.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>161, 17</value>
</metadata>
<metadata name="dataAdapter.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>241, 17</value>
</metadata>
</root>

167
TimeTable/view/RowEdit.Designer.cs generated Normal file
View File

@ -0,0 +1,167 @@
namespace TimeTable.view {
partial class RowEdit {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
uidTxt = new Label();
startTxt = new Label();
EndTxt = new Label();
textTxt = new Label();
uidLbl = new Label();
startTimePicker = new DateTimePicker();
endTimePicker = new DateTimePicker();
textBox = new TextBox();
btnSave = new Button();
btnCancel = new Button();
SuspendLayout();
//
// uidTxt
//
uidTxt.AutoSize = true;
uidTxt.Location = new Point(12, 20);
uidTxt.Name = "uidTxt";
uidTxt.Size = new Size(34, 20);
uidTxt.TabIndex = 0;
uidTxt.Text = "UID";
//
// startTxt
//
startTxt.AutoSize = true;
startTxt.Location = new Point(12, 54);
startTxt.Name = "startTxt";
startTxt.Size = new Size(40, 20);
startTxt.TabIndex = 1;
startTxt.Text = "Start";
//
// EndTxt
//
EndTxt.AutoSize = true;
EndTxt.Location = new Point(12, 88);
EndTxt.Name = "EndTxt";
EndTxt.Size = new Size(34, 20);
EndTxt.TabIndex = 2;
EndTxt.Text = "End";
//
// textTxt
//
textTxt.AutoSize = true;
textTxt.Location = new Point(12, 126);
textTxt.Name = "textTxt";
textTxt.Size = new Size(36, 20);
textTxt.TabIndex = 3;
textTxt.Text = "Text";
//
// uidLbl
//
uidLbl.AutoSize = true;
uidLbl.Location = new Point(71, 20);
uidLbl.Name = "uidLbl";
uidLbl.Size = new Size(34, 20);
uidLbl.TabIndex = 4;
uidLbl.Text = "UID";
//
// startTimePicker
//
startTimePicker.Location = new Point(71, 49);
startTimePicker.Name = "startTimePicker";
startTimePicker.Size = new Size(250, 27);
startTimePicker.TabIndex = 5;
//
// endTimePicker
//
endTimePicker.Location = new Point(71, 88);
endTimePicker.Name = "endTimePicker";
endTimePicker.Size = new Size(250, 27);
endTimePicker.TabIndex = 6;
//
// textBox
//
textBox.Location = new Point(71, 126);
textBox.Name = "textBox";
textBox.Size = new Size(250, 27);
textBox.TabIndex = 7;
//
// btnSave
//
btnSave.Location = new Point(134, 173);
btnSave.Name = "btnSave";
btnSave.Size = new Size(101, 30);
btnSave.TabIndex = 8;
btnSave.Text = "Save";
btnSave.UseVisualStyleBackColor = true;
btnSave.Click += button1_Click;
//
// btnCancel
//
btnCancel.Location = new Point(241, 173);
btnCancel.Name = "btnCancel";
btnCancel.Size = new Size(101, 30);
btnCancel.TabIndex = 9;
btnCancel.Text = "Cancel";
btnCancel.UseVisualStyleBackColor = true;
//
// RowEdit
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(354, 215);
Controls.Add(btnCancel);
Controls.Add(btnSave);
Controls.Add(textBox);
Controls.Add(endTimePicker);
Controls.Add(startTimePicker);
Controls.Add(uidLbl);
Controls.Add(textTxt);
Controls.Add(EndTxt);
Controls.Add(startTxt);
Controls.Add(uidTxt);
FormBorderStyle = FormBorderStyle.FixedSingle;
Name = "RowEdit";
Text = "RowEdit";
ResumeLayout(false);
PerformLayout();
}
#endregion
public void setData(string uid, string start, string end, string text) {
uidLbl.Text = uid;
startTimePicker.Text = start;
endTimePicker.Text = end;
textBox.Text = text;
}
private Label uidTxt;
private Label startTxt;
private Label EndTxt;
private Label textTxt;
private Label uidLbl;
private DateTimePicker startTimePicker;
private DateTimePicker endTimePicker;
private TextBox textBox;
private Button btnSave;
private Button btnCancel;
}
}

11
TimeTable/view/RowEdit.cs Normal file
View File

@ -0,0 +1,11 @@
namespace TimeTable.view {
public partial class RowEdit : Form {
public RowEdit() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
}
}
}

120
TimeTable/view/RowEdit.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>