private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl1.SelectedIndex == 0) { txt_habitSearch.Focus(); } if (tabControl1.SelectedIndex == 1) { taskId = JournalTask.TabChangeHandler(dataGrid_dailyTask); txt_dailySearch.Focus(); } if (tabControl1.SelectedIndex == 2) { taskId = JournalTask.TabChangeHandler(dataGrid_monthly); txt_monthlySearch.Focus(); } if (tabControl1.SelectedIndex == 3) { taskId = JournalTask.TabChangeHandler(dataGrid_futureLog);; txt_futureSearch.Focus(); } if (tabControl1.SelectedIndex == 4) { taskId = JournalTask.TabChangeHandler(dataGrid_notes); txt_collectionSearch.Focus(); } }
private void dataGrid_content_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int temp = 0; if (entryType == JournalTask.EntryType.daily) { temp = JournalTask.GetCurrentTaskIds(selectedId).Count; } if (entryType == JournalTask.EntryType.monthly) { temp = JournalTask.GetMonthlyTaskIds(selectedId).Count; } if (entryType == JournalTask.EntryType.future) { temp = JournalTask.GetFutureTaskIds(selectedId).Count; } if (temp == 0) { return; } using (History history = new History(JournalTask.EntryType.daily, title, layer + 1, selectedId)) { history.OnTaskUndone += OnRefreshGrid; history.ShowDialog(); } }
private void dataGrid_content_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { // Store collection id and show contextmenu selectedId = JournalTask.ContextMenuHandler(dataGrid_content, contextMenuStrip1, e); } }
private void dataGrid_content_CellContentClick(object sender, DataGridViewCellEventArgs e) { selectedId = JournalTask.ContentClickHandler(dataGrid_content, e); string command = ""; if (entryType == JournalTask.EntryType.daily) { command = "update currenttasks " + "set " + "iscompleted = @iscompleted, " + "datecompleted = @completeddate " + "where id = @id"; } if (entryType == JournalTask.EntryType.monthly) { command = "update monthlytasks " + "set " + "iscompleted = @iscompleted, " + "datecompleted = @completeddate " + "where id = @id"; } if (entryType == JournalTask.EntryType.future) { command = "update futuretasks " + "set " + "iscompleted = @iscompleted, " + "datecompleted = @completeddate " + "where id = @id"; } if (e.ColumnIndex == 0) { foreach (int pickedId in JournalTask.GetAllPreviousLayerId(selectedId, entryType)) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int) { Value = pickedId }, new SqlParameter("@iscompleted", SqlDbType.Bit) { Value = false }, new SqlParameter("@completeddate", SqlDbType.DateTime) { Value = DBNull.Value } }; db.GenericNonQueryAction(command, parameter); } OnRefreshGrid(); } }
private void dataGrid_content_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == dataGrid_content.Columns["btn_undo"].Index) { if (dataGrid_content.Rows[e.RowIndex].Cells[4].Value.ToString() != "Completed") { JournalTask.DataGridViewCellVisibility(dataGrid_content.Rows[e.RowIndex].Cells["btn_undo"], false); } } }
private void dataGrid_content_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { selectedId = JournalTask.ContextMenuHandler(dataGrid_content, contextMenuStrip1, e); } if (e.Button == MouseButtons.Left) { selectedId = JournalTask.ContextMenuHandler(dataGrid_content, contextMenuStrip1, e); contextMenuStrip1.Hide(); } }
private void dataGrid_collection_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { // Right Click if (e.Button == MouseButtons.Right) { title = dataGrid_notes.SelectedRows[0].Cells[1].Value.ToString(); // Store id taskId = JournalTask.ContextMenuHandler(dataGrid_notes, contextMenuStrip1, e); contextMenuStrip1.Items["migrate"].Visible = false; entryType = JournalTask.EntryType.notes; } }
private void dataGrid_content_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { selectedId = JournalTask.ContextMenuHandler(dataGrid_content, contextMenuStrip1, e); title = dataGrid_content.SelectedRows[0].Cells[5].Value.ToString(); } if (e.Button == MouseButtons.Left) { selectedId = JournalTask.ContextMenuHandler(dataGrid_content, contextMenuStrip1, e); if (selectedId != 0) { title = dataGrid_content.SelectedRows[0].Cells[5].Value.ToString(); } contextMenuStrip1.Hide(); } }
private void deleteToolStripMenuItem_Click(object sender, System.EventArgs e) { string command = "delete from notes " + "where id = @ids"; List <int> ids = JournalTask.GetAllNoteId(selectedId); for (int i = 0; i < ids.Count; i++) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@ids", SqlDbType.Int) { Value = ids[i] } }; db.GenericNonQueryAction(command, parameter); } OnNotesSaved(); }
private void dataGrid_content_CellContentClick(object sender, DataGridViewCellEventArgs e) { selectedId = JournalTask.ContentClickHandler(dataGrid_content, e); if (e.ColumnIndex == 1) { string command = "update monthlytasks " + "set " + "iscompleted = @iscompleted, " + "datecompleted = @completeddate " + "where id = @id"; List <int> ids = JournalTask.GetAllMonthlyTasksId(selectedId); for (int i = 0; i < ids.Count; i++) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int) { Value = ids[i] }, new SqlParameter("@iscompleted", SqlDbType.Bit) { Value = true }, new SqlParameter("@completeddate", SqlDbType.DateTime) { Value = DateTime.Now } }; db.GenericNonQueryAction(command, parameter); } OnMonthlyTaskSave(); } }
private void dataGrid_futureLog_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Left) { taskId = JournalTask.ContextMenuHandler(dataGrid_futureLog, contextMenuStrip1, e); if (taskId != 0) { title = dataGrid_futureLog.SelectedRows[0].Cells[4].Value.ToString(); } entryType = JournalTask.EntryType.future; contextMenuStrip1.Hide(); } // right clock if (e.Button == MouseButtons.Right) { title = dataGrid_futureLog.SelectedRows[0].Cells[4].Value.ToString(); taskId = JournalTask.ContextMenuHandler(dataGrid_futureLog, contextMenuStrip1, e); entryType = JournalTask.EntryType.future; } }
private void dataGrid_content_CellContentClick(object sender, DataGridViewCellEventArgs e) { selectedId = JournalTask.ContentClickHandler(dataGrid_content, e); string command = "select isvisible from habit where id = @id"; SqlParameter[] paramter = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int) { Value = selectedId } }; bool visibility = db.GenericQueryAction(command, paramter).AsEnumerable().ToList()[0].Field <bool>("isvisible"); command = "update habit " + "set " + "isvisible = @isvisible " + "where id = @id"; paramter = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int) { Value = selectedId }, new SqlParameter("@isvisible", SqlDbType.Bit) { Value = !visibility } }; db.GenericQueryAction(command, paramter); RefreshGrid(); }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { // validation if (!(JournalTask.IsInputInvalid(txt_notes))) { return; } // add if (mode == JournalTask.EntryMode.add) { string command = "insert into notes " + "(notedescription, layerid, previouslayerid, dateadded, datechanged) " + "values " + "(@desc, @layerid, @prevlayer, @dateadded, @datechanged) "; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@desc", SqlDbType.NVarChar) { Value = txt_notes.Text }, new SqlParameter("@layerid", SqlDbType.Int) { Value = layer }, new SqlParameter("@prevlayer", SqlDbType.Int) { Value = id }, new SqlParameter("@dateadded", SqlDbType.DateTime) { Value = DateTime.Now }, new SqlParameter("@datechanged", SqlDbType.DateTime) { Value = DateTime.Now } }; db.GenericNonQueryAction(command, parameter); } // edit if (mode == JournalTask.EntryMode.edit) { string command = "update notes " + "set " + "notedescription = @desc, " + "datechanged = @datechanged " + "where id = @id"; SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@desc", SqlDbType.NVarChar) { Value = txt_notes.Text }, new SqlParameter("@id", SqlDbType.Int) { Value = id }, new SqlParameter("@datechanged", SqlDbType.DateTime) { Value = DateTime.Now } }; db.GenericNonQueryAction(command, parameters); } // Cleanup txt_notes.Text = ""; // Broadcast the event OnNotesSave(); // Close when on edit mode if (mode == JournalTask.EntryMode.edit) { this.Close(); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { // validation if (!(JournalTask.IsInputInvalid(txt_currentTaskDescription))) { return; } // add if (mode == JournalTask.EntryMode.add) { string command = "insert into futuretasks " + "(description, layerid, previouslayerid, dateadded, datechanged, taskisimportant, tasktype) " + "values " + "(@desc, @layerid, @prevlayer, @dateadded, @datechanged, @taskisimportant, @tasktype) "; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@desc", SqlDbType.NVarChar) { Value = txt_currentTaskDescription.Text }, new SqlParameter("@layerid", SqlDbType.Int) { Value = layer }, new SqlParameter("@prevlayer", SqlDbType.Int) { Value = id }, new SqlParameter("@dateadded", SqlDbType.DateTime) { Value = DateTime.Now }, new SqlParameter("@datechanged", SqlDbType.DateTime) { Value = DateTime.Now }, new SqlParameter("@taskisimportant", SqlDbType.Bit) { Value = chk_taskIsImportant.Checked }, new SqlParameter("@tasktype", SqlDbType.Int) { Value = JournalTask.GetTask(cmb_taskType.Text) } }; db.GenericNonQueryAction(command, parameter); } // edit if (mode == JournalTask.EntryMode.edit) { string command = "update futuretasks " + "set " + "description = @desc, " + "datechanged = @datechanged," + "tasktype = @tasktype, " + "taskisimportant = @taskisimportant " + "where id = @id"; SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@desc", SqlDbType.NVarChar) { Value = txt_currentTaskDescription.Text }, new SqlParameter("@id", SqlDbType.Int) { Value = id }, new SqlParameter("@datechanged", SqlDbType.DateTime) { Value = DateTime.Now }, new SqlParameter("@tasktype", SqlDbType.Int) { Value = JournalTask.GetTask(cmb_taskType.Text) }, new SqlParameter("@taskisimportant", SqlDbType.Bit) { Value = chk_taskIsImportant.Checked } }; db.GenericNonQueryAction(command, parameters); } // migrate if (mode == JournalTask.EntryMode.migrate) { string command = "insert into futuretasks " + "(description, layerid, previouslayerid, dateadded, datechanged, taskisimportant, tasktype) " + "output inserted.id " + "values " + "(@desc, @layerid, @prevlayer, @dateadded, @datechanged, @taskisimportant, @tasktype) "; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@desc", SqlDbType.NVarChar) { Value = txt_currentTaskDescription.Text }, new SqlParameter("@layerid", SqlDbType.Int) { Value = 0 }, new SqlParameter("@prevlayer", SqlDbType.Int) { Value = -1 }, new SqlParameter("@dateadded", SqlDbType.DateTime) { Value = DateTime.Now }, new SqlParameter("@datechanged", SqlDbType.DateTime) { Value = DateTime.Now }, new SqlParameter("@taskisimportant", SqlDbType.Bit) { Value = chk_taskIsImportant.Checked }, new SqlParameter("@tasktype", SqlDbType.Int) { Value = JournalTask.GetTask(cmb_taskType.Text) } }; int insertedId = db.GenericScalarAction(command, parameter); switch (entryType) { case JournalTask.EntryType.daily: MigrationHelper.MigrateDailyToFuture(id, insertedId); break; case JournalTask.EntryType.monthly: MigrationHelper.MigrateMonthlyToFuture(id, insertedId); break; case JournalTask.EntryType.future: MigrationHelper.MigrateFutureToFuture(id, insertedId); break; default: break; } } // Cleanup txt_currentTaskDescription.Text = ""; // Broadcast the event OnFutureTaskSave(); // Close when on edit mode if (mode != JournalTask.EntryMode.add) { this.Close(); } }
private void Populate_DailyTasks() { List <int> layerIds = JournalTask.GetAllIdInLayer(layer, entryType); List <int> validIds = new List <int>(); string command = "select count(*) from currenttasks " + "where id = @id " + "and datecompleted is not null"; foreach (int layerId in layerIds) { List <int> taskIds = JournalTask.GetAllCurrentTasksId(layerId); int contentCounter = 0; foreach (int taskId in taskIds) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int) { Value = taskId } }; if (db.GenericQueryAction(command, parameter).AsEnumerable().ToList()[0].Field <int>(0) > 0) { contentCounter++; } } if (contentCounter != 0) { validIds.Add(layerId); } } command = "select " + "a.id, " + "case " + "when a.taskisimportant = 1 " + "then '*' " + "else '' end as [I], " + "case " + "when a.tasktype = 0 then 'TASK' " + "when a.tasktype = 1 then 'EVENT' " + "when a.tasktype = 2 then 'NOTES' " + "else 'CLOSED' end as [Type], " + "case when a.iscompleted = 1 then 'Completed' " + "else 'Incomplete' end as [Status], " + "a.description as [Description], " + "sum(case when b.datecompleted is not null and b.id is not null then 1 " + "else 0 end) as [Contents], " + "format(a.datecompleted, 'dd/MM/yyyy, hh:mm:ss tt') as [Date Completed], " + "format(a.dateadded, 'dd/MM/yyyy, hh:mm:ss tt') as [Date Added], " + "format(a.datechanged, 'dd/MM/yyyy, hh:mm:ss tt') as [Date Changed] " + "from currenttasks as a " + "left join currenttasks as b " + "on a.id = b.previouslayerid " + "where a.layerid = @layerid " + "and a.id in ({0}) " + "and a.description like @filter " + "and a.previouslayerid = case " + "when @layerid = 0 " + "then a.previouslayerid " + "else @currentid end " + "group by a.id, " + "case when a.iscompleted = 1 then 'Completed' " + "else 'Incomplete' end, " + "a.description, " + "case " + "when a.tasktype = 0 then 'TASK' " + "when a.tasktype = 1 then 'EVENT' " + "when a.tasktype = 2 then 'NOTES' " + "else 'CLOSED' end, " + "case " + "when a.taskisimportant = 1 " + "then '*' " + "else '' end, " + "a.description, " + "format(a.datecompleted, 'dd/MM/yyyy, hh:mm:ss tt'), " + "format(a.dateadded, 'dd/MM/yyyy, hh:mm:ss tt'), " + "format(a.datechanged, 'dd/MM/yyyy, hh:mm:ss tt')"; command = String.Format(command, String.Join(",", validIds.Count > 0 ? validIds : new List <int>() { -1 })); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@layerid", SqlDbType.Int) { Value = layer }, new SqlParameter("@currentId", SqlDbType.Int) { Value = currentId }, new SqlParameter("@filter", SqlDbType.NVarChar) { Value = '%' + txt_historySearch.Text + '%' } }; dataGrid_content.Columns["btn_undo"].Width = 70; dataGrid_content.DataSource = db.GenericQueryAction(command, parameters); dataGrid_content.Columns["id"].Visible = false; dataGrid_content.Columns["id"].Width = 1; dataGrid_content.Columns["Status"].Width = 70; dataGrid_content.Columns["I"].Width = 30; dataGrid_content.Columns["I"].Visible = Properties.Settings.Default.DailyTaskIsImportant; dataGrid_content.Columns["Type"].Width = 60; dataGrid_content.Columns["Type"].Visible = Properties.Settings.Default.DailyTaskType; dataGrid_content.Columns["Description"].Width = 400; dataGrid_content.Columns["Description"].DefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGrid_content.Columns["Contents"].Width = 70; dataGrid_content.Columns["Date Completed"].Width = 150; dataGrid_content.Columns["Date Added"].Width = 150; dataGrid_content.Columns["Date Added"].Visible = Properties.Settings.Default.DailyDateAdded; dataGrid_content.Columns["Date Changed"].Width = 150; dataGrid_content.Columns["Date Changed"].Visible = Properties.Settings.Default.DailyDateChanged; }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { if (entryType == JournalTask.EntryType.daily) { string command = "delete from currenttasks " + "where id = @ids"; List <int> ids = JournalTask.GetAllCurrentTasksId(taskId); for (int i = 0; i < ids.Count; i++) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@ids", SqlDbType.Int) { Value = ids[i] } }; db.GenericNonQueryAction(command, parameter); } RefreshGrid(); } if (entryType == JournalTask.EntryType.monthly) { string command = "delete from monthlytasks " + "where id = @ids"; List <int> ids = JournalTask.GetAllMonthlyTasksId(taskId); for (int i = 0; i < ids.Count; i++) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@ids", SqlDbType.Int) { Value = ids[i] } }; db.GenericNonQueryAction(command, parameter); } RefreshGrid(); } if (entryType == JournalTask.EntryType.future) { string command = "delete from futuretasks " + "where id = @ids"; List <int> ids = JournalTask.GetAllFutureTasksId(taskId); for (int i = 0; i < ids.Count; i++) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@ids", SqlDbType.Int) { Value = ids[i] } }; db.GenericNonQueryAction(command, parameter); } RefreshGrid(); } if (entryType == JournalTask.EntryType.notes) { string command = "delete from notes " + "where id = @ids"; List <int> ids = JournalTask.GetAllNoteId(taskId); for (int i = 0; i < ids.Count; i++) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@ids", SqlDbType.Int) { Value = ids[i] } }; db.GenericNonQueryAction(command, parameter); } RefreshGrid(); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { // validation if (!(JournalTask.IsInputInvalid(txt_currentTaskDescription))) { return; } if (entryMode == JournalTask.EntryMode.add) { string command = "insert into habit " + "(description, isvisible) " + "values " + "(@description, @isvisible)"; SqlParameter[] paramter = new SqlParameter[] { new SqlParameter("@description", SqlDbType.NVarChar) { Value = txt_currentTaskDescription.Text }, new SqlParameter("isvisible", SqlDbType.Bit) { Value = chk_taskIsVisible.Checked } }; db.GenericNonQueryAction(command, paramter); } if (entryMode == JournalTask.EntryMode.edit) { string command = "update habit " + "set " + "description = @desc, " + "isvisible = @isvisible " + "where id = @id"; SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@desc", SqlDbType.NVarChar) { Value = txt_currentTaskDescription.Text }, new SqlParameter("@id", SqlDbType.Int) { Value = id }, new SqlParameter("@isvisible", SqlDbType.Bit) { Value = chk_taskIsVisible.Checked } }; db.GenericNonQueryAction(command, parameters); } txt_currentTaskDescription.Text = ""; if (entryMode == JournalTask.EntryMode.edit) { this.Close(); } OnSave(); }
private void dataGrid_content_SelectionChanged(object sender, System.EventArgs e) { selectedId = JournalTask.TabChangeHandler(dataGrid_content); }
private void dataGrid_tracker_CellContentClick(object sender, DataGridViewCellEventArgs e) { taskId = JournalTask.ContentClickHandler(dataGrid_tracker, e); // MessageBox.Show(dataGrid_tracker.Columns[e.ColumnIndex].HeaderText); string headerText = dataGrid_tracker.Columns[e.ColumnIndex].HeaderText; DateTime dateTime = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, int.Parse(headerText)); string command = "select iscompleted from tracker " + "where habitid = @id " + "and habitdate = @habitdate"; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int) { Value = taskId }, new SqlParameter("@habitdate", SqlDbType.DateTime) { Value = dateTime } }; DataTable dataTable = db.GenericQueryAction(command, parameter); if (dataTable.Rows.Count > 0) { bool visibility = dataTable.AsEnumerable().ToList()[0].Field <bool>("iscompleted"); command = "update tracker " + "set " + "iscompleted = @iscompleted " + "where habitid = @id " + "and habitdate = @habitdate"; parameter = new SqlParameter[] { new SqlParameter("@id", SqlDbType.Int) { Value = taskId }, new SqlParameter("@habitdate", SqlDbType.DateTime) { Value = dateTime }, new SqlParameter("@iscompleted", SqlDbType.Bit) { Value = !visibility } }; db.GenericNonQueryAction(command, parameter); } else { command = "insert into tracker " + "(habitid, habitdate, iscompleted) " + "values" + "(@habitid, @habitdate, @iscompleted)"; parameter = new SqlParameter[] { new SqlParameter("@habitid", SqlDbType.Int) { Value = taskId }, new SqlParameter("@iscompleted", SqlDbType.Bit) { Value = true }, new SqlParameter("@habitdate", SqlDbType.Date) { Value = dateTime } }; db.GenericNonQueryAction(command, parameter); } CheckAllHabits(); }