using Microsoft.Data.SqlClient; using Microsoft.Data.Sqlite; using System; using System.Data; using System.Data.Common; using System.Data.SQLite; using System.Drawing; using System.Windows.Forms; using TimeTable.controll; using TimeTable.model; using TimeTable.view; namespace TimeTable { partial class Main { /// /// Required designer variable. /// private string sqlConnectionString = "Data Source=" + Directory.GetCurrentDirectory() + "\\sqllite.db"; #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { components = new System.ComponentModel.Container(); btnPanel = new Panel(); uidLbl = new Label(); uidText = new Label(); btnDelete = new Button(); btnTaskStop = new Button(); btnTaskStart = new Button(); btnStop = new Button(); btnStart = new Button(); tableView = new Panel(); timeTableGridView = new DataGridView(); bindingSource = new BindingSource(components); con = new SQLiteConnection(); dataAdapter = new SQLiteDataAdapter(); taskTableGridView = new DataGridView(); btnPanel.SuspendLayout(); tableView.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)timeTableGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)bindingSource).BeginInit(); ((System.ComponentModel.ISupportInitialize)taskTableGridView).BeginInit(); SuspendLayout(); // // btnPanel // btnPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; btnPanel.Controls.Add(uidLbl); btnPanel.Controls.Add(uidText); btnPanel.Controls.Add(btnDelete); btnPanel.Controls.Add(btnTaskStop); btnPanel.Controls.Add(btnTaskStart); btnPanel.Controls.Add(btnStop); btnPanel.Controls.Add(btnStart); btnPanel.Dock = DockStyle.Left; btnPanel.Location = new Point(0, 0); btnPanel.Name = "btnPanel"; btnPanel.Size = new Size(233, 378); btnPanel.TabIndex = 0; // // uidLbl // uidLbl.AutoSize = true; uidLbl.Location = new Point(3, 152); uidLbl.Name = "uidLbl"; uidLbl.Size = new Size(42, 20); uidLbl.TabIndex = 2; uidLbl.Text = "none"; // // uidText // uidText.AutoSize = true; uidText.Location = new Point(3, 122); uidText.Name = "uidText"; uidText.Size = new Size(95, 20); uidText.TabIndex = 5; uidText.Text = "Selected UID"; // // btnDelete // btnDelete.Location = new Point(3, 73); btnDelete.Name = "btnDelete"; btnDelete.Size = new Size(94, 26); btnDelete.TabIndex = 4; btnDelete.Text = "Delete"; btnDelete.UseVisualStyleBackColor = true; btnDelete.Click += DeleteRow; // // btnTaskStop // btnTaskStop.Location = new Point(103, 38); btnTaskStop.Name = "btnTaskStop"; btnTaskStop.Size = new Size(114, 29); btnTaskStop.TabIndex = 3; btnTaskStop.Text = "Task Stop"; btnTaskStop.UseVisualStyleBackColor = true; // // btnTaskStart // btnTaskStart.Location = new Point(3, 38); btnTaskStart.Name = "btnTaskStart"; btnTaskStart.Size = new Size(94, 29); btnTaskStart.TabIndex = 2; btnTaskStart.Text = "Task Start"; btnTaskStart.UseVisualStyleBackColor = true; // // btnStop // 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 // btnStart.Location = new Point(3, 3); btnStart.Name = "btnStart"; btnStart.Size = new Size(94, 29); btnStart.TabIndex = 0; btnStart.Text = "Start"; btnStart.UseVisualStyleBackColor = true; btnStart.Click += btnStartClick; // // tableView // tableView.AutoSizeMode = AutoSizeMode.GrowAndShrink; tableView.Controls.Add(taskTableGridView); 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; // // timeTableGridView // 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 // con.BusyTimeout = 0; 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; OtherTasks(); // // taskTableGridView // taskTableGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; taskTableGridView.Dock = DockStyle.Bottom; taskTableGridView.Location = new Point(0, 232); taskTableGridView.Name = "taskTableGridView"; taskTableGridView.RowHeadersWidth = 51; taskTableGridView.Size = new Size(631, 146); taskTableGridView.TabIndex = 1; // // Main // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(864, 378); Controls.Add(tableView); Controls.Add(btnPanel); Name = "Main"; Text = "TimeTable"; btnPanel.ResumeLayout(false); btnPanel.PerformLayout(); tableView.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)timeTableGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)bindingSource).EndInit(); ((System.ComponentModel.ISupportInitialize)taskTableGridView).EndInit(); ResumeLayout(false); } private void OtherTasks() { SqliteTimeTableCommands.CreateTableIfNotExists(sqlConnectionString); timeTableGridView.AutoGenerateColumns = true; con.ConnectionString = sqlConnectionString; bindingSource.DataSource = createDataTable(); SqliteTaskCommands.CreateTableIfNotExists(sqlConnectionString); taskTableGridView.AutoGenerateColumns = true; } public 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 DeleteRow(object sender, EventArgs e) { SqliteTimeTableCommands.DeleteTableRow(uid, sqlConnectionString); bindingSource.DataSource = createDataTable(); } private void TimetableEditDoubleClick(object sender, DataGridViewCellEventArgs e) { 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); rowEdit.ShowDialog(); } private void TimeTableClick(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = timeTableGridView.Rows[e.RowIndex]; string uid = row.Cells[4].Value.ToString(); uidLbl.Text = uid; this.uid = uid; 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); dataAdapter.SelectCommand = sqlCommand; dataAdapter.Fill(table); taskTableGridView.DataSource = table; } public void executeSql(string command) { SqliteConnection con = new SqliteConnection(sqlConnectionString); SqliteCommand sqliteCmd = con.CreateCommand(); sqliteCmd.CommandText = command; 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); } private void btnTaskStartClick(object sender, EventArgs e) { } private void btnStopClick(object sender, EventArgs e) { AddText text = new AddText(); text. String cmd = SqliteTimeTableCommands.UpdateEndCmd(uid, DateTime.Now); executeSql(cmd); } private void btnTaskStopClick(object sender, EventArgs e) { } #endregion private Panel btnPanel; private Button btnTaskStop; private Button btnTaskStart; private Button btnStop; private Button btnStart; private Panel tableView; private DataGridView timeTableGridView; private string uid; private BindingSource bindingSource; private SQLiteConnection con; private SQLiteDataAdapter dataAdapter; private System.ComponentModel.IContainer components; private Button btnDelete; private Label uidText; private Label uidLbl; private DataGridView taskTableGridView; } }