-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbsenceManagerForm.cs
More file actions
53 lines (45 loc) · 1.81 KB
/
AbsenceManagerForm.cs
File metadata and controls
53 lines (45 loc) · 1.81 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WorkTimer
{
public partial class AbsenceManagerForm : Form
{
private List<AbsencePeriod> _allAbsences;
public List<AbsencePeriod> AbsencesToRemove { get; private set; }
public AbsenceManagerForm(List<AbsencePeriod> absences)
{
InitializeComponent();
_allAbsences = absences;
AbsencesToRemove = new List<AbsencePeriod>();
}
private void AbsenceManagerForm_Load(object sender, EventArgs e)
{
foreach (var absence in _allAbsences)
{
var duration = absence.End - absence.Start;
// Corrected the format string to include hours
lstAbsences.Items.Add($"From: {absence.Start:HH:mm:ss} | Duration: {duration:hh\\:mm\\:ss}");
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
if (lstAbsences.SelectedIndices.Count == 0)
{
MessageBox.Show("Please select one or more absences to remove.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var result = MessageBox.Show("Are you sure you want to remove the selected absence(s)? This will subtract the time from your countdown.", "Confirm Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
foreach (int index in lstAbsences.SelectedIndices.Cast<int>().OrderByDescending(i => i))
{
AbsencesToRemove.Add(_allAbsences[index]);
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}
}