-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowTasks.cs
More file actions
121 lines (107 loc) · 4.22 KB
/
WindowTasks.cs
File metadata and controls
121 lines (107 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
namespace Developer_Allocation_Management
{
public partial class WindowTasks : Form
{
private static WindowTasks _instance;
private Boolean _preAllocation = false;
private WindowTasks()
{
InitializeComponent();
}
private WindowTasks(Allocation createdAllocation) : this()
{
_preAllocation = true;
txtProject.Text = $"{createdAllocation.Project.Name}";
txtDeveloper.Text = $"{createdAllocation.Developer.Id}";
}
public static WindowTasks GetInstance()
{
if (_instance == null || _instance.IsDisposed)
{
_instance = new WindowTasks();
}
return _instance;
}
public static WindowTasks GetInstance(Allocation createdAllocation)
{
if (_instance == null || _instance.IsDisposed)
{
_instance = new WindowTasks(createdAllocation);
}
return _instance;
}
private void txtProject_TextChanged(object sender, EventArgs e)
{
lstProjects.DataSource = ProjectRepository.FindByPartialName(txtDeveloper.Text);
}
private void lstProjects_SelectedIndexChanged(object sender, EventArgs e)
{
lstDevelopers.DataSource = AllocationRepository.FindByProject((Project)lstProjects.SelectedItem);
Allocation allocation = (Allocation)lstDevelopers.SelectedItem;
lstTasks.DataSource = AllocationRepository.GetTasks(allocation.Id);
}
private void txtDeveloper_TextChanged(object sender, EventArgs e)
{
if (!_preAllocation)
{
lstDevelopers.DataSource = AllocationRepository.FindByDeveloper(txtDeveloper.Text, (Project)lstProjects.SelectedItem);
}
else
{
List<Developer> list = new List<Developer>();
list.Add(DeveloperRepository.FindByIdEProject(Convert.ToInt64(txtDeveloper.Text), (Project)lstProjects.SelectedItem));
lstDevelopers.DataSource = list;
_preAllocation = false;
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtProject.Text))
{
Allocation allocation = (Allocation)lstDevelopers.SelectedItem;
Task task = new Task(txtTask.Text);
AllocationRepository.AddTask(allocation, task);
lstTasks.DataSource = AllocationRepository.GetTasks(allocation.Id);
txtTask.Text = string.Empty;
}
else
{
MessageBox.Show("Enter a description for your task.");
}
}
private void lstDevelopers_SelectedIndexChanged(object sender, EventArgs e)
{
Allocation allocation = (Allocation)lstDevelopers.SelectedItem;
lstTasks.DataSource = AllocationRepository.GetTasks(allocation.Id);
}
private void lstTasks_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
int index = lstTasks.IndexFromPoint(e.Location);
if (index != -1)
{
lstTasks.SelectedIndex = index;
Point locationOnForm = lstTasks.PointToScreen(e.Location);
contextMenuStrip1.Show(locationOnForm);
}
}
}
private void excluirToolStripMenuItem_Click(object sender, EventArgs e)
{
AllocationRepository.RemoveTask((Task)lstTasks.SelectedItem);
Allocation allocation = (Allocation)lstDevelopers.SelectedItem;
lstTasks.DataSource = AllocationRepository.GetTasks(allocation.Id);
}
}
}