-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServiceElement.cs
123 lines (115 loc) · 4.36 KB
/
ServiceElement.cs
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
122
123
using System.Windows.Forms;
namespace PPTXcreator
{
public enum ElementType
{
None,
Reading,
PsalmOB,
PsalmWK,
SongWK,
SongOTH,
SongOther,
Gezang
}
/// <summary>
/// Basic object which contains information about a
/// part of the service (a song or reading)
/// </summary>
public class ServiceElement
{
public ElementType Type { get; }
/// <summary>
/// Appears in the presentation before the service and on the
/// first line in the presentation during the service
/// </summary>
public string Title { get; }
/// <summary>
/// Appears in the second line in the presentation during the service
/// </summary>
public string Subtitle { get; }
public bool IsSong { get => Type > ElementType.Reading; }
public bool IsReading { get => Type == ElementType.Reading; }
public bool ShowQR { get; set; } = false;
/// <summary>
/// Construct a ServiceElement instance from a DataGridViewRow
/// </summary>
/// <param name="row">A row from <see cref="Window.dataGridView"/></param>
public ServiceElement(DataGridViewRow row)
{
string type = (string)row.Cells[0].Value;
string selection = (string)row.Cells[1].Value;
string songname = (string)row.Cells[2].Value;
switch (type)
{
case "Lezing":
Type = ElementType.Reading;
Title = FormatTitle(selection);
break;
case "Psalm":
Type = ElementType.PsalmOB;
Title = "Psalm " + FormatTitle(selection);
Subtitle = "Oude berijming";
break;
case "Psalm (WK)":
Type = ElementType.PsalmWK;
Title = "Psalm " + FormatTitle(selection);
Subtitle = "Weerklank";
break;
case "Lied (WK)":
Type = ElementType.SongWK;
Title = "Lied " + FormatTitle(selection);
if (string.IsNullOrWhiteSpace(songname)) Subtitle = "";
else Subtitle = songname.Trim();
break;
case "Lied (OTH)":
Type = ElementType.SongOTH;
Title = "OTH " + FormatTitle(selection);
if (string.IsNullOrWhiteSpace(songname)) Subtitle = "";
else Subtitle = songname.Trim();
break;
case "Lied (Overig)":
Type = ElementType.SongOther;
if (string.IsNullOrWhiteSpace(songname)) Title = "";
else Title = songname.Trim();
break;
case "Gezang":
Type = ElementType.Gezang;
Title = "Gezang " + FormatTitle(selection);
if (string.IsNullOrWhiteSpace(songname)) Subtitle = "";
else Subtitle = songname.Trim();
break;
default:
Type = ElementType.None;
Title = "";
Subtitle = "";
break;
}
}
public ServiceElement()
{
Type = ElementType.None;
Title = "";
Subtitle = "";
}
private string ReplaceLastComma(string input)
{
int lastComma = input.LastIndexOf(",");
if (lastComma == -1) return input;
return input.Remove(lastComma, 1).Insert(lastComma, " en ");
}
private string FormatTitle(string title)
{
if (!string.IsNullOrWhiteSpace(title))
{
title = ReplaceLastComma(title); // Replace last comma with 'en'
title = title.Replace(",", ", ") // Add space after comma
.Replace(":", " : ") // Add space before and after colon
.Replace("-", " - ") // Add space before and after dash
.Replace(" ", " ") // Remove double spaces
.Trim(); // Remove leading/trailing whitespace
}
return title;
}
}
}