프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 5c6aea78

이력 | 보기 | 이력해설 | 다운로드 (38.7 KB)

1 787a4489 KangIngu
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Windows;
5
using System.Windows.Controls;
6
using System.Windows.Media;
7
using Telerik.Windows.Controls;
8
using System.Collections.ObjectModel;
9
using System.Drawing.Printing;
10
using System.Windows.Media.Imaging;
11
using System.Reactive.Linq;
12
using KCOMDataModel.DataModel;
13
using Microsoft.Win32;
14
using System.IO;
15
using System.Timers;
16
//using IKCOM.Common;
17
using KCOM.Event;
18
using iTextSharp;
19
using iTextSharp.text;
20
//using Leadtools.Windows.Controls;
21
using IKCOM;
22
using iTextSharp.text.pdf;
23
using Microsoft.Office.Core;
24 481c3fb9 djkim
using System.Net;
25 86bff326 taeseongkim
using Image = System.Windows.Controls.Image;
26 e3a15e22 djkim
27 787a4489 KangIngu
namespace KCOM.Control
28
{
29
    public class DefinedPages
30
    {
31 86bff326 taeseongkim
        public DOCINFO DocumentInfo { get; set; }
32
33 787a4489 KangIngu
        public int PagesCount { get; set; }
34
        public string vpSlip { get; set; }
35
        public string vpTitle { get; set; }
36
        public string fileUrl { get; set; }
37
        public ImageBrush Back_Image { get; set; }
38
39 86bff326 taeseongkim
        public double CurrentValue { get; set; }
40
41 787a4489 KangIngu
        string _DefinedPagesStrings;
42
        /// <summary>
43
        /// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용
44
        /// </summary>
45
        public string DefinedPagesStrings
46
        {
47
            get { return _DefinedPagesStrings; }
48
            set
49
            {
50
                if (string.IsNullOrWhiteSpace(value)) return;
51
52
                var _definedPages = value.Replace('-', ',').Split(',');
53
                List<char> _NotEx = new List<char>();
54
55
                foreach (var item in _definedPages)
56
                {
57
                    bool _isNum = true;
58
59
                    foreach (var chr in item)
60
                    {
61
                        if (!char.IsNumber(chr))
62
                        {
63
                            _NotEx.Add(chr);
64
                            _isNum = false;
65
                        }
66
                    }
67
68
                    if (_isNum)
69
                    {
70
                        if (Convert.ToInt32(item) > PagesCount)
71
                            throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount));
72
                    }
73
                }
74
75
                if (_NotEx.Count() > 0)
76
                {
77
                    string _notString = "";
78
                    _NotEx.ForEach(s => _notString += s.ToString());
79
                    throw new Exception(string.Format("'{0}' Can not be added.", _notString));
80
                }
81
82
83
                try
84
                {
85
86
                    string _notString2 = "";
87
                    _NotEx.ForEach(s => _notString2 += s.ToString());
88
                    _DefinedPagesStrings = value;
89
                }
90
                catch (Exception)
91
                {
92
                    throw new Exception(string.Format("Can not be added."));
93
                }
94
95
            }
96
        }
97
    }
98
99
    /// <summary>
100
    /// Interaction logic for Print.xaml
101
    /// </summary>
102
    public partial class PrintControl : UserControl
103
    {
104
        #region Data
105
106
        string ProjectNo = null; //프로젝트 넘버
107
        string _DefaultTileUri = null; //기본 타일 경로
108
        int _StartPageNo; //시작페이지 
109
        DOCINFO _DocInfo; //문서 정보
110
        //DocInfo _DocInfo; //문서 정보
111
        bool currentPagePrint = false; //현재 페이지 수
112
        int PageCount { get; set; } //총 페이지수 
113
        DefinedPages _definePages = null; //인쇄 설정 범위 지정
114
        public bool IsPrint { get; set; }
115
116
        PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성
117
118
        //LayerControl LayerControl = null; // 레이어 컨트롤
119
        ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보
120
        List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>();
121
        List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>();
122
        List<int> _lstPrintPageNo = new List<int>();
123
124
        System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer();
125
        bool _initializeComponentFinished; //이벤트
126
        bool _IsDagSlider = false; //드래그 상태인가
127
        List<DisplayColorInfo> colorList = new List<DisplayColorInfo>();
128
        DefinedPages DocumentInfo { get; set; } //문서정보 정의        
129
        //PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 
130
        delegate void PrintEventHandler(); //프린트 핸들러
131
        SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그
132
        //SaveFileDialog SaveFile { get; set; } //저장할 때 사용
133
134
        //RasterImageViewer _viewer; //이미지 뷰어
135 53880c83 ljiyeon
        //System.Windows.Controls.Image backimg; //백그라운드 이미지
136 787a4489 KangIngu
        System.Drawing.Image Printimg; //프린트 이미지
137
        System.Drawing.Image p_img; //프린트 이미지
138
        iTextSharp.text.Image Export_img;
139 481c3fb9 djkim
        Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지
140 787a4489 KangIngu
141
        //RasterCodecs codecs;
142
        int currentPage;
143
        public string PrintName;
144
        public string Type;
145
146
        public System.Timers.Timer timm = new System.Timers.Timer();
147
148
149
        #endregion
150
151
        #region Static Property Defines
152
        public static readonly DependencyProperty CurrentPageNoProperty =
153
                   DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl),
154
                   new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged)));
155
        #endregion
156
157
        #region Property
158
        public int CurrentPageNo
159
        {
160
            get { return (int)GetValue(CurrentPageNoProperty); }
161
            set { SetValue(CurrentPageNoProperty, value); }
162
        }
163
        #endregion
164
165
        #region PropertyChangeMethod
166
        private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
167
        {
168
            var printPage = (PrintControl)d;
169
            var newValue = (int)e.NewValue;
170
171
            printPage.sliderPages.Value = newValue;
172
            printPage.SetLoadMakupList(newValue);
173
174
        }
175
        #endregion
176
177
        #region 생성자
178 481c3fb9 djkim
179 787a4489 KangIngu
        public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint)
180
        {
181
            InitializeComponent();
182 481c3fb9 djkim
183 787a4489 KangIngu
            this.IsEnabled = true;
184
185
            //Layer Control을 통째로 가져와야 하는건가
186
            this._DocInfo = DocInfo;
187
            this._DefaultTileUri = TileSourceUri;
188
            this.ProjectNo = ProjectNo;
189
            this._StartPageNo = CurrentPageNo;
190
191
            markupInfo.ForEach(info => this._markupInfo.Add(info));
192
193
            foreach (var info in _markupInfo)
194
            {
195
                if (info.Consolidate == 1)
196
                {
197
                    info.UserName = "Consolidation";
198
                }
199
                info.MarkupList.ForEach(makup =>
200
                {
201
                    var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber);
202
                    var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor };
203
204
                    if (_pageMarkup.Count() > 0)
205
                        _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem);
206
                    else
207
                        _PageMarkupList.Add(new MarkupPageItem
208
                        {
209
                            PageNumber = makup.PageNumber,
210
                            DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem }
211
                        });
212
                });
213
214
                colorList.Add(new DisplayColorInfo
215
                {
216
                    UserID = info.UserID,
217
                    DisplayColor = info.DisplayColor,
218
                    Department = info.Depatment,
219
                    UserName = info.UserName,
220
                });
221
            }
222
223
            gridViewMarkup.ItemsSource = this._markupInfo;
224
            SetLoadMakupList(this._StartPageNo);
225
            if (_LoadMakupList.Count() == 0)
226
                chkOnlyMarkup.IsChecked = false;
227
228
            this.CurrentPageNo = _StartPageNo;
229 86bff326 taeseongkim
230
            _definePages = new DefinedPages { DefinedPagesStrings = "", DocumentInfo = this._DocInfo
231
                            , PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
232
233 787a4489 KangIngu
            DocumentInfo = _definePages;
234
            this.DataContext = _definePages;
235
236
            CheckCommentPages();
237
238
            //초기화면 Comment Check된 상태로 보여주기
239
            foreach (var item in _markupInfo)
240
            {
241
                gridViewMarkup.SelectedItems.Add(item);
242
            }
243
244 86bff326 taeseongkim
            PageChangeAsync(_StartPageNo).ConfigureAwait(true);
245 787a4489 KangIngu
246
            sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
247
            this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
248
            this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
249
            this.IsPrint = isPrint;
250
251
            if (!IsPrint)
252
            {
253
                GetPrint(false);
254
                btnWholeExport.Visibility = Visibility.Visible;
255
                btnWholePrint.Visibility = Visibility.Collapsed;
256
                Selected_Print.Header = "Export Type";
257
            }
258
            else
259
            {
260
                //PrintList 가져오기
261
                GetPrint(true);
262
                btnWholePrint.Visibility = Visibility.Visible;
263
                btnWholeExport.Visibility = Visibility.Collapsed;
264
            }
265
266
            _initializeComponentFinished = true;
267
268
            //timm.Interval = 10;
269
            //timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed);
270
            //timm.Enabled = true;
271
        }
272
273
        private void _Timer_Elapsed(object sender, ElapsedEventArgs e)
274
        {
275
            timm.Enabled = false;
276 86bff326 taeseongkim
            PageChangeAsync(_StartPageNo);
277 787a4489 KangIngu
        }
278
        #endregion
279
280
        #region Control Event
281 86bff326 taeseongkim
        private async void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
282 787a4489 KangIngu
        {
283
            if (_initializeComponentFinished)
284
            {
285
                if (!_IsDagSlider)
286
                {
287
                    this.CurrentPageNo = (int)this.sliderPages.Value;
288 90865212 taeseongkim
                    await PageChangeAsync(this.CurrentPageNo);
289
                    //await App.PageStorage.GetPageUriAsync(this.CurrentPageNo);
290 53deabaf taeseongkim
                
291 481c3fb9 djkim
                    if (_ButtonName == "Current")
292 114015fd ljiyeon
                    {
293
                        stPageNo.Value = CurrentPageNo;
294
                        edPageNo.Value = CurrentPageNo;
295 481c3fb9 djkim
                    }
296 114015fd ljiyeon
297 787a4489 KangIngu
                    //CheckCommentPages();
298
                }
299
            }
300
        }
301
302 86bff326 taeseongkim
        private async void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
303 787a4489 KangIngu
        {
304
            _IsDagSlider = false;
305
            this.CurrentPageNo = (int)this.sliderPages.Value;
306
            if (_initializeComponentFinished)
307
            {
308 90865212 taeseongkim
               
309 787a4489 KangIngu
            }
310
        }
311
312
        private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e)
313
        {
314
            _IsDagSlider = true;
315
        }
316
317
        private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e)
318
        {
319
            if (_initializeComponentFinished)      //GridRangePages
320
            {
321
                CheckCommentPages();
322
            }
323
        }
324 114015fd ljiyeon
        string _ButtonName;
325 787a4489 KangIngu
        private void PageSelect_Checked(object sender, RoutedEventArgs e)
326
        {
327
            if (!_initializeComponentFinished) return;
328
329 114015fd ljiyeon
            _ButtonName = (sender as RadRadioButton).Tag.ToString();
330 787a4489 KangIngu
            CommentPageList.ItemsSource = null;
331
332
            switch (_ButtonName)
333
            {
334
                case "Current":
335
                    stPageNo.Value = CurrentPageNo;
336
                    edPageNo.Value = CurrentPageNo;
337
338
                    GridCurrentPage.Visibility = Visibility.Visible;
339
                    GridDefinePages.Visibility = Visibility.Collapsed;
340
                    GridRangePages.Visibility = Visibility.Collapsed;
341
                    GridAllPages.Visibility = Visibility.Collapsed;
342
343
                    break;
344
                case "RangePrint":
345
                    GridCurrentPage.Visibility = Visibility.Collapsed;
346
                    GridDefinePages.Visibility = Visibility.Visible;
347
                    GridRangePages.Visibility = Visibility.Collapsed;
348
                    GridAllPages.Visibility = Visibility.Collapsed;
349
                    break;
350
                case "UserDefined":
351
                    GridCurrentPage.Visibility = Visibility.Collapsed;
352
                    GridDefinePages.Visibility = Visibility.Collapsed;
353
                    GridRangePages.Visibility = Visibility.Visible;
354
                    GridAllPages.Visibility = Visibility.Collapsed;
355
                    break;
356
                case "AllPrint":
357
                    stPageNo.Value = 1;
358
                    edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT);
359
                    GridCurrentPage.Visibility = Visibility.Collapsed;
360
                    GridDefinePages.Visibility = Visibility.Collapsed;
361
                    GridRangePages.Visibility = Visibility.Collapsed;
362
                    GridAllPages.Visibility = Visibility.Visible;
363
                    break;
364
            }
365
366
            CheckCommentPages();
367
        }
368
369
        private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
370
        {
371
            if (_initializeComponentFinished)      //GridRangePages
372
            {
373
                if (stPageNo.Value > edPageNo.Value)
374
                {
375
                    if (sender.Equals(stPageNo))
376
                        edPageNo.Value = stPageNo.Value;
377
                    else
378
                        stPageNo.Value = edPageNo.Value;
379
                }
380
381
                //뷰어잠시제외(강인구)
382
                //this.LayoutRoot.Dispatcher.BeginInvoke(delegate()
383
                //{
384
                CheckCommentPages();
385
                //});
386
            }
387
        }
388
389
        private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e)
390
        {
391
            CheckCommentPages();
392
        }
393
394
        private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e)
395
        {
396
            txtDefinedPages.Text = "";
397
        }
398
399
        private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
400
        {
401
            if (_initializeComponentFinished)
402
                if (CommentPageList.SelectedItem != null)
403
                    this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber;
404
        }
405
406 86bff326 taeseongkim
        private async void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
407 787a4489 KangIngu
        {
408
            if (_initializeComponentFinished)
409
            {
410 86bff326 taeseongkim
                await PageChangeAsync(this.CurrentPageNo);
411 787a4489 KangIngu
            }
412
        }
413
414
        #endregion
415
416 86bff326 taeseongkim
        public async System.Threading.Tasks.Task<bool> PageChangeAsync(int PageNo, bool Flag = false)
417 787a4489 KangIngu
        {
418 53deabaf taeseongkim
            System.Diagnostics.Debug.WriteLine("PageChangeAsync " + PageNo);
419 86bff326 taeseongkim
            bool result = false;
420
            //Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
421
            //{
422
            try
423 787a4489 KangIngu
            {
424 86bff326 taeseongkim
                Load load = new Load();
425
426
                _definePages.Back_Image = new ImageBrush();
427
                //var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
428
429
                var pages = _definePages.DocumentInfo.DOCPAGE.Where(x => x.PAGE_NUMBER == PageNo);
430
431
                if(pages.Count() > 0)
432 481c3fb9 djkim
                {
433 86bff326 taeseongkim
                    var currentPage = pages.First();
434 787a4489 KangIngu
435 86bff326 taeseongkim
                    //var buffer = await new WebClient().DownloadDataTaskAsync(_DefaultTileUri + PageNo + ".png");
436
437
                    //var bitmap = new BitmapImage();
438
                    //using (var stream = new MemoryStream(buffer))
439
                    //{
440 90865212 taeseongkim
                    //bitmap.BeginInit();
441
                    //bitmap.CacheOption = BitmapCacheOption.OnLoad;
442
                    //bitmap.StreamSource = stream;
443
                    //bitmap.EndInit();
444
445
                        
446 00143658 taeseongkim
                        var uri = await  App.PageStorage.GetPageUriAsync(currentPage.PAGE_NUMBER);
447 90865212 taeseongkim
                    //Image bitmap = new Image();
448
                    //bitmap.Stretch = Stretch.Fill;
449
                    //bitmap.Source = bitmapframe;
450
                    //bitmap.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
451
                    //bitmap.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
452 00143658 taeseongkim
                    printCanvas.Children.Clear();
453
                    printCanvas.Width = Convert.ToDouble(currentPage.PAGE_WIDTH);
454
                    printCanvas.Height = Convert.ToDouble(currentPage.PAGE_HEIGHT);
455
                    printCanvas.Background = new ImageBrush { ImageSource = new BitmapImage(uri)};
456 90865212 taeseongkim
457 00143658 taeseongkim
                    //printCanvas.RenderTransformOrigin = new Point(0.5, 0.5);
458
                    //printCanvas.RenderTransform = new RotateTransform(currentPage.PAGE_ANGLE);
459
                    //ImageBrush background = new ImageBrush(bitmap);
460
                    //printCanvas.Background = background;
461
                    //printCanvas.Background = new SolidColorBrush(Colors.Transparent);
462 787a4489 KangIngu
463 481c3fb9 djkim
464 00143658 taeseongkim
                    foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
465
                    {
466
                        load.User_Id = info.UserID;
467
                        load.document_id = _DocInfo.DOCUMENT_ID;
468
                        load.Page_No = PageNo;
469
                        load.DisplayColor = info.DisplayColor;
470
                        load.Markupinfoid = info.MarkupInfoID;
471
                        await load.Markup_LoadAsync(printCanvas);
472
                    }
473 481c3fb9 djkim
474 90865212 taeseongkim
                    //await Dispatcher.InvokeAsync(() => {
475
                    //    printCanvas.UpdateLayout();
476
                    //});
477 481c3fb9 djkim
478 d04e8ee9 taeseongkim
                    if (Flag)
479 481c3fb9 djkim
                        {
480 d04e8ee9 taeseongkim
                        //MemoryStream ms = new MemoryStream();
481
                        //BmpBitmapEncoder bbe = new BmpBitmapEncoder();
482
                        //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
483
                        //bbe.Save(ms);
484
485
                        //System.Drawing.Image.FromFile()
486
                        //Printimg = System.Drawing.Image.FromStream(stream);
487 53deabaf taeseongkim
                        //await System.Threading.Tasks.Task.Run(() =>
488
                        //{
489
                           await Dispatcher.InvokeAsync(() =>
490 d04e8ee9 taeseongkim
                            {
491
                                Export export = new Export();
492
                                p_img = export.Exporting(PrintView, printCanvas.Width, printCanvas.Height);
493
                                Printimg_List.Add(Printimg_List.Count() + 1, p_img);
494
                            });
495 53deabaf taeseongkim
                        //});
496 d04e8ee9 taeseongkim
                    }
497 481c3fb9 djkim
498 86bff326 taeseongkim
                        result = true;
499
                    //}
500
                } 
501
            }
502
            catch (Exception ex)
503
            {
504
                Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0);
505
            }
506
507
            return result;
508
            //}));
509 787a4489 KangIngu
        }
510 481c3fb9 djkim
        public static MemoryStream ByteBufferFromImage(BitmapImage imageSource)
511
        {
512
            var ms = new MemoryStream();
513
            var pngEncoder = new PngBitmapEncoder();
514
            pngEncoder.Frames.Add(BitmapFrame.Create(imageSource));
515
            pngEncoder.Save(ms);
516 787a4489 KangIngu
517 481c3fb9 djkim
            return ms;
518
        }
519 787a4489 KangIngu
        //Print 버튼 클릭 이벤트
520
        #region Method - 명령
521 86bff326 taeseongkim
        async void PrintMethod(object sender, RoutedEventArgs e)
522 787a4489 KangIngu
        {
523 481c3fb9 djkim
            try
524
            {
525
                if (this.printIndy.IsBusy == true)
526
                    return;
527 787a4489 KangIngu
528 00143658 taeseongkim
                (this.Parent as RadWindow).CanClose = false;
529
530 86bff326 taeseongkim
                await this.Dispatcher.InvokeAsync(() => { 
531 481c3fb9 djkim
                        this.printIndy.IsBusy = true;
532
                        printIndy.BusyContent = "Printing. . .";
533
                });
534 787a4489 KangIngu
535 481c3fb9 djkim
536
                _lstPrintPageNo = PrintPageCreate();
537
538
                if (_lstPrintPageNo.Count == 0)
539 787a4489 KangIngu
                {
540 481c3fb9 djkim
                    RadWindow.Alert(new DialogParameters
541
                    {
542
                        Owner = Application.Current.MainWindow,
543
                        Theme = new VisualStudio2013Theme(),
544 eeb0a39c taeseongkim
                        Header = "Info",
545
                        Content = "Not specified the page."
546 481c3fb9 djkim
                    });
547
                    this.printIndy.IsBusy = false;
548
                    return;
549
                }
550 86bff326 taeseongkim
551 481c3fb9 djkim
                int cnt = 0;
552 787a4489 KangIngu
553 481c3fb9 djkim
                Printimg_List = new Dictionary<int, System.Drawing.Image>();
554 787a4489 KangIngu
555 481c3fb9 djkim
                foreach (int PageNo in _lstPrintPageNo)
556
                {
557
                    cnt++;
558
                    sliderPages.Value = PageNo;
559 86bff326 taeseongkim
                    await PageChangeAsync(PageNo, true);
560 481c3fb9 djkim
                    //PageChanged(cnt, true);
561
                }
562
                PrintName = cbPrint.SelectedItem.ToString();
563 787a4489 KangIngu
564 86bff326 taeseongkim
                await this.Dispatcher.InvokeAsync(() => {
565 481c3fb9 djkim
                    if (cnt == _lstPrintPageNo.Count)
566
                    {
567
                        Printing();
568
                    }
569 787a4489 KangIngu
                });
570
            }
571 481c3fb9 djkim
            catch (Exception ex)
572 787a4489 KangIngu
            {
573 481c3fb9 djkim
                Logger.sendResLog("PrintMethod", ex.Message, 0);
574 787a4489 KangIngu
            }
575 00143658 taeseongkim
            finally
576
            {
577
                (this.Parent as RadWindow).CanClose = true;
578
            }
579 787a4489 KangIngu
580
        }
581
582
        //Export 버튼 클릭 이벤트
583 86bff326 taeseongkim
        async void ExportMethod(object sender, RoutedEventArgs e)
584 787a4489 KangIngu
        {
585 481c3fb9 djkim
            try
586
            {
587
                if (this.printIndy.IsBusy == true)
588
                    return;
589 787a4489 KangIngu
590 00143658 taeseongkim
                (this.Parent as RadWindow).CanClose = false;
591
592 481c3fb9 djkim
                this.printIndy.IsBusy = true;
593
                printIndy.BusyContent = "Exporting. . .";
594 787a4489 KangIngu
595 481c3fb9 djkim
                Export export = new Export();
596
                _lstPrintPageNo = PrintPageCreate();
597 787a4489 KangIngu
598 481c3fb9 djkim
                if (_lstPrintPageNo.Count == 0)
599 787a4489 KangIngu
                {
600 481c3fb9 djkim
                    this.printIndy.IsBusy = false;
601
                    RadWindow.Alert(new DialogParameters
602 787a4489 KangIngu
                    {
603 481c3fb9 djkim
                        Owner = Application.Current.MainWindow,
604
                        Theme = new VisualStudio2013Theme(),
605 eeb0a39c taeseongkim
                        Header = "Info",
606
                        Content = "Not specified the page.",
607 481c3fb9 djkim
                    });
608
                    return;
609
                }
610 787a4489 KangIngu
611 481c3fb9 djkim
                //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png");
612 787a4489 KangIngu
613
                switch (cbPrint.SelectedIndex)
614
                {
615
                    case (0):
616
                        {
617 481c3fb9 djkim
                            SaveDig.Filter = "PDF file format|*.pdf";
618
                            break;
619
                        }
620
                    case (1):
621
                        {
622
                            SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
623
                            break;
624
                        }
625
                }
626
627
                SaveDig.Title = "Save an PDF File";
628
                if(SaveDig.ShowDialog().Value)
629
                {
630
                    Printimg_List = new Dictionary<int, System.Drawing.Image>();
631
632
                    foreach (int PageNo in _lstPrintPageNo)
633
                    {
634 d04e8ee9 taeseongkim
                        await Dispatcher.InvokeAsync(() =>
635
                        {
636
                            sliderPages.Value = PageNo;
637
                        });
638 53deabaf taeseongkim
639 86bff326 taeseongkim
                        await PageChangeAsync(PageNo, true);
640 53deabaf taeseongkim
                        System.Diagnostics.Debug.WriteLine("Export Page : " + PageNo);
641 481c3fb9 djkim
                    }
642
643
                    //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
644
645
                    if (SaveDig.FileName != "")
646
                    {
647
                        switch (cbPrint.SelectedIndex)
648
                        {
649
                            case (0):
650 787a4489 KangIngu
                                {
651 481c3fb9 djkim
                                    using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
652 787a4489 KangIngu
                                    {
653 481c3fb9 djkim
                                        using (Document doc = new Document())
654 787a4489 KangIngu
                                        {
655 481c3fb9 djkim
                                            using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
656 e3a15e22 djkim
                                            {
657 481c3fb9 djkim
                                                doc.Open();
658 00143658 taeseongkim
                                                
659 481c3fb9 djkim
                                                float height = doc.PageSize.Height;
660
                                                float width = doc.PageSize.Width;
661
662
                                                foreach (var item in Printimg_List)
663
                                                {
664
                                                    Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
665
666
                                                    if (Export_img.Width > Export_img.Height)
667
                                                    {
668
                                                        doc.SetPageSize(new Rectangle(height, width));
669
                                                        Export_img.ScaleToFit(height, width);
670
                                                    }
671
                                                    else
672
                                                    {
673
                                                        doc.SetPageSize(new Rectangle(width, height));
674
                                                        Export_img.ScaleToFit(width, height);
675
                                                    }
676
677
                                                    Export_img.SetAbsolutePosition(0, 0);
678
679
                                                    doc.NewPage();
680
                                                    doc.Add(Export_img);
681 00143658 taeseongkim
682
                                                    await System.Threading.Tasks.Task.Delay(100);
683
684 481c3fb9 djkim
                                                }
685
                                                doc.Close();
686
                                            }
687 787a4489 KangIngu
                                        }
688
                                    }
689 481c3fb9 djkim
                                    break;
690 787a4489 KangIngu
                                }
691 481c3fb9 djkim
                            case (1):
692 787a4489 KangIngu
                                {
693 481c3fb9 djkim
                                    foreach (var item in Printimg_List)
694
                                    {
695
                                        switch (SaveDig.FilterIndex)
696 787a4489 KangIngu
                                        {
697 481c3fb9 djkim
                                            case (1):
698
                                                {
699
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
700
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
701
                                                }
702
                                                break;
703
                                            case (2):
704
                                                {
705
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
706
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
707
                                                }
708
                                                break;
709 787a4489 KangIngu
                                        }
710 481c3fb9 djkim
                                    }
711
                                    break;
712 787a4489 KangIngu
                                }
713
                        }
714 481c3fb9 djkim
                    }
715
                    else
716
                    {
717
                        this.printIndy.IsBusy = false;
718
                        return;
719
                    }
720 86bff326 taeseongkim
721
                    await this.Dispatcher.InvokeAsync(() =>
722 481c3fb9 djkim
                    {
723
                        printIndy.IsBusy = false;
724 86bff326 taeseongkim
                    });
725
726
                    await PageChangeAsync(_StartPageNo);
727 787a4489 KangIngu
728 481c3fb9 djkim
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
729
                }else
730
                {
731
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
732
                    {
733
                        printIndy.IsBusy = false;
734
                    }));
735 787a4489 KangIngu
736 481c3fb9 djkim
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert");
737
                }                
738
            }
739
            catch (Exception ex)
740 787a4489 KangIngu
            {
741 86bff326 taeseongkim
                printIndy.IsBusy = false;
742
743 481c3fb9 djkim
                Logger.sendResLog("Export Method", ex.Message, 0);
744
                //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message);
745
            }
746 00143658 taeseongkim
            finally
747
            {
748
                (this.Parent as RadWindow).CanClose = true;
749
            }
750
751 787a4489 KangIngu
752
        }
753
        #endregion
754
755
        #region Method - 처리
756
        void CheckCommentPages()
757
        {
758
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
759
            DoubleCollection _Ticks = new DoubleCollection();
760
761
762
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
763
            {
764
765
                _pages = (from commPage in this._PageMarkupList
766
                          where commPage.PageNumber == CurrentPageNo
767
                          orderby commPage.PageNumber
768
                          select commPage).ToList();
769
            }
770
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
771
            {
772
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
773
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
774
775
                int _stPage = (int)stPageNo.Value;
776
                int _edPage = (int)edPageNo.Value;
777
778
                _pages = (from commPage in this._PageMarkupList
779
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
780
                          orderby commPage.PageNumber
781
                          select commPage).ToList();
782
            }
783
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
784
            {
785
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
786
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
787
788
                int _stPage = (int)stPageNo.Value;
789
                int _edPage = (int)edPageNo.Value;
790
791
                //Using DeepView.Common.RangeParser
792
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
793
                _pages = (from commPage in this._PageMarkupList
794
                          from compareData in lst
795
                          where commPage.PageNumber == compareData
796
                          orderby commPage.PageNumber
797
                          select commPage).ToList();
798
            }
799
            else
800
            {
801
                _pages = (from commPage in this._PageMarkupList
802
                          orderby commPage.PageNumber
803
                          select commPage).ToList();
804
            }
805
            CommentPageList.ItemsSource = _pages.ToList();
806
        }
807
808
        void SetLoadMakupList(int PageNo)
809
        {
810
            _LoadMakupList.Clear();
811
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
812
813
            if (_markupList.Count() > 0)
814
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
815
        }
816
817
        #region 프린트 리스트 가져오기
818
        public void GetPrint(bool flag)
819
        {
820
            if (flag)
821
            {
822
                foreach (string printer in PrinterSettings.InstalledPrinters)
823
                {
824
                    this.cbPrint.Items.Add(printer);
825
                }
826
                printDocument = new PrintDocument();
827
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
828
            }
829
            else
830
            {
831
                this.cbPrint.Items.Add("PDF");
832
                this.cbPrint.Items.Add("IMAGE");
833
834
                this.cbPrint.SelectedItem = "PDF";
835
            }
836
        }
837
        #endregion
838
839
        #region 프린트 실행
840 86bff326 taeseongkim
        public async void Printing()
841 787a4489 KangIngu
        {
842 86bff326 taeseongkim
            await PageChangeAsync(1);
843
844 787a4489 KangIngu
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
845
            {
846 481c3fb9 djkim
                printDocument = new PrintDocument();
847 408e4218 ljiyeon
                printDocument.OriginAtMargins = true;
848 787a4489 KangIngu
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
849
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
850
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
851
            }
852
            else
853
                printDocument = null;
854
855
            #region 인쇄 미리보기 테스트
856
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
857
            {
858
                printDocument.PrinterSettings.MinimumPage = 1;
859
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
860
                printDocument.PrinterSettings.FromPage = 1;
861 408e4218 ljiyeon
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
862 787a4489 KangIngu
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
863 481c3fb9 djkim
                printDocument.PrinterSettings.PrinterName = PrintName;
864
                dlg.Document = printDocument;
865 787a4489 KangIngu
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
866
                dlg.ShowDialog();
867
            }
868
            #endregion
869
870
            #region 인쇄
871
            //printDocument.PrinterSettings.MinimumPage = 1;
872
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
873
            //printDocument.PrinterSettings.FromPage = 1;
874
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
875
876
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
877
            //printDocument.PrinterSettings.PrinterName = PrintName;
878
879
            //printDocument.Print();
880
            #endregion
881
        }
882
883
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
884
        {
885
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
886
            // This demo only loads one page at a time, so no need to re-set the print page number
887 481c3fb9 djkim
            PrintDocument document = sender as PrintDocument;
888 787a4489 KangIngu
            currentPage = document.PrinterSettings.FromPage;
889
        }
890 481c3fb9 djkim
891 787a4489 KangIngu
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
892
        {
893
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
894
895
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
896
            {
897
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
898 2024d8d1 ljiyeon
899 481c3fb9 djkim
                if (p_img.Width > p_img.Height)
900 2024d8d1 ljiyeon
                {
901
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
902
                }
903 408e4218 ljiyeon
904
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
905
                System.Drawing.Image pic = p_img;
906 787a4489 KangIngu
                System.Drawing.Rectangle m = e.MarginBounds;
907
908 408e4218 ljiyeon
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
909
                //{
910
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
911
                //}
912
                //else
913
                //{
914
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
915
                //}
916
                m.Width = (int)e.PageSettings.PrintableArea.Width;
917
                m.Height = (int)e.PageSettings.PrintableArea.Height;
918
                m.X = (int)e.PageSettings.HardMarginX;
919
                m.Y = (int)e.PageSettings.HardMarginY;
920
921
                e.Graphics.DrawImage(pic, m);
922 787a4489 KangIngu
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
923
                //e.Graphics.DrawImage(p_img, 0, 0);
924
            }));
925 481c3fb9 djkim
926 787a4489 KangIngu
            //다음 페이지
927
            currentPage++;
928 481c3fb9 djkim
929 787a4489 KangIngu
            ////인쇄를 계속 할지 말지 확인
930
            if (currentPage <= printDocument.PrinterSettings.ToPage)
931
                e.HasMorePages = true;
932
            else
933
                e.HasMorePages = false;
934
935
        }
936
937
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
938
        {
939
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
940
            {
941
                printIndy.IsBusy = false;
942
            }));
943
        }
944
        #endregion
945
946
        #region Selected Pages Check
947
        List<int> PrintPageCreate()
948
        {
949
            List<int> Result = new List<int>();
950
951
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
952
            {
953
                Result.Add(CurrentPageNo);
954
            }
955
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
956
            {
957
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
958
                {
959
                    Result.Add(i);
960
                }
961
            }
962
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
963
            {
964
                int _stPage = (int)stPageNo.Value;
965
                int _edPage = (int)edPageNo.Value;
966
967
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
968
                Result.AddRange(lst);
969
            }
970
            else
971
            {
972
                for (int i = 1; i <= _definePages.PagesCount; i++)
973
                {
974
                    Result.Add(i);
975
                }
976
            }
977
            if (currentPagePrint)
978
            {
979
                return Result;
980
            }
981
982
            if (chkOnlyMarkup.IsChecked.Value)
983
            {
984
                var _result = from result in Result
985
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
986
                              select result;
987
                Result = _result.ToList();
988
            }
989
            return Result;
990
        }
991
        #endregion
992
993
        #endregion
994
    }
995
}
클립보드 이미지 추가 (최대 크기: 500 MB)