-
Notifications
You must be signed in to change notification settings - Fork 1
/
YearSchedule.cs
179 lines (157 loc) · 6.89 KB
/
YearSchedule.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.Threading;
using DotNetNuke.Services.GeneratedImage;
namespace Bitboxx.Services.GeneratedImage
{
public class YearSchedule : ImageTransform
{
public string Matrix { get; set; }
public string Culture { get; set; }
public Color BackColor { get; set; }
public override string UniqueString
{
get { return base.UniqueString + this.Matrix + this.Culture +this.BackColor.ToString(); }
}
public YearSchedule()
{
InterpolationMode = InterpolationMode.HighQualityBicubic;
SmoothingMode = SmoothingMode.Default;
PixelOffsetMode = PixelOffsetMode.Default;
CompositingQuality = CompositingQuality.HighSpeed;
}
public override Image ProcessImage(Image image)
{
Bitmap bmp = new Bitmap(486, 224, PixelFormat.Format32bppPArgb);
SolidBrush emptyBrush = new SolidBrush(Color.FromArgb(204, 204, 204));
SolidBrush captionBrush = new SolidBrush(Color.FromArgb(204, 204, 204));
SolidBrush freeBrush = new SolidBrush(Color.FromArgb(1, 151, 0));
SolidBrush reservedBrush = new SolidBrush(Color.FromArgb(255, 204, 0));
SolidBrush occupiedBrush = new SolidBrush(Color.FromArgb(155, 0, 3));
SolidBrush selectedBrush = new SolidBrush(Color.FromArgb(1, 79, 255));
SolidBrush transBrush = new SolidBrush(Color.FromArgb(100, 255, 255, 255));
using (var gr = Graphics.FromImage(bmp))
{
gr.Clear(BackColor);
// Paint Month Name boxes
int x = 1;
int y = 2;
for (int i = 0; i < 12; i++)
{
y += 17;
gr.FillRectangle(captionBrush, x, y, 50, 16);
using (Font drawFont = new Font("Arial", 6.5f))
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(Culture);
string month = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames[i];
StringFormat stringFormat = new StringFormat()
{
Alignment = StringAlignment.Far,
LineAlignment = StringAlignment.Center
};
gr.DrawString(month, drawFont, new SolidBrush(Color.Black), new RectangleF(x, y, 48, 16),
stringFormat);
}
}
// Paint Day Number boxes
x = 38;
y = 1;
for (int i = 0; i < 31; i++)
{
x += 14;
gr.FillRectangle(captionBrush, x, y, 13, 16);
using (Font drawFont = new Font("Arial", 6.5f))
{
string day = (i + 1).ToString().PadLeft(2, '0');
StringFormat stringFormat = new StringFormat()
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
gr.DrawString(day, drawFont, new SolidBrush(Color.Black), new RectangleF(x, y, 13, 16),
stringFormat);
}
}
int[,] matrix = new int[12, 31];
char[] chars = Matrix.ToCharArray();
for (int month = 1; month < 13; month++)
{
for (int day = 1; day < 32; day++)
{
char value = chars[(month - 1) * 31 + day - 1];
matrix[month - 1, day - 1] = int.Parse(value.ToString());
}
}
int yesterday = 1;
x = 38;
y = 2;
for (int month = 0; month < 12; month++)
{
y += 17;
for (int day = 0; day < 31; day++)
{
x += 14;
Point[] firstHalf = { new Point(x, y), new Point(x + 13, y), new Point(x, y + 16) };
Point[] lastHalf = { new Point(x + 13, y), new Point(x + 13, y + 16), new Point(x, y + 16) };
int today = matrix[month, day];
if (today == 0)
{
gr.FillRectangle(emptyBrush, x, y, 13, 16);
}
else
{
switch (today)
{
case 1:
case 6:
gr.FillPolygon(freeBrush, lastHalf);
break;
case 2:
case 7:
gr.FillPolygon(reservedBrush, lastHalf);
break;
case 3:
case 8:
gr.FillPolygon(occupiedBrush, lastHalf);
break;
case 4:
case 9:
gr.FillPolygon(selectedBrush, lastHalf);
break;
}
switch (yesterday)
{
case 1:
case 6:
gr.FillPolygon(freeBrush, firstHalf);
break;
case 2:
case 7:
gr.FillPolygon(reservedBrush, firstHalf);
break;
case 3:
case 8:
gr.FillPolygon(occupiedBrush, firstHalf);
break;
case 4:
case 9:
gr.FillPolygon(selectedBrush, firstHalf);
break;
}
if (today > 4)
{
gr.FillRectangle(transBrush, x, y, 13, 16);
}
yesterday = matrix[month, day];
}
}
x = 38;
}
return (Image)bmp;
}
}
}
}