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; 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(); btnTaskStop = new Button(); btnTaskStart = new Button(); btnStopResume = new Button(); btnStart = new Button(); tableView = new Panel(); taskTimeGridView = new DataGridView(); bindingSource = new BindingSource(components); con = new SQLiteConnection(); dataAdapter = new SQLiteDataAdapter(); btnDelete = new Button(); btnPanel.SuspendLayout(); tableView.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)taskTimeGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)bindingSource).BeginInit(); SuspendLayout(); // // btnPanel // btnPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; btnPanel.Controls.Add(btnDelete); btnPanel.Controls.Add(btnTaskStop); btnPanel.Controls.Add(btnTaskStart); btnPanel.Controls.Add(btnStopResume); 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; // // 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; btnTaskStart.Click += btnStopResumeClick; // // btnStopResume // btnStopResume.Location = new Point(103, 3); btnStopResume.Name = "btnStopResume"; btnStopResume.Size = new Size(114, 29); btnStopResume.TabIndex = 1; btnStopResume.Text = "Stop/Resume"; btnStopResume.UseVisualStyleBackColor = true; // // 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(taskTimeGridView); tableView.Dock = DockStyle.Fill; tableView.Location = new Point(233, 0); tableView.Name = "tableView"; 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.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.CellDoubleClick += TimetableEditDoubleClick; // // con // con.BusyTimeout = 0; 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(); // // btnDelete // btnDelete.Location = new Point(8, 78); btnDelete.Name = "btnDelete"; btnDelete.Size = new Size(94, 26); btnDelete.TabIndex = 4; btnDelete.Text = "Delete"; btnDelete.UseVisualStyleBackColor = true; btnDelete.Click += DeleteRow; // // 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); 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 DeleteRow(object sender, EventArgs e) { DataGridViewRow row = taskTimeGridView.Rows[0]; string currentId = row.Cells[0].Value.ToString(); SqliteCommands.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(); RowEdit rowEdit = new RowEdit(); rowEdit.Data(uid, start, end, text); rowEdit.ShowDialog(); } private void executeSql(string command) { SqliteConnection con = new SqliteConnection(sqlConnectionString); SqliteCommand sqliteCmd = con.CreateCommand(); sqliteCmd.CommandText = command; con.Open(); sqliteCmd.ExecuteNonQuery(); con.Close(); bindingSource.DataSource = createDataTable(); } private void btnStartClick(object sender, EventArgs e) { UidCommand uidCmd = SqliteCommands.InsertCmd(DateTime.Now); uid = uidCmd.uid; executeSql(uidCmd.command); } private void btnTaskStartClick(object sender, EventArgs e) { } private void btnStopResumeClick(object sender, EventArgs e) { String cmd = SqliteCommands.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 btnStopResume; private Button btnStart; private Panel tableView; private DataGridView taskTimeGridView; private string uid; private BindingSource bindingSource; private SQLiteConnection con; private SQLiteDataAdapter dataAdapter; private System.ComponentModel.IContainer components; private Button btnDelete; } }