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
|
using System;
using System.Xml;
using System.Text.RegularExpressions;
namespace DHTMLX.Export.PDF.Scheduler
{
public class SchedulerEvent
{
private string _backgroundColor;
private string _text = "";
private string _color;
public SchedulerEvent(){
Footenote = -1;
}
public string Text
{
get { return _text ?? (_text = ""); }
protected set { _text = value; }
}
public int Day { get; protected set; }
public int Week { get; protected set; }
public int Month { get; protected set; }
public int Len { get; protected set; }
public double X { get; protected set; }
public double Y { get; set; }
public string Type { get; protected set; }
public double Width { get; protected set; }
public double Height { get; protected set; }
public string HeaderText { get; protected set; }
public string HeaderAgendaText { get; protected set; }
public string BackgroundColor
{
get
{
_backgroundColor = ProcessColor(_backgroundColor);
return _backgroundColor;
}
protected set { _backgroundColor = value; }
}
public string Color
{
get
{
_color = ProcessColor(_color);
return _color;
}
protected set { _color = value; }
}
public int Footenote { get; set; }
private string GetNodeValue(XmlNode node)
{
var txt = node.FirstChild != null ? node.FirstChild.Value : "";
if (string.IsNullOrEmpty(txt))
txt = node.InnerText;
if (string.IsNullOrEmpty(txt))
txt = "";
return txt;
}
private int GetNumAttributeValue(XmlNode node, string attr)
{
string val = node.Attributes[attr] != null ? node.Attributes[attr].Value : "0";
int result = 0;
if (!string.IsNullOrEmpty(val) && val != "undefined")
int.TryParse(val, out result);
return result;
}
private string GetAttributeValue(XmlNode node, string attr)
{
return node.Attributes[attr] != null ? node.Attributes[attr].Value : "0";
}
private double GetDoublAttributeValue(XmlNode node, string attr)
{
string val = node.Attributes[attr] != null ? node.Attributes[attr].Value : "0";
double result = 0;
if (!string.IsNullOrEmpty(val) && val != "undefined")
double.TryParse(val, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out result);
return result;
}
public void Parse(XmlNode parent)
{
var children = parent.ChildNodes;
var bgProcessed = false;
for (var i = 0; i < children.Count; i++)
{
switch (children[i].LocalName)
{
case "body":
Text = GetNodeValue(children[i]);
BackgroundColor = GetAttributeValue(children[i], "backgroundColor");
Color = GetAttributeValue(children[i], "color");
bgProcessed = true;
break;
case "header":
HeaderText = GetNodeValue(children[i]);
break;
case "head":
HeaderAgendaText = GetNodeValue(children[i]);
break;
}
}
if (!bgProcessed)
{
BackgroundColor = GetAttributeValue(parent, "backgroundColor");
Color = GetAttributeValue(parent, "color");
}
Day = GetNumAttributeValue(parent, "day");
Week = GetNumAttributeValue(parent, "week");
Len = GetNumAttributeValue(parent, "len");
Month = GetNumAttributeValue(parent, "month");
X = GetDoublAttributeValue(parent, "x");
Y = GetDoublAttributeValue(parent, "y");
Width = GetDoublAttributeValue(parent, "width");
Height = GetDoublAttributeValue(parent, "height");
Type = GetAttributeValue(parent, "type");
}
private string ProcessColor(string color)
{
if (Regex.IsMatch(color, "#[0-9A-Fa-f]{6}"))
{
return color.Substring(1);
}
if (Regex.IsMatch(color, "[0-9A-Fa-f]{6}"))
{
return color;
}
var m3 = Regex.Match(color, "rgb\\s?\\(\\s?(\\d{1,3})\\s?,\\s?(\\d{1,3})\\s?,\\s?(\\d{1,3})\\s?\\)");
if (m3.Length > 0)
{
var r = m3.Groups[1].Value;
var g = m3.Groups[2].Value;
var b = m3.Groups[3].Value;
r = int.Parse(r).ToString("x");
r = (r.Length == 1) ? "0" + r : r;
g = int.Parse(g).ToString("x");
g = (g.Length == 1) ? "0" + g : g;
b = int.Parse(b).ToString("x");
b = (b.Length == 1) ? "0" + b : b;
color = r + g + b;
return color;
}
return "transparent";
}
}
}
|