프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkupToPDF / Controls / Etc / DateControl.cs @ a5b465dc

이력 | 보기 | 이력해설 | 다운로드 (20.5 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
using System.Linq;
18

    
19
namespace MarkupToPDF.Controls.Etc
20
{
21
    public class DateControl : CommentUserInfo, IDisposable, IPath, INotifyPropertyChanged, IViewBox, IMarkupCommonData
22
    {
23
        private const string PART_ViewBox = "PART_ViewBox";
24
        private const string PART_TextBox = "PART_TextBox";
25
        public Viewbox Base_ViewBox = null;
26
        public TextBlock Base_TextBox = null;
27

    
28
        static DateControl()
29
        {
30
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DateControl), new FrameworkPropertyMetadata(typeof(DateControl)));
31
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
32
            ResourceDictionary dictionary = new ResourceDictionary();
33
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
34
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
35
            System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
36
        }
37
     
38
        public DateControl()
39
        {
40
            this.DefaultStyleKey = typeof(DateControl);
41
        }
42

    
43

    
44
        #region Dependency Properties
45

    
46

    
47
        public static readonly DependencyProperty IsSelectedProperty =
48
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(DateControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
49

    
50
        public static readonly DependencyProperty ControlTypeProperty =
51
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(DateControl), new FrameworkPropertyMetadata(ControlType.Date));
52

    
53
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
54
        "OverViewPathData", typeof(Geometry), typeof(DateControl), null);
55

    
56
        public static readonly DependencyProperty OverViewStartPointProperty = DependencyProperty.Register(
57
        "OverViewStartPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(null));
58

    
59
        public static readonly DependencyProperty OverViewEndPointProperty = DependencyProperty.Register(
60
                "OverViewEndPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(null));
61

    
62

    
63
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
64
                "Text", typeof(string), typeof(DateControl), new PropertyMetadata(null));
65
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
66
                "UserID", typeof(string), typeof(DateControl), new PropertyMetadata(null));
67
        public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register(
68
               "FontColor", typeof(SolidColorBrush), typeof(DateControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
69
        //[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
70
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
71
              "StartPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
72
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
73
               "EndPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
74
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
75
               "LineSize", typeof(double), typeof(DateControl), new PropertyMetadata((double)3));
76
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
77
                "TopRightPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), TRPointValueChanged));
78
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
79
                "PointSet", typeof(List<Point>), typeof(DateControl), new PropertyMetadata(new List<Point>()));
80
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
81
                 "LeftBottomPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), LBPointValueChanged));
82
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
83
                "PathData", typeof(Geometry), typeof(DateControl), null);
84
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(DateControl),
85
            new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
86

    
87
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(DateControl),
88
            new PropertyMetadata((double)0, OnCenterXYChanged));
89

    
90
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(DateControl),
91
            new PropertyMetadata((double)0, OnCenterXYChanged));
92

    
93
        #endregion
94
        #region PropertyChanged Method
95
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
96
        {
97
            //var instance = (DateControl)sender;
98

    
99
            //if (e.OldValue != e.NewValue && instance.Base_ViewBox != null)
100
            //{
101

    
102
            //    instance.SetValue(e.Property, e.NewValue);
103

    
104
            //    if (instance.IsSelected)
105
            //    {
106
            //        //instance.Base_ViewBox.Style. = new SolidColorBrush(Colors.Blue);
107
            //    }
108
            //    else
109
            //    {
110
            //        //instance.Base_ViewBox.Stroke = new SolidColorBrush(Colors.Red);
111
            //    }
112
            //}
113
        }
114

    
115
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
116
        {
117
            var instance = (DateControl)sender;
118
            if (e.OldValue != e.NewValue && instance.Base_TextBox != null)
119
            {
120
                instance.SetValue(e.Property, e.NewValue);
121
                instance.SetDate();
122
            }
123
        }
124
        public static void LBPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
125
        {
126
            var instance = (DateControl)sender;
127
            if (e.OldValue != e.NewValue && instance.Base_TextBox != null)
128
            {
129
                instance.SetValue(e.Property, e.NewValue);
130
                //instance.EndPoint = new Point(instance.EndPoint.X, ((Point)e.NewValue).Y);
131
                //instance.StartPoint = new Point(((Point)e.NewValue).X, instance.StartPoint.Y);
132
                ////instance.PointSet[0] = instance.StartPoint;
133
                ////instance.PointSet[2] = instance.EndPoint;
134
                instance.SetDate();
135
            }
136
        }
137
        public static void TRPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
138
        {
139
            var instance = (DateControl)sender;
140
            if (e.OldValue != e.NewValue && instance.Base_TextBox != null)
141
            {
142
                instance.SetValue(e.Property, e.NewValue);
143
                instance.SetDate();
144
            }
145
        }
146
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
147
        {
148
            var instance = (DateControl)sender;
149
            if (e.OldValue != e.NewValue && instance.Base_ViewBox != null)
150
            {
151
                instance.SetValue(e.Property, e.NewValue);
152
                instance.SetDate();
153
            }
154
        }
155

    
156
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
157
        {
158
            var instance = (DateControl)sender;
159
            if (e.OldValue != e.NewValue && instance.Base_ViewBox != null)
160
            {
161
                instance.SetValue(e.Property, e.NewValue);
162
                instance.SetDate();
163
            }
164
        }
165
        #endregion
166
        #region Properties
167
        public double LineSize
168
        {
169
            get { return (double)GetValue(LineSizeProperty); }
170
            set
171
            {
172
                if (this.LineSize != value)
173
                {
174
                    SetValue(LineSizeProperty, value);
175
                    OnPropertyChanged("LineSize");
176
                }
177
            }
178
        }
179
        public string UserID
180
        {
181
            get { return (string)GetValue(UserIDProperty); }
182
            set
183
            {
184
                if (this.UserID != value)
185
                {
186
                    SetValue(UserIDProperty, value);
187
                    OnPropertyChanged("UserID");
188
                }
189
            }
190
        }
191
        public double Angle
192
        {
193
            get { return (double)GetValue(AngleProperty); }
194
            set
195
            {
196
                if (this.Angle != value)
197
                {
198
                    SetValue(AngleProperty, value);
199
                }
200
            }
201
        }
202

    
203

    
204

    
205
        public override bool IsSelected
206
        {
207
            get
208
            {
209
                return (bool)GetValue(IsSelectedProperty);
210
            }
211
            set
212
            {
213
                SetValue(IsSelectedProperty, value);
214
                OnPropertyChanged("IsSelected");
215
            }
216
        }
217

    
218
        public override ControlType ControlType
219
        {
220
            set
221
            {
222
                SetValue(ControlTypeProperty, value);
223
                OnPropertyChanged("ControlType");
224
            }
225
            get
226
            {
227
                return (ControlType)GetValue(ControlTypeProperty);
228
            }
229
        }
230

    
231
        public Geometry OverViewPathData
232
        {
233
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
234
            set
235
            {
236
                SetValue(OverViewPathDataProperty, value);
237
                OnPropertyChanged("OverViewPathData");
238
            }
239
        }
240

    
241
        public List<Point> PointSet
242
        {
243
            get { return (List<Point>)GetValue(PointSetProperty); }
244
            set { SetValue(PointSetProperty, value); }
245
        }
246
        public Point TopRightPoint
247
        {
248
            get { return (Point)GetValue(TopRightPointProperty); }
249
            set
250
            {
251
                SetValue(TopRightPointProperty, value);
252
                OnPropertyChanged("TopRightPoint");
253
            }
254
        }
255
        public Point LeftBottomPoint
256
        {
257
            get { return (Point)GetValue(LeftBottomPointProperty); }
258
            set
259
            {
260
                SetValue(LeftBottomPointProperty, value);
261
                OnPropertyChanged("LeftBottomPoint");
262
            }
263
        }
264
        public double CenterX
265
        {
266
            get { return (double)GetValue(CenterXProperty); }
267
            set { SetValue(CenterXProperty, value); }
268
        }
269
        public double CenterY
270
        {
271
            get { return (double)GetValue(CenterYProperty); }
272
            set { SetValue(CenterYProperty, value); }
273
        }
274
        public string Text
275
        {
276
            get { return (string)GetValue(TextProperty); }
277
            set
278
            {
279
                if (this.Text != value)
280
                {
281
                    SetValue(TextProperty, value);
282
                    OnPropertyChanged("Text");
283
                }
284
            }
285
        }
286
        public Geometry PathData
287
        {
288
            get { return (Geometry)GetValue(PathDataProperty); }
289
            set
290
            {
291
                SetValue(PathDataProperty, value);
292
                OnPropertyChanged("PathData");
293
            }
294
        }
295
        public SolidColorBrush FontColor
296
        {
297
            get { return (SolidColorBrush)GetValue(FontColorProperty); }
298
            set
299
            {
300
                if (this.FontColor != value)
301
                {
302
                    SetValue(FontColorProperty, value);
303
                    OnPropertyChanged("FontColor");
304
                }
305

    
306
            }
307
        }
308
        public Point EndPoint
309
        {
310
            get { return (Point)GetValue(EndPointProperty); }
311
            set
312
            {
313
                if (this.EndPoint != value)
314
                {
315
                    SetValue(EndPointProperty, value);
316
                    OnPropertyChanged("EndPoint");
317
                }
318
            }
319
        }
320
        public Point StartPoint
321
        {
322
            get { return (Point)GetValue(StartPointProperty); }
323
            set
324
            {
325
                if (this.StartPoint != value)
326
                {
327
                    SetValue(StartPointProperty, value);
328
                    OnPropertyChanged("StartPoint");
329
                }
330
            }
331
        }
332

    
333
        public Point OverViewStartPoint
334
        {
335
            get { return (Point)GetValue(OverViewStartPointProperty); }
336
            set { SetValue(OverViewStartPointProperty, value); }
337
        }
338

    
339
        public Point OverViewEndPoint
340
        {
341
            get { return (Point)GetValue(OverViewEndPointProperty); }
342
            set { SetValue(OverViewEndPointProperty, value); }
343
        }
344

    
345
        //public int MyProperty { get; set; }
346

    
347

    
348
        #endregion
349
        #region Data
350
        LineGeometry p1 = new LineGeometry();
351
        LineGeometry p2 = new LineGeometry();
352
        LineGeometry p3 = new LineGeometry();
353
        LineGeometry p4 = new LineGeometry();
354
        GeometryGroup instanceGroup = new GeometryGroup();
355
        FormattedText text;
356
        #endregion
357
        public override void OnApplyTemplate()
358
        {
359
            base.OnApplyTemplate();
360
            Base_ViewBox = GetTemplateChild(PART_ViewBox) as Viewbox;
361
            Base_TextBox = GetTemplateChild(PART_TextBox) as TextBlock;
362
            Base_TextBox.Visibility = System.Windows.Visibility.Hidden;
363
            SetDate();
364
        }
365

    
366
        private void SetDate()
367
        {
368
            if (Text == null)
369
            {
370
                Text = DateTime.Now.ToString("yyyy-MM-dd");
371
            }
372
            this.ApplyTemplate();
373
            instanceGroup.Children.Clear();
374
            Base_TextBox.Visibility = System.Windows.Visibility.Visible;
375
            Point mid = MathSet.FindCentroid(new List<Point>()
376
            {
377
                this.StartPoint,
378
                this.LeftBottomPoint,
379
                this.EndPoint,
380
                this.TopRightPoint,                
381
            });
382

    
383

    
384
            double AngleData = this.Angle * -1;
385

    
386
            PathFigure pathFigure = new PathFigure();
387
            pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
388

    
389
            LineSegment lineSegment0 = new LineSegment();
390
            lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
391
            pathFigure.Segments.Add(lineSegment0);
392

    
393
            LineSegment lineSegment1 = new LineSegment();
394
            lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData);
395
            pathFigure.Segments.Add(lineSegment1);
396

    
397
            LineSegment lineSegment2 = new LineSegment();
398
            lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData);
399
            pathFigure.Segments.Add(lineSegment2);
400

    
401
            LineSegment lineSegment3 = new LineSegment();
402
            lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData);
403
            pathFigure.Segments.Add(lineSegment3);
404

    
405
            PathGeometry pathGeometry = new PathGeometry();
406
            pathGeometry.Figures = new PathFigureCollection();
407
            pathFigure.IsClosed = true;
408
            pathGeometry.Figures.Add(pathFigure);
409
            this.Base_ViewBox.Width = pathGeometry.Bounds.Width;
410
            this.Base_ViewBox.Height = pathGeometry.Bounds.Height;
411
            this.Tag = pathGeometry;
412

    
413
            Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2);
414
            Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2);
415

    
416
            //CenterX = MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2;
417
            //CenterY = MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2;
418

    
419
            instanceGroup.Children.Add(pathGeometry);
420

    
421
            text = new FormattedText(Text, System.Globalization.CultureInfo.CurrentCulture,
422
                 FlowDirection.LeftToRight, new Typeface("Tahoma"), 16, Brushes.Black);
423

    
424
            instanceGroup.Children.Add(text.BuildGeometry(new Point(10,10)));
425

    
426
            PathData = instanceGroup;
427
            //OverViewPathData = PathData;
428

    
429

    
430
        }
431

    
432
        public event PropertyChangedEventHandler PropertyChanged;
433
        protected void OnPropertyChanged(string propName)
434
        {
435
            if (PropertyChanged != null)
436
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
437
        }
438

    
439
        public void Dispose()
440
        {
441
            GC.Collect();
442
            GC.SuppressFinalize(this);
443
        }
444

    
445
        public void ApplyOverViewData()
446
        {
447
            //this.OverViewPathData = this.PathData;
448
            this.OverViewStartPoint = this.StartPoint;
449
            this.OverViewEndPoint = this.EndPoint;
450
        }
451

    
452
        public void updateControl()
453
        {
454
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
455
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
456
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
457
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
458
            this.SetDate();
459
        }
460

    
461
        /// <summary>
462
        /// return DateControl's area
463
        /// </summary>
464
        /// <author>humkyung</author>
465
        /// <date>2019.06.13</date>
466
        public override Rect ItemRect
467
        {
468
            get
469
            {
470
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
471
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
472
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
473
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
474

    
475
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
476
            }
477
        }
478

    
479
        /// <summary>
480
        /// Serialize this
481
        /// </summary>
482
        /// <param name="sUserId"></param>
483
        /// <returns></returns>
484
        public override string Serialize()
485
        {
486
            using (S_DateControl STemp = new S_DateControl())
487
            {
488
                STemp.Angle = this.Angle;
489
                STemp.EndPoint = this.EndPoint;
490
                STemp.UserID = this.UserID;
491
                STemp.LB = this.LeftBottomPoint;
492
                STemp.Name = this.GetType().Name;
493
                STemp.PointSet = this.PointSet;
494
                STemp.StartPoint = this.StartPoint;
495
                STemp.Opac = this.Opacity;
496
                STemp.TR = this.TopRightPoint;
497
                STemp.TransformPoint = "0|0";
498
                STemp.FontColor = this.FontColor.Color.ToString();
499
                //STemp.FontColor = "#FFFFFF00";
500
                STemp.SizeSet = String.Format("{0}", this.LineSize);
501
                STemp.Text = this.Text;
502
                ///강인구 추가(2017.11.02)
503
                ///Memo 추가
504
                STemp.Memo = this.Memo;
505

    
506
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
507
            }
508
        }
509

    
510
        /// <summary>
511
        /// create a datecontrol from given string
512
        /// </summary>
513
        /// <param name="str"></param>
514
        /// <returns></returns>
515
        public static DateControl FromString(string str, SolidColorBrush brush, string sProjectNo)
516
        {
517
            using (S_DateControl s = JsonSerializerHelper.JsonDeserialize<S_DateControl>(str))
518
            {
519
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
520
                return new DateControl
521
                {
522
                    Angle = s.Angle,
523
                    StartPoint = s.StartPoint,
524
                    EndPoint = s.EndPoint,
525
                    LeftBottomPoint = s.LB,
526
                    TopRightPoint = s.TR,
527
                    Opacity = s.Opac,
528
                    FontColor = brush,
529
                    LineSize = Convert.ToDouble(data2.First()),
530
                    Text = s.Text,
531
                    PointSet = s.PointSet,
532
                    UserID = s.UserID,
533
                    Memo = s.Memo
534
                };
535
            }
536
        }
537
    }
538
}
클립보드 이미지 추가 (최대 크기: 500 MB)