Minor code refactoring (renaming functions, variables, etc

This commit is contained in:
c0d3.m0nk3y 2026-05-15 13:55:25 -04:00
parent 29497cc003
commit e9ec7ca392
11 changed files with 203 additions and 177 deletions

View File

@ -261,21 +261,21 @@
addTaskSubtaskToolStripMenuItem.Name = "addTaskSubtaskToolStripMenuItem"; addTaskSubtaskToolStripMenuItem.Name = "addTaskSubtaskToolStripMenuItem";
addTaskSubtaskToolStripMenuItem.Size = new Size(370, 38); addTaskSubtaskToolStripMenuItem.Size = new Size(370, 38);
addTaskSubtaskToolStripMenuItem.Text = "Add Task / Sub-task"; addTaskSubtaskToolStripMenuItem.Text = "Add Task / Sub-task";
addTaskSubtaskToolStripMenuItem.Click += addTaskSubtaskToolStripMenuItem_Click; addTaskSubtaskToolStripMenuItem.Click += PTask_AddTaskSubtaskToolStripMenuItem_Click;
// //
// editThisTaskSubtaskToolStripMenuItem // editThisTaskSubtaskToolStripMenuItem
// //
editThisTaskSubtaskToolStripMenuItem.Name = "editThisTaskSubtaskToolStripMenuItem"; editThisTaskSubtaskToolStripMenuItem.Name = "editThisTaskSubtaskToolStripMenuItem";
editThisTaskSubtaskToolStripMenuItem.Size = new Size(370, 38); editThisTaskSubtaskToolStripMenuItem.Size = new Size(370, 38);
editThisTaskSubtaskToolStripMenuItem.Text = "Edit this Task / Sub-task"; editThisTaskSubtaskToolStripMenuItem.Text = "Edit this Task / Sub-task";
editThisTaskSubtaskToolStripMenuItem.Click += editThisTaskSubtaskToolStripMenuItem_Click; editThisTaskSubtaskToolStripMenuItem.Click += PTask_EditThisTaskSubtaskToolStripMenuItem_Click;
// //
// deleteThisTaskSubtaskToolStripMenuItem // deleteThisTaskSubtaskToolStripMenuItem
// //
deleteThisTaskSubtaskToolStripMenuItem.Name = "deleteThisTaskSubtaskToolStripMenuItem"; deleteThisTaskSubtaskToolStripMenuItem.Name = "deleteThisTaskSubtaskToolStripMenuItem";
deleteThisTaskSubtaskToolStripMenuItem.Size = new Size(370, 38); deleteThisTaskSubtaskToolStripMenuItem.Size = new Size(370, 38);
deleteThisTaskSubtaskToolStripMenuItem.Text = "Delete this Task / Sub-task"; deleteThisTaskSubtaskToolStripMenuItem.Text = "Delete this Task / Sub-task";
deleteThisTaskSubtaskToolStripMenuItem.Click += deleteThisTaskSubtaskToolStripMenuItem_Click; deleteThisTaskSubtaskToolStripMenuItem.Click += PTask_DeleteThisTaskSubtaskToolStripMenuItem_Click;
// //
// toolStripSeparator1 // toolStripSeparator1
// //
@ -287,7 +287,7 @@
addACommentToolStripMenuItem.Name = "addACommentToolStripMenuItem"; addACommentToolStripMenuItem.Name = "addACommentToolStripMenuItem";
addACommentToolStripMenuItem.Size = new Size(370, 38); addACommentToolStripMenuItem.Size = new Size(370, 38);
addACommentToolStripMenuItem.Text = "Add a comment"; addACommentToolStripMenuItem.Text = "Add a comment";
addACommentToolStripMenuItem.Click += addACommentToolStripMenuItem_Click; addACommentToolStripMenuItem.Click += PTask_AddACommentToolStripMenuItem_Click;
// //
// splitContainerTasks2 // splitContainerTasks2
// //
@ -356,7 +356,7 @@
richTextBoxTaskComments.Size = new Size(1218, 259); richTextBoxTaskComments.Size = new Size(1218, 259);
richTextBoxTaskComments.TabIndex = 1; richTextBoxTaskComments.TabIndex = 1;
richTextBoxTaskComments.Text = ""; richTextBoxTaskComments.Text = "";
richTextBoxTaskComments.LinkClicked += richTextBoxTaskComments_LinkClicked; richTextBoxTaskComments.LinkClicked += PTask_RichTextBoxTaskComments_LinkClicked;
// //
// MainForm // MainForm
// //

View File

@ -1,22 +1,22 @@
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using newcle.us.Forms;
using newcle.us.Utilities;
using System.ComponentModel; using System.ComponentModel;
using trakker.Data; using trakker.Data;
using trakker.Forms; using trakker.Forms;
using trakker.Interfaces; using trakker.Interfaces;
using trakker.Models; using trakker.Models;
using trakker.Services; using trakker.Services;
using trakker.Utilities;
namespace trakker namespace trakker
{ {
public partial class MainForm : Form, IMainForm public partial class MainForm : Form, IMainForm
{ {
//private readonly string _dbversion = "[N.N.N]"; private const string _AppVersion = "[n.n.n]";
private string connectionString = string.Empty; private static readonly string _empty = string.Empty;
private string _ConnectionString = _empty;
readonly MainCtrl _ctrl; readonly MainCtrl _ctrl;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="MainForm"/> class. /// Initializes a new instance of the <see cref="MainForm"/> class.
/// Sets up the form's controls and event handlers by calling /// Sets up the form's controls and event handlers by calling
@ -29,19 +29,19 @@ namespace trakker
// build connection string that will be used for database connections // build connection string that will be used for database connections
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
var dbPath = Path.Combine(AppContext.BaseDirectory, "trakker.db"); var dbPath = Path.Combine(AppContext.BaseDirectory, "trakker.db");
connectionString = new SqliteConnectionStringBuilder _ConnectionString = new SqliteConnectionStringBuilder
{ {
DataSource = dbPath, DataSource = dbPath,
Mode = SqliteOpenMode.ReadWriteCreate, Mode = SqliteOpenMode.ReadWriteCreate,
Cache = SqliteCacheMode.Shared Cache = SqliteCacheMode.Shared
}.ToString(); }.ToString();
Text = "Project Trakker - v[n.n.n] / pragmattica.com"; Text = $"Project Trakker - v{_AppVersion} / pragmattica.com";
tabControlMainForm.TabPages[0].Text = " Home "; tabControlMainForm.TabPages[0].Text = " Home ";
tabControlMainForm.TabPages[1].Text = " Clients "; tabControlMainForm.TabPages[1].Text = " Clients ";
tabControlMainForm.TabPages[2].Text = " Projects "; tabControlMainForm.TabPages[2].Text = " Projects ";
_ctrl = new Services.MainCtrl(this, connectionString); _ctrl = new Services.MainCtrl(this, _ConnectionString);
} }
/// <summary> /// <summary>
@ -55,7 +55,7 @@ namespace trakker
Application.Exit(); Application.Exit();
} }
public void InitDataGridViewClients(BindingList<Client> clients) public void Client_DataGridViewClients_Init(BindingList<Client> clients)
{ {
dataGridViewClients.AllowUserToAddRows = true; dataGridViewClients.AllowUserToAddRows = true;
dataGridViewClients.AllowUserToDeleteRows = true; dataGridViewClients.AllowUserToDeleteRows = true;
@ -112,56 +112,67 @@ namespace trakker
dataGridViewClients.DoubleClick += (s, e) => dataGridViewClients.DoubleClick += (s, e) =>
{ {
if (dataGridViewClients.SelectedRows.Count > 0) Client_DataGridViewClients_DoubleClick(s!, e);
{
var selectedClient = dataGridViewClients.SelectedRows[0].DataBoundItem as Client;
if (selectedClient != null)
{
var dialog = new ClientForm(selectedClient, _ctrl.GetLOV("state"));
if (dialog.ShowDialog(this) == DialogResult.OK)
{
Client client = dialog.Client;
ClientData clientData = new ClientData(connectionString);
try
{
clientData.Upsert(client);
dataGridViewClients.Refresh(); // Refresh the DataGridView to reflect changes
}
catch (Exception ex)
{
MessageBox.Show($"Error saving client: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}; };
dataGridViewClients.SelectionChanged += (s, e) => dataGridViewClients.SelectionChanged += (s, e) =>
{ {
if (dataGridViewClients.SelectedRows.Count > 0) Client_DataGridViewClients_SelectionChanged(s!, e);
{
var selectedClient = dataGridViewClients.SelectedRows[0].DataBoundItem as Client;
if (selectedClient != null)
{
// Handle the selected client as needed
// MessageBox.Show($"Selected Client: {selectedClient.AddressStreet}", "Client Selected", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
}
}; };
} }
public void FillDataGridViewProjects(BindingSource projects)
public void Client_DataGridViewClients_DoubleClick(object sender, EventArgs e)
{
if (dataGridViewClients.SelectedRows.Count > 0)
{
var selectedClient = dataGridViewClients.SelectedRows[0].DataBoundItem as Client;
if (selectedClient != null)
{
var dialog = new ClientForm(selectedClient, _ctrl.GetLOV("state"));
if (dialog.ShowDialog(this) == DialogResult.OK)
{
Client client = dialog.Client;
ClientData clientData = new ClientData(_ConnectionString);
try
{
clientData.Upsert(client);
dataGridViewClients.Refresh(); // Refresh the DataGridView to reflect changes
}
catch (Exception ex)
{
MessageBox.Show($"Error saving client: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
public void Client_DataGridViewClients_SelectionChanged(object sender, EventArgs e)
{
if (dataGridViewClients.SelectedRows.Count > 0)
{
var selectedClient = dataGridViewClients.SelectedRows[0].DataBoundItem as Client;
if (selectedClient != null)
{
// Handle the selected client as needed
// MessageBox.Show($"Selected Client: {selectedClient.AddressStreet}", "Client Selected", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
}
}
public void Project_DataGridViewProjects_Fill(BindingSource projects)
{ {
int idx = 0; int idx = 0;
if (dataGridViewProjects.CurrentRow != null) if (dataGridViewProjects.CurrentRow != null)
{ {
idx = dataGridViewProjects.CurrentRow.Index; idx = dataGridViewProjects.CurrentRow.Index;
} }
//MessageBox.Show($"Project idx: {idx}", "Debug Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
dataGridViewProjects.DataSource = projects; dataGridViewProjects.DataSource = projects;
dataGridViewProjects.Rows[idx].Selected = true; dataGridViewProjects.Rows[idx].Selected = true;
} }
public void InitDataGridViewProjects() public void Project_DataGridViewProjects_Init()
{ {
dataGridViewProjects.AllowUserToAddRows = true; dataGridViewProjects.AllowUserToAddRows = true;
dataGridViewProjects.AllowUserToDeleteRows = true; dataGridViewProjects.AllowUserToDeleteRows = true;
@ -268,55 +279,65 @@ namespace trakker
dataGridViewProjects.DoubleClick += (s, e) => dataGridViewProjects.DoubleClick += (s, e) =>
{ {
if (dataGridViewProjects.SelectedRows.Count > 0) Project_DataGridViewProjects_DoubleClick(s!, e);
{
var selectedIdx = dataGridViewProjects.SelectedRows[0].Index;
var selectedProject = dataGridViewProjects.SelectedRows[0].DataBoundItem as Project;
if (selectedProject != null)
{
var dialog = new ProjectForm(selectedProject, _ctrl.GetClients(), _ctrl.GetLOV("project.status"));
if (dialog.ShowDialog(this) == DialogResult.OK)
{
Project project = dialog.Project;
ProjectData projectData = new ProjectData(connectionString);
try
{
projectData.Upsert(project);
_ctrl.LoadProjects(); // Reload projects to update the DataGridView with any changes
dataGridViewProjects.ClearSelection();
if (selectedIdx >= 0 && selectedIdx < dataGridViewProjects.Rows.Count)
{
dataGridViewProjects.Rows[selectedIdx].Selected = true;
}
}
catch (Exception ex)
{
MessageBox.Show($"Error saving project: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
return;
}
}
}; };
dataGridViewProjects.SelectionChanged += (s, e) => dataGridViewProjects.SelectionChanged += (s, e) =>
{ {
if (_ctrl == null) return; // Safety check to prevent null reference exceptions during initialization) Project_DataGridViewProjects_SelectionChanged(s!, e);
if (dataGridViewProjects.SelectedRows.Count > 0)
{
var selectedProject = dataGridViewProjects.SelectedRows[0].DataBoundItem as Project;
if (selectedProject != null)
{
// Handle the selected project as needed
//MessageBox.Show($"Project ID: {selectedProject.ProjectId}, Selected Project: {selectedProject.ProjectName}", "Project Selected", MessageBoxButtons.OK, MessageBoxIcon.Information );
_ctrl.LoadTasks(selectedProject.ProjectId); // Load tasks for the selected project
InitProjectTasks();
}
}
}; };
} }
public void Project_DataGridViewProjects_DoubleClick(object sender, EventArgs e)
{
if (dataGridViewProjects.SelectedRows.Count > 0)
{
var selectedIdx = dataGridViewProjects.SelectedRows[0].Index;
var selectedProject = dataGridViewProjects.SelectedRows[0].DataBoundItem as Project;
if (selectedProject != null)
{
var dialog = new ProjectForm(selectedProject, _ctrl.GetClients(), _ctrl.GetLOV("project.status"));
if (dialog.ShowDialog(this) == DialogResult.OK)
{
Project project = dialog.Project;
ProjectData projectData = new ProjectData(_ConnectionString);
try
{
projectData.Upsert(project);
_ctrl.LoadProjects(); // Reload projects to update the DataGridView with any changes
dataGridViewProjects.ClearSelection();
if (selectedIdx >= 0 && selectedIdx < dataGridViewProjects.Rows.Count)
{
dataGridViewProjects.Rows[selectedIdx].Selected = true;
}
}
catch (Exception ex)
{
MessageBox.Show($"Error saving project: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
return;
}
}
}
public void Project_DataGridViewProjects_SelectionChanged(object sender, EventArgs e)
{
if (_ctrl == null) return; // Safety check to prevent null reference exceptions during initialization)
if (dataGridViewProjects.SelectedRows.Count > 0)
{
var selectedProject = dataGridViewProjects.SelectedRows[0].DataBoundItem as Project;
if (selectedProject != null)
{
// Handle the selected project as needed
//MessageBox.Show($"Project ID: {selectedProject.ProjectId}, Selected Project: {selectedProject.ProjectName}", "Project Selected", MessageBoxButtons.OK, MessageBoxIcon.Information );
_ctrl.LoadTasks(selectedProject.ProjectId); // Load tasks for the selected project
InitProjectTasks();
}
}
}
public void InitProjectTasks() public void InitProjectTasks()
{ {
//dataGridViewProjectTasks.Rows.Clear(); //dataGridViewProjectTasks.Rows.Clear();
@ -325,7 +346,7 @@ namespace trakker
richTextBoxTaskComments.ReadOnly = true; richTextBoxTaskComments.ReadOnly = true;
} }
public void InitTreeViewTasks() public void PTask_TreeViewTasks1_Init()
{ {
// Basic TreeView configuration // Basic TreeView configuration
treeViewTasks1.BeginUpdate(); treeViewTasks1.BeginUpdate();
@ -339,11 +360,11 @@ namespace trakker
// When a tree node is clicked, fetch and show notebooks for that folder // When a tree node is clicked, fetch and show notebooks for that folder
treeViewTasks1.NodeMouseClick += (sender, e) => treeViewTasks1.NodeMouseClick += (sender, e) =>
{ {
TreeViewTasks1_NodeMouseClick(e.Node, e.Button); PTask_TreeViewTasks1_NodeMouseClick(e.Node, e.Button);
}; };
} }
public void TreeViewTasks1_NodeMouseClick(TreeNode node, MouseButtons button = MouseButtons.Left) public void PTask_TreeViewTasks1_NodeMouseClick(TreeNode node, MouseButtons button = MouseButtons.Left)
{ {
if (node == null) return; if (node == null) return;
@ -360,7 +381,7 @@ namespace trakker
} }
_ctrl.LoadTasksRecursive(selectedNode?.GUID ?? "/", PTask.RecursiveRoot.TASK_ID); // Load all tasks for the project when root node is clicked _ctrl.LoadTasksRecursive(selectedNode?.GUID ?? "/", PTask.RecursiveRoot.TASK_ID); // Load all tasks for the project when root node is clicked
} }
public void FillTreeViewTasks(List<PTaskFS> items) public void PTask_TreeViewTasks1_Fill(List<PTaskFS> items)
{ {
if (items == null) return; if (items == null) return;
@ -371,7 +392,7 @@ namespace trakker
PTaskFS root = new(); PTaskFS root = new();
root.GUID = "/"; root.GUID = "/";
root.Node = "/Project"; root.Node = "/Project";
root.Parent = string.Empty; root.Parent = _empty;
TreeNode rootNode = new TreeNode(root.Node) { Tag = root }; TreeNode rootNode = new TreeNode(root.Node) { Tag = root };
treeViewTasks1.Nodes.Add(rootNode); treeViewTasks1.Nodes.Add(rootNode);
@ -417,12 +438,12 @@ namespace trakker
treeViewTasks1.EndUpdate(); // End the update treeViewTasks1.EndUpdate(); // End the update
TreeNode node = rootNode.FirstNode; TreeNode node = rootNode.FirstNode;
TreeViewTasks1_NodeMouseClick(node, MouseButtons.Left); PTask_TreeViewTasks1_NodeMouseClick(node, MouseButtons.Left);
//treeViewTasks1.SelectedNode = node; //treeViewTasks1.SelectedNode = node;
//treeViewTasks1.Focus(); //treeViewTasks1.Focus();
} }
private void addTaskSubtaskToolStripMenuItem_Click(object sender, EventArgs e) private void PTask_AddTaskSubtaskToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (treeViewTasks1.SelectedNode == null) return; if (treeViewTasks1.SelectedNode == null) return;
PTaskFS? selectedNode = (PTaskFS?)treeViewTasks1.SelectedNode.Tag ?? new PTaskFS(); PTaskFS? selectedNode = (PTaskFS?)treeViewTasks1.SelectedNode.Tag ?? new PTaskFS();
@ -436,7 +457,7 @@ namespace trakker
{ {
TaskId = taskId, TaskId = taskId,
Title = "New Task", Title = "New Task",
Description = string.Empty, Description = _empty,
ParentTaskId = selectedNode?.GUID == "/" ? null : selectedNode?.GUID, ParentTaskId = selectedNode?.GUID == "/" ? null : selectedNode?.GUID,
HourlyRate = selectedNode?.HourlyRate, HourlyRate = selectedNode?.HourlyRate,
ProjectId = selectedNode?.ProjectId, // Root node has no project ProjectId = selectedNode?.ProjectId, // Root node has no project
@ -446,7 +467,7 @@ namespace trakker
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
task = dialog.Task; task = dialog.Task;
TaskData taskData = new TaskData(connectionString); TaskData taskData = new TaskData(_ConnectionString);
try try
{ {
taskData.Upsert(task); taskData.Upsert(task);
@ -460,7 +481,7 @@ namespace trakker
} }
} }
private void editThisTaskSubtaskToolStripMenuItem_Click(object sender, EventArgs e) private void PTask_EditThisTaskSubtaskToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (treeViewTasks1.SelectedNode == null) return; if (treeViewTasks1.SelectedNode == null) return;
PTaskFS? selectedTask = treeViewTasks1.SelectedNode.Tag as PTaskFS; PTaskFS? selectedTask = treeViewTasks1.SelectedNode.Tag as PTaskFS;
@ -469,7 +490,7 @@ namespace trakker
MessageBox.Show("Cannot edit root node", "Edit Task", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("Cannot edit root node", "Edit Task", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; return;
} }
TaskData taskData = new TaskData(connectionString); TaskData taskData = new TaskData(_ConnectionString);
PTask task = taskData.Get(selectedTask?.GUID); PTask task = taskData.Get(selectedTask?.GUID);
TaskForm dialog = new TaskForm(task, _ctrl.GetLOV("task.status"), _ctrl.GetLOV("task.priority")); TaskForm dialog = new TaskForm(task, _ctrl.GetLOV("task.status"), _ctrl.GetLOV("task.priority"));
DialogResult result = dialog.ShowDialog(this); DialogResult result = dialog.ShowDialog(this);
@ -490,7 +511,7 @@ namespace trakker
} }
} }
private void deleteThisTaskSubtaskToolStripMenuItem_Click(object sender, EventArgs e) private void PTask_DeleteThisTaskSubtaskToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (treeViewTasks1.SelectedNode == null) return; if (treeViewTasks1.SelectedNode == null) return;
PTaskFS? selectedTask = treeViewTasks1.SelectedNode.Tag as PTaskFS; PTaskFS? selectedTask = treeViewTasks1.SelectedNode.Tag as PTaskFS;
@ -505,14 +526,14 @@ namespace trakker
MessageBox.Show("Cannot delete a task with subtasks", "Delete Task", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("Cannot delete a task with subtasks", "Delete Task", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return; return;
} }
TaskData taskData = new TaskData(connectionString); TaskData taskData = new TaskData(_ConnectionString);
DialogResult result = MessageBox.Show("Are you sure you want to delete this task?", "Delete Task", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); DialogResult result = MessageBox.Show("Are you sure you want to delete this task?", "Delete Task", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes) if (result == DialogResult.Yes)
{ {
//MessageBox.Show(task.ToString(), "Task Details", MessageBoxButtons.OK, MessageBoxIcon.Information); //MessageBox.Show(task.ToString(), "Task Details", MessageBoxButtons.OK, MessageBoxIcon.Information);
try try
{ {
taskData.Delete(selectedTask?.GUID ?? string.Empty); taskData.Delete(selectedTask?.GUID ?? _empty);
treeViewTasks1.SelectedNode.Remove(); treeViewTasks1.SelectedNode.Remove();
//_ctrl.LoadTasks(); // Reload tasks to update the DataGridView with any changes //_ctrl.LoadTasks(); // Reload tasks to update the DataGridView with any changes
} }
@ -523,7 +544,7 @@ namespace trakker
} }
} }
private void addACommentToolStripMenuItem_Click(object sender, EventArgs e) private void PTask_AddACommentToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (treeViewTasks1.SelectedNode == null) return; if (treeViewTasks1.SelectedNode == null) return;
PTaskFS? selectedTask = treeViewTasks1.SelectedNode.Tag as PTaskFS; PTaskFS? selectedTask = treeViewTasks1.SelectedNode.Tag as PTaskFS;
@ -538,17 +559,17 @@ namespace trakker
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
if (string.IsNullOrEmpty(textAreaForm.BasicText)) return; if (string.IsNullOrEmpty(textAreaForm.BasicText)) return;
TaskData taskData = new TaskData(connectionString); TaskData taskData = new TaskData(_ConnectionString);
try try
{ {
PTaskComment comment = new() PTaskComment comment = new()
{ {
TaskId = selectedTask?.GUID ?? string.Empty, TaskId = selectedTask?.GUID ?? _empty,
Comment = textAreaForm.BasicText ?? string.Empty, Comment = textAreaForm.BasicText ?? _empty,
}; };
taskData.SaveComment(comment); taskData.SaveComment(comment);
DialogExtensions.GenericSuccess($"Comment saved successfully for task '{selectedTask!.Node}'."); DialogExtensions.GenericSuccess($"Comment saved successfully for task '{selectedTask!.Node}'.");
dataGridViewProjectTasks_SelectionChanged(null, null); PTask_DataGridViewProjectTasks_SelectionChanged(null, null);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -556,7 +577,7 @@ namespace trakker
} }
} }
} }
public void InitDataGridViewProjectTasks() public void PTask_DataGridViewProjectTasks_Init()
{ {
dataGridViewProjectTasks.AllowUserToAddRows = false; dataGridViewProjectTasks.AllowUserToAddRows = false;
dataGridViewProjectTasks.AllowUserToDeleteRows = false; dataGridViewProjectTasks.AllowUserToDeleteRows = false;
@ -681,52 +702,15 @@ namespace trakker
dataGridViewProjectTasks.SelectionChanged += (s, e) => dataGridViewProjectTasks.SelectionChanged += (s, e) =>
{ {
dataGridViewProjectTasks_SelectionChanged(s, e); PTask_DataGridViewProjectTasks_SelectionChanged(s, e);
}; };
dataGridViewProjectTasks.DoubleClick += (s, e) => dataGridViewProjectTasks.DoubleClick += (s, e) =>
{ // BCN {
var projectIdx = dataGridViewProjects.SelectedRows[0].Index; PTask_DataGridViewProjectTasks_DoubleClick(s, e);
var taskIdx = dataGridViewProjectTasks.SelectedRows[0].Index;
var row = dataGridViewProjectTasks.SelectedRows[0];
if (row != null)
{
var task = dataGridViewProjectTasks.SelectedRows[0].DataBoundItem as PTask;
TaskForm dialog = new TaskForm(task!, _ctrl.GetLOV("task.status"), _ctrl.GetLOV("task.priority"));
DialogResult result = dialog.ShowDialog(this);
if (result == DialogResult.OK)
{
task = dialog.Task;
try
{
TaskData taskData = new TaskData(connectionString);
taskData.Upsert(task);
//_ctrl.LoadTasks(task.ProjectId ?? string.Empty); // Reload tasks to update the DataGridView with any changes
_ctrl.LoadProjects(); // Reload projects to update the DataGridView with any changes
_ctrl.LoadTasksRecursive(task.TaskId ?? string.Empty, PTask.RecursiveRoot.TASK_ID); // Reload tasks to update the tree view with any changes
dataGridViewProjects.ClearSelection();
if (projectIdx >= 0 && projectIdx < dataGridViewProjects.Rows.Count)
{
dataGridViewProjects.Rows[projectIdx].Selected = true;
}
dataGridViewProjectTasks.ClearSelection();
if (taskIdx >= 0 && taskIdx < dataGridViewProjectTasks.Rows.Count)
{
dataGridViewProjectTasks.Rows[taskIdx].Selected = true;
}
}
catch (Exception ex)
{
MessageBox.Show($"Error saving task: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}; };
} }
public void dataGridViewProjectTasks_SelectionChanged(object? sender, EventArgs? e) public void PTask_DataGridViewProjectTasks_SelectionChanged(object? sender, EventArgs? e)
{ {
if (dataGridViewProjectTasks.SelectedRows.Count > 0) if (dataGridViewProjectTasks.SelectedRows.Count > 0)
{ {
@ -734,8 +718,8 @@ namespace trakker
var selectedTask = dataGridViewProjectTasks.SelectedRows[0].DataBoundItem as PTask; var selectedTask = dataGridViewProjectTasks.SelectedRows[0].DataBoundItem as PTask;
if (selectedTask != null) if (selectedTask != null)
{ {
TaskData taskData = new TaskData(connectionString); TaskData taskData = new TaskData(_ConnectionString);
List<PTaskComment> comments = taskData.GetComments(selectedTask.TaskId ?? string.Empty); List<PTaskComment> comments = taskData.GetComments(selectedTask.TaskId ?? _empty);
richTextBoxTaskComments.Clear(); richTextBoxTaskComments.Clear();
foreach (var comment in comments) foreach (var comment in comments)
{ {
@ -744,14 +728,57 @@ namespace trakker
} }
} }
} }
public void FillDataGridViewProjectTasks(BindingSource tasks)
public void PTask_DataGridViewProjectTasks_DoubleClick(object? sender, EventArgs? e)
{
var projectIdx = dataGridViewProjects.SelectedRows[0].Index;
var taskIdx = dataGridViewProjectTasks.SelectedRows[0].Index;
var row = dataGridViewProjectTasks.SelectedRows[0];
if (row != null)
{
var task = dataGridViewProjectTasks.SelectedRows[0].DataBoundItem as PTask;
TaskForm dialog = new TaskForm(task!, _ctrl.GetLOV("task.status"), _ctrl.GetLOV("task.priority"));
DialogResult result = dialog.ShowDialog(this);
if (result == DialogResult.OK)
{
task = dialog.Task;
try
{
TaskData taskData = new TaskData(_ConnectionString);
taskData.Upsert(task);
//_ctrl.LoadTasks(task.ProjectId ?? string.Empty); // Reload tasks to update the DataGridView with any changes
_ctrl.LoadProjects(); // Reload projects to update the DataGridView with any changes
_ctrl.LoadTasksRecursive(task.TaskId ?? _empty, PTask.RecursiveRoot.TASK_ID); // Reload tasks to update the tree view with any changes
dataGridViewProjects.ClearSelection();
if (projectIdx >= 0 && projectIdx < dataGridViewProjects.Rows.Count)
{
dataGridViewProjects.Rows[projectIdx].Selected = true;
}
dataGridViewProjectTasks.ClearSelection();
if (taskIdx >= 0 && taskIdx < dataGridViewProjectTasks.Rows.Count)
{
dataGridViewProjectTasks.Rows[taskIdx].Selected = true;
}
}
catch (Exception ex)
{
MessageBox.Show($"Error saving task: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
public void PTask_DataGridViewProjectTasks_Fill(BindingSource tasks)
{ {
//dataGridViewProjectTasks.Rows.Clear(); //dataGridViewProjectTasks.Rows.Clear();
dataGridViewProjectTasks.DataSource = tasks; dataGridViewProjectTasks.DataSource = tasks;
//dataGridViewProjectTasks.Refresh(); //dataGridViewProjectTasks.Refresh();
} }
private void richTextBoxTaskComments_LinkClicked(object sender, LinkClickedEventArgs e) private void PTask_RichTextBoxTaskComments_LinkClicked(object sender, LinkClickedEventArgs e)
{ {
try try
{ {

View File

@ -1,4 +1,4 @@
namespace newcle.us.Forms namespace trakker.Forms
{ {
partial class TextAreaForm partial class TextAreaForm
{ {

View File

@ -1,7 +1,6 @@
using newcle.us.Utilities; using System.ComponentModel;
using System.ComponentModel;
namespace newcle.us.Forms namespace trakker.Forms
{ {
public partial class TextAreaForm : Form public partial class TextAreaForm : Form
{ {

View File

@ -10,13 +10,13 @@ namespace trakker.Interfaces
{ {
internal interface IMainForm internal interface IMainForm
{ {
void InitDataGridViewClients(BindingList<Client> clients); void Client_DataGridViewClients_Init(BindingList<Client> clients);
void InitDataGridViewProjects(); void Project_DataGridViewProjects_Init();
void FillDataGridViewProjects(BindingSource projects); void Project_DataGridViewProjects_Fill(BindingSource projects);
void FillTreeViewTasks(List<PTaskFS> items); void PTask_TreeViewTasks1_Fill(List<PTaskFS> items);
void InitTreeViewTasks(); void PTask_TreeViewTasks1_Init();
void InitDataGridViewProjectTasks(); void PTask_DataGridViewProjectTasks_Init();
void InitProjectTasks(); void InitProjectTasks();
void FillDataGridViewProjectTasks(BindingSource tasks); void PTask_DataGridViewProjectTasks_Fill(BindingSource tasks);
} }
} }

View File

@ -22,9 +22,9 @@ namespace trakker.Services
LoadClients(); LoadClients();
_view.InitDataGridViewProjectTasks(); _view.PTask_DataGridViewProjectTasks_Init();
_view.InitDataGridViewProjects(); _view.Project_DataGridViewProjects_Init();
_view.InitTreeViewTasks(); _view.PTask_TreeViewTasks1_Init();
LoadProjects(); LoadProjects();
} }
@ -42,7 +42,7 @@ namespace trakker.Services
internal void LoadClients() internal void LoadClients()
{ {
var clients = GetClients(); var clients = GetClients();
_view.InitDataGridViewClients(clients); _view.Client_DataGridViewClients_Init(clients);
} }
public BindingList<Project> GetProjects() public BindingList<Project> GetProjects()
@ -58,13 +58,13 @@ namespace trakker.Services
{ {
var x = project.Status; var x = project.Status;
} }
_view.FillDataGridViewProjects(new BindingSource { DataSource = projects }); _view.Project_DataGridViewProjects_Fill(new BindingSource { DataSource = projects });
//LoadTasks(); //LoadTasks();
} }
internal void LoadTasks(string projectId) internal void LoadTasks(string projectId)
{ {
var dbo = new TaskData(_connectionString); var dbo = new TaskData(_connectionString);
_view.FillTreeViewTasks(dbo.GetFS(projectId)); _view.PTask_TreeViewTasks1_Fill(dbo.GetFS(projectId));
_view.InitProjectTasks(); _view.InitProjectTasks();
//_view.InitDataGridViewProjectTasks(); //_view.InitDataGridViewProjectTasks();
} }
@ -72,7 +72,7 @@ namespace trakker.Services
{ {
var dbo = new TaskData(_connectionString); var dbo = new TaskData(_connectionString);
BindingList<PTask> tasks = dbo.GetRecursive(id, root); BindingList<PTask> tasks = dbo.GetRecursive(id, root);
_view.FillDataGridViewProjectTasks(new BindingSource { DataSource = tasks }); _view.PTask_DataGridViewProjectTasks_Fill(new BindingSource { DataSource = tasks });
} }

View File

@ -1,6 +1,6 @@
using System.Globalization; using System.Globalization;
namespace newcle.us.Utilities namespace trakker.Utilities
{ {
public static class CurrencyExtensions public static class CurrencyExtensions
{ {

View File

@ -1,4 +1,4 @@
namespace newcle.us.Utilities namespace trakker.Utilities
{ {
internal class DateTimeExtensions internal class DateTimeExtensions
{ {

View File

@ -1,4 +1,4 @@
namespace newcle.us.Utilities namespace trakker.Utilities
{ {
internal class DialogExtensions internal class DialogExtensions
{ {

View File

@ -1,6 +1,6 @@
using System.Diagnostics; using System.Diagnostics;
namespace newcle.us.Utilities namespace trakker.Utilities
{ {
public class FileExtensions public class FileExtensions
{ {

View File

@ -1,4 +1,4 @@
namespace newcle.us.Utilities namespace trakker.Utilities
{ {
public class StringExtensions public class StringExtensions
{ {