markus / MarkupToPDF / Controls / Etc / DateControl.cs @ 036650a0
이력 | 보기 | 이력해설 | 다운로드 (18.8 KB)
1 |
using System; |
---|---|
2 |
using System.Net; |
3 |
using System.Windows; |
4 |
using System.Windows.Controls; |
5 |
using System.Windows.Documents; |
6 |
using System.Windows.Ink; |
7 |
using System.Windows.Input; |
8 |
using System.Windows.Media; |
9 |
using System.Windows.Media.Animation; |
10 |
using System.Windows.Shapes; |
11 |
using System.ComponentModel; |
12 |
using System.Collections.Generic; |
13 |
using MarkupToPDF.Controls.Common; |
14 |
using MarkupToPDF.Common; |
15 |
using MarkupToPDF.Serialize.Core; |
16 |
using MarkupToPDF.Serialize.S_Control; |
17 |
|
18 |
namespace MarkupToPDF.Controls.Etc |
19 |
{ |
20 |
public class DateControl : CommentUserInfo, IDisposable, IPath, INotifyPropertyChanged, IViewBox, IMarkupCommonData |
21 |
{ |
22 |
private const string PART_ViewBox = "PART_ViewBox"; |
23 |
private const string PART_TextBox = "PART_TextBox"; |
24 |
public Viewbox Base_ViewBox = null; |
25 |
public TextBlock Base_TextBox = null; |
26 |
|
27 |
static DateControl() |
28 |
{ |
29 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(DateControl), new FrameworkPropertyMetadata(typeof(DateControl))); |
30 |
//Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
31 |
ResourceDictionary dictionary = new ResourceDictionary(); |
32 |
dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
33 |
Application.Current.Resources.MergedDictionaries.Add(dictionary); |
34 |
System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count); |
35 |
} |
36 |
|
37 |
public DateControl() |
38 |
{ |
39 |
this.DefaultStyleKey = typeof(DateControl); |
40 |
} |
41 |
|
42 |
|
43 |
#region Dependency Properties |
44 |
|
45 |
|
46 |
public static readonly DependencyProperty IsSelectedProperty = |
47 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(DateControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
48 |
|
49 |
public static readonly DependencyProperty ControlTypeProperty = |
50 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(DateControl), new FrameworkPropertyMetadata(ControlType.Date)); |
51 |
|
52 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
53 |
"OverViewPathData", typeof(Geometry), typeof(DateControl), null); |
54 |
|
55 |
public static readonly DependencyProperty OverViewStartPointProperty = DependencyProperty.Register( |
56 |
"OverViewStartPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(null)); |
57 |
|
58 |
public static readonly DependencyProperty OverViewEndPointProperty = DependencyProperty.Register( |
59 |
"OverViewEndPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(null)); |
60 |
|
61 |
|
62 |
public static readonly DependencyProperty TextProperty = DependencyProperty.Register( |
63 |
"Text", typeof(string), typeof(DateControl), new PropertyMetadata(null)); |
64 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
65 |
"UserID", typeof(string), typeof(DateControl), new PropertyMetadata(null)); |
66 |
public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register( |
67 |
"FontColor", typeof(SolidColorBrush), typeof(DateControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
68 |
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] |
69 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
70 |
"StartPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
71 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
72 |
"EndPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
73 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
74 |
"LineSize", typeof(double), typeof(DateControl), new PropertyMetadata((double)3)); |
75 |
public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
76 |
"TopRightPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), TRPointValueChanged)); |
77 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
78 |
"PointSet", typeof(List<Point>), typeof(DateControl), new PropertyMetadata(new List<Point>())); |
79 |
public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
80 |
"LeftBottomPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), LBPointValueChanged)); |
81 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
82 |
"PathData", typeof(Geometry), typeof(DateControl), null); |
83 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(DateControl), |
84 |
new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
85 |
|
86 |
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(DateControl), |
87 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
88 |
|
89 |
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(DateControl), |
90 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
91 |
|
92 |
#endregion |
93 |
#region PropertyChanged Method |
94 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
95 |
{ |
96 |
//var instance = (DateControl)sender; |
97 |
|
98 |
//if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
99 |
//{ |
100 |
|
101 |
// instance.SetValue(e.Property, e.NewValue); |
102 |
|
103 |
// if (instance.IsSelected) |
104 |
// { |
105 |
// //instance.Base_ViewBox.Style. = new SolidColorBrush(Colors.Blue); |
106 |
// } |
107 |
// else |
108 |
// { |
109 |
// //instance.Base_ViewBox.Stroke = new SolidColorBrush(Colors.Red); |
110 |
// } |
111 |
//} |
112 |
} |
113 |
|
114 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
115 |
{ |
116 |
var instance = (DateControl)sender; |
117 |
if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
118 |
{ |
119 |
instance.SetValue(e.Property, e.NewValue); |
120 |
instance.SetDate(); |
121 |
} |
122 |
} |
123 |
public static void LBPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
124 |
{ |
125 |
var instance = (DateControl)sender; |
126 |
if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
127 |
{ |
128 |
instance.SetValue(e.Property, e.NewValue); |
129 |
//instance.EndPoint = new Point(instance.EndPoint.X, ((Point)e.NewValue).Y); |
130 |
//instance.StartPoint = new Point(((Point)e.NewValue).X, instance.StartPoint.Y); |
131 |
////instance.PointSet[0] = instance.StartPoint; |
132 |
////instance.PointSet[2] = instance.EndPoint; |
133 |
instance.SetDate(); |
134 |
} |
135 |
} |
136 |
public static void TRPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
137 |
{ |
138 |
var instance = (DateControl)sender; |
139 |
if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
140 |
{ |
141 |
instance.SetValue(e.Property, e.NewValue); |
142 |
instance.SetDate(); |
143 |
} |
144 |
} |
145 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
146 |
{ |
147 |
var instance = (DateControl)sender; |
148 |
if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
149 |
{ |
150 |
instance.SetValue(e.Property, e.NewValue); |
151 |
instance.SetDate(); |
152 |
} |
153 |
} |
154 |
|
155 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
156 |
{ |
157 |
var instance = (DateControl)sender; |
158 |
if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
159 |
{ |
160 |
instance.SetValue(e.Property, e.NewValue); |
161 |
instance.SetDate(); |
162 |
} |
163 |
} |
164 |
#endregion |
165 |
#region Properties |
166 |
public double LineSize |
167 |
{ |
168 |
get { return (double)GetValue(LineSizeProperty); } |
169 |
set |
170 |
{ |
171 |
if (this.LineSize != value) |
172 |
{ |
173 |
SetValue(LineSizeProperty, value); |
174 |
OnPropertyChanged("LineSize"); |
175 |
} |
176 |
} |
177 |
} |
178 |
public string UserID |
179 |
{ |
180 |
get { return (string)GetValue(UserIDProperty); } |
181 |
set |
182 |
{ |
183 |
if (this.UserID != value) |
184 |
{ |
185 |
SetValue(UserIDProperty, value); |
186 |
OnPropertyChanged("UserID"); |
187 |
} |
188 |
} |
189 |
} |
190 |
public double Angle |
191 |
{ |
192 |
get { return (double)GetValue(AngleProperty); } |
193 |
set |
194 |
{ |
195 |
if (this.Angle != value) |
196 |
{ |
197 |
SetValue(AngleProperty, value); |
198 |
} |
199 |
} |
200 |
} |
201 |
|
202 |
|
203 |
|
204 |
public bool IsSelected |
205 |
{ |
206 |
get |
207 |
{ |
208 |
return (bool)GetValue(IsSelectedProperty); |
209 |
} |
210 |
set |
211 |
{ |
212 |
SetValue(IsSelectedProperty, value); |
213 |
OnPropertyChanged("IsSelected"); |
214 |
} |
215 |
} |
216 |
|
217 |
override public ControlType ControlType |
218 |
{ |
219 |
set |
220 |
{ |
221 |
SetValue(ControlTypeProperty, value); |
222 |
OnPropertyChanged("ControlType"); |
223 |
} |
224 |
get |
225 |
{ |
226 |
return (ControlType)GetValue(ControlTypeProperty); |
227 |
} |
228 |
} |
229 |
|
230 |
public Geometry OverViewPathData |
231 |
{ |
232 |
get { return (Geometry)GetValue(OverViewPathDataProperty); } |
233 |
set |
234 |
{ |
235 |
SetValue(OverViewPathDataProperty, value); |
236 |
OnPropertyChanged("OverViewPathData"); |
237 |
} |
238 |
} |
239 |
|
240 |
public List<Point> PointSet |
241 |
{ |
242 |
get { return (List<Point>)GetValue(PointSetProperty); } |
243 |
set { SetValue(PointSetProperty, value); } |
244 |
} |
245 |
public Point TopRightPoint |
246 |
{ |
247 |
get { return (Point)GetValue(TopRightPointProperty); } |
248 |
set |
249 |
{ |
250 |
SetValue(TopRightPointProperty, value); |
251 |
OnPropertyChanged("TopRightPoint"); |
252 |
} |
253 |
} |
254 |
public Point LeftBottomPoint |
255 |
{ |
256 |
get { return (Point)GetValue(LeftBottomPointProperty); } |
257 |
set |
258 |
{ |
259 |
SetValue(LeftBottomPointProperty, value); |
260 |
OnPropertyChanged("LeftBottomPoint"); |
261 |
} |
262 |
} |
263 |
public double CenterX |
264 |
{ |
265 |
get { return (double)GetValue(CenterXProperty); } |
266 |
set { SetValue(CenterXProperty, value); } |
267 |
} |
268 |
public double CenterY |
269 |
{ |
270 |
get { return (double)GetValue(CenterYProperty); } |
271 |
set { SetValue(CenterYProperty, value); } |
272 |
} |
273 |
public string Text |
274 |
{ |
275 |
get { return (string)GetValue(TextProperty); } |
276 |
set |
277 |
{ |
278 |
if (this.Text != value) |
279 |
{ |
280 |
SetValue(TextProperty, value); |
281 |
OnPropertyChanged("Text"); |
282 |
} |
283 |
} |
284 |
} |
285 |
public Geometry PathData |
286 |
{ |
287 |
get { return (Geometry)GetValue(PathDataProperty); } |
288 |
set |
289 |
{ |
290 |
SetValue(PathDataProperty, value); |
291 |
OnPropertyChanged("PathData"); |
292 |
} |
293 |
} |
294 |
public SolidColorBrush FontColor |
295 |
{ |
296 |
get { return (SolidColorBrush)GetValue(FontColorProperty); } |
297 |
set |
298 |
{ |
299 |
if (this.FontColor != value) |
300 |
{ |
301 |
SetValue(FontColorProperty, value); |
302 |
OnPropertyChanged("FontColor"); |
303 |
} |
304 |
|
305 |
} |
306 |
} |
307 |
public Point EndPoint |
308 |
{ |
309 |
get { return (Point)GetValue(EndPointProperty); } |
310 |
set |
311 |
{ |
312 |
if (this.EndPoint != value) |
313 |
{ |
314 |
SetValue(EndPointProperty, value); |
315 |
OnPropertyChanged("EndPoint"); |
316 |
} |
317 |
} |
318 |
} |
319 |
public Point StartPoint |
320 |
{ |
321 |
get { return (Point)GetValue(StartPointProperty); } |
322 |
set |
323 |
{ |
324 |
if (this.StartPoint != value) |
325 |
{ |
326 |
SetValue(StartPointProperty, value); |
327 |
OnPropertyChanged("StartPoint"); |
328 |
} |
329 |
} |
330 |
} |
331 |
|
332 |
public Point OverViewStartPoint |
333 |
{ |
334 |
get { return (Point)GetValue(OverViewStartPointProperty); } |
335 |
set { SetValue(OverViewStartPointProperty, value); } |
336 |
} |
337 |
|
338 |
public Point OverViewEndPoint |
339 |
{ |
340 |
get { return (Point)GetValue(OverViewEndPointProperty); } |
341 |
set { SetValue(OverViewEndPointProperty, value); } |
342 |
} |
343 |
|
344 |
//public int MyProperty { get; set; } |
345 |
|
346 |
|
347 |
#endregion |
348 |
#region Data |
349 |
LineGeometry p1 = new LineGeometry(); |
350 |
LineGeometry p2 = new LineGeometry(); |
351 |
LineGeometry p3 = new LineGeometry(); |
352 |
LineGeometry p4 = new LineGeometry(); |
353 |
GeometryGroup instanceGroup = new GeometryGroup(); |
354 |
FormattedText text; |
355 |
#endregion |
356 |
public override void OnApplyTemplate() |
357 |
{ |
358 |
base.OnApplyTemplate(); |
359 |
Base_ViewBox = GetTemplateChild(PART_ViewBox) as Viewbox; |
360 |
Base_TextBox = GetTemplateChild(PART_TextBox) as TextBlock; |
361 |
Base_TextBox.Visibility = System.Windows.Visibility.Hidden; |
362 |
SetDate(); |
363 |
} |
364 |
public void SetDate() |
365 |
{ |
366 |
if (Text == null) |
367 |
{ |
368 |
Text = DateTime.Now.ToString("yyyy-MM-dd"); |
369 |
} |
370 |
this.ApplyTemplate(); |
371 |
instanceGroup.Children.Clear(); |
372 |
Base_TextBox.Visibility = System.Windows.Visibility.Visible; |
373 |
Point mid = MathSet.FindCentroid(new List<Point>() |
374 |
{ |
375 |
this.StartPoint, |
376 |
this.LeftBottomPoint, |
377 |
this.EndPoint, |
378 |
this.TopRightPoint, |
379 |
}); |
380 |
|
381 |
|
382 |
double AngleData = this.Angle * -1; |
383 |
|
384 |
PathFigure pathFigure = new PathFigure(); |
385 |
pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
386 |
|
387 |
LineSegment lineSegment0 = new LineSegment(); |
388 |
lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
389 |
pathFigure.Segments.Add(lineSegment0); |
390 |
|
391 |
LineSegment lineSegment1 = new LineSegment(); |
392 |
lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData); |
393 |
pathFigure.Segments.Add(lineSegment1); |
394 |
|
395 |
LineSegment lineSegment2 = new LineSegment(); |
396 |
lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData); |
397 |
pathFigure.Segments.Add(lineSegment2); |
398 |
|
399 |
LineSegment lineSegment3 = new LineSegment(); |
400 |
lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData); |
401 |
pathFigure.Segments.Add(lineSegment3); |
402 |
|
403 |
PathGeometry pathGeometry = new PathGeometry(); |
404 |
pathGeometry.Figures = new PathFigureCollection(); |
405 |
pathFigure.IsClosed = true; |
406 |
pathGeometry.Figures.Add(pathFigure); |
407 |
this.Base_ViewBox.Width = pathGeometry.Bounds.Width; |
408 |
this.Base_ViewBox.Height = pathGeometry.Bounds.Height; |
409 |
this.Tag = pathGeometry; |
410 |
|
411 |
Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2); |
412 |
Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2); |
413 |
|
414 |
//CenterX = MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2; |
415 |
//CenterY = MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2; |
416 |
|
417 |
instanceGroup.Children.Add(pathGeometry); |
418 |
|
419 |
text = new FormattedText(Text, System.Globalization.CultureInfo.CurrentCulture, |
420 |
FlowDirection.LeftToRight, new Typeface("Tahoma"), 16, Brushes.Black); |
421 |
|
422 |
instanceGroup.Children.Add(text.BuildGeometry(new Point(10,10))); |
423 |
|
424 |
PathData = instanceGroup; |
425 |
//OverViewPathData = PathData; |
426 |
|
427 |
|
428 |
} |
429 |
|
430 |
public event PropertyChangedEventHandler PropertyChanged; |
431 |
protected void OnPropertyChanged(string propName) |
432 |
{ |
433 |
if (PropertyChanged != null) |
434 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
435 |
} |
436 |
|
437 |
public void Dispose() |
438 |
{ |
439 |
GC.Collect(); |
440 |
GC.SuppressFinalize(this); |
441 |
} |
442 |
|
443 |
public void ApplyOverViewData() |
444 |
{ |
445 |
//this.OverViewPathData = this.PathData; |
446 |
this.OverViewStartPoint = this.StartPoint; |
447 |
this.OverViewEndPoint = this.EndPoint; |
448 |
} |
449 |
|
450 |
public void updateControl() |
451 |
{ |
452 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
453 |
this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
454 |
this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
455 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
456 |
this.SetDate(); |
457 |
} |
458 |
|
459 |
/// <summary> |
460 |
/// Serialize this |
461 |
/// </summary> |
462 |
/// <param name="sUserId"></param> |
463 |
/// <returns></returns> |
464 |
public override string Serialize() |
465 |
{ |
466 |
using (S_DateControl STemp = new S_DateControl()) |
467 |
{ |
468 |
STemp.Angle = this.Angle; |
469 |
STemp.EndPoint = this.EndPoint; |
470 |
STemp.UserID = this.UserID; |
471 |
STemp.LB = this.LeftBottomPoint; |
472 |
STemp.Name = this.GetType().Name; |
473 |
STemp.PointSet = this.PointSet; |
474 |
STemp.StartPoint = this.StartPoint; |
475 |
STemp.Opac = this.Opacity; |
476 |
STemp.TR = this.TopRightPoint; |
477 |
STemp.TransformPoint = "0|0"; |
478 |
STemp.FontColor = this.FontColor.Color.ToString(); |
479 |
//STemp.FontColor = "#FFFFFF00"; |
480 |
STemp.SizeSet = String.Format("{0}", this.LineSize); |
481 |
STemp.Text = this.Text; |
482 |
///강인구 추가(2017.11.02) |
483 |
///Memo 추가 |
484 |
STemp.Memo = this.Memo; |
485 |
|
486 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
487 |
} |
488 |
} |
489 |
} |
490 |
} |