프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 41e2e4cb

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

1
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 Leadtools.Controls;
15
//using Leadtools.Drawing;
16
//using Leadtools;
17
//using Leadtools.Codecs;
18
using System.IO;
19
using System.Timers;
20
//using IKCOM.Common;
21
using KCOM.Event;
22
using iTextSharp;
23
using iTextSharp.text;
24
//using Leadtools.Windows.Controls;
25
using IKCOM;
26
using iTextSharp.text.pdf;
27
using Microsoft.Office.Core;
28
//강인구 추가
29
namespace KCOM.Control
30
{
31
    //문서 정보 모음 클래스?
32
    public class DefinedPages
33
    {
34
        public int PagesCount { get; set; }
35
        public string vpSlip { get; set; }
36
        public string vpTitle { get; set; }
37
        public string fileUrl { get; set; }
38
        public ImageBrush Back_Image { get; set; }
39

    
40
        string _DefinedPagesStrings;
41
        /// <summary>
42
        /// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용
43
        /// </summary>
44
        public string DefinedPagesStrings
45
        {
46
            get { return _DefinedPagesStrings; }
47
            set
48
            {
49
                if (string.IsNullOrWhiteSpace(value)) return;
50

    
51
                var _definedPages = value.Replace('-', ',').Split(',');
52
                List<char> _NotEx = new List<char>();
53

    
54
                foreach (var item in _definedPages)
55
                {
56
                    bool _isNum = true;
57

    
58
                    foreach (var chr in item)
59
                    {
60
                        if (!char.IsNumber(chr))
61
                        {
62
                            _NotEx.Add(chr);
63
                            _isNum = false;
64
                        }
65
                    }
66

    
67
                    if (_isNum)
68
                    {
69
                        if (Convert.ToInt32(item) > PagesCount)
70
                            throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount));
71
                    }
72
                }
73

    
74
                if (_NotEx.Count() > 0)
75
                {
76
                    string _notString = "";
77
                    _NotEx.ForEach(s => _notString += s.ToString());
78
                    throw new Exception(string.Format("'{0}' Can not be added.", _notString));
79
                }
80

    
81

    
82
                try
83
                {
84

    
85
                    string _notString2 = "";
86
                    _NotEx.ForEach(s => _notString2 += s.ToString());
87
                    _DefinedPagesStrings = value;
88
                }
89
                catch (Exception)
90
                {
91
                    throw new Exception(string.Format("Can not be added."));
92
                }
93

    
94
            }
95
        }
96
    }
97

    
98
    /// <summary>
99
    /// Interaction logic for Print.xaml
100
    /// </summary>
101
    public partial class PrintControl : UserControl
102
    {
103
        #region Data
104

    
105
        string ProjectNo = null; //프로젝트 넘버
106
        string _DefaultTileUri = null; //기본 타일 경로
107
        int _StartPageNo; //시작페이지 
108
        DOCINFO _DocInfo; //문서 정보
109
        //DocInfo _DocInfo; //문서 정보
110
        bool currentPagePrint = false; //현재 페이지 수
111
        int PageCount { get; set; } //총 페이지수 
112
        DefinedPages _definePages = null; //인쇄 설정 범위 지정
113
        public bool IsPrint { get; set; }
114

    
115
        PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성
116

    
117
        //LayerControl LayerControl = null; // 레이어 컨트롤
118
        ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보
119
        List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>();
120
        List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>();
121
        List<int> _lstPrintPageNo = new List<int>();
122

    
123
        System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer();
124
        bool _initializeComponentFinished; //이벤트
125
        bool _IsDagSlider = false; //드래그 상태인가
126
        List<DisplayColorInfo> colorList = new List<DisplayColorInfo>();
127
        DefinedPages DocumentInfo { get; set; } //문서정보 정의        
128
        //PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 
129
        delegate void PrintEventHandler(); //프린트 핸들러
130
        SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그
131
        //SaveFileDialog SaveFile { get; set; } //저장할 때 사용
132

    
133
        //RasterImageViewer _viewer; //이미지 뷰어
134
        System.Windows.Controls.Image backimg; //백그라운드 이미지
135
        System.Drawing.Image Printimg; //프린트 이미지
136
        System.Drawing.Image p_img; //프린트 이미지
137
        iTextSharp.text.Image Export_img;
138
        Dictionary<int,System.Drawing.Image> Printimg_List; //프린트 이미지
139

    
140
        //RasterCodecs codecs;
141
        int currentPage;
142
        public string PrintName;
143
        public string Type;
144

    
145
        public System.Timers.Timer timm = new System.Timers.Timer();
146

    
147

    
148
        #endregion
149

    
150
        #region Static Property Defines
151
        public static readonly DependencyProperty CurrentPageNoProperty =
152
                   DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl),
153
                   new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged)));
154
        #endregion
155

    
156
        #region Property
157
        public int CurrentPageNo
158
        {
159
            get { return (int)GetValue(CurrentPageNoProperty); }
160
            set { SetValue(CurrentPageNoProperty, value); }
161
        }
162
        #endregion
163

    
164
        #region PropertyChangeMethod
165
        private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
166
        {
167
            var printPage = (PrintControl)d;
168
            var newValue = (int)e.NewValue;
169

    
170
            printPage.sliderPages.Value = newValue;
171
            printPage.SetLoadMakupList(newValue);
172

    
173
        }
174
        #endregion
175

    
176
        #region 생성자
177
        //public PrintControl()
178
        //{
179
        //}
180
        //public PrintControl(LayerControl LayerControl, string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<ServiceInterface.MarkupInfoItem>
181
        //                   markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint)
182
        public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint)
183
        {
184
            InitializeComponent();
185

    
186
            this.IsEnabled = true;
187

    
188
            //Layer Control을 통째로 가져와야 하는건가
189
            //this.LayerControl = LayerControl;
190
            this._DocInfo = DocInfo;
191
            this._DefaultTileUri = TileSourceUri;
192
            this.ProjectNo = ProjectNo;
193
            this._StartPageNo = CurrentPageNo;
194

    
195
            markupInfo.ForEach(info => this._markupInfo.Add(info));
196

    
197
            foreach (var info in _markupInfo)
198
            {
199
                if (info.Consolidate == 1)
200
                {
201
                    info.UserName = "Consolidation";
202
                }
203
                info.MarkupList.ForEach(makup =>
204
                {
205
                    var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber);
206
                    var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor };
207

    
208
                    if (_pageMarkup.Count() > 0)
209
                        _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem);
210
                    else
211
                        _PageMarkupList.Add(new MarkupPageItem
212
                        {
213
                            PageNumber = makup.PageNumber,
214
                            DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem }
215
                        });
216
                });
217

    
218
                colorList.Add(new DisplayColorInfo
219
                {
220
                    UserID = info.UserID,
221
                    DisplayColor = info.DisplayColor,
222
                    Department = info.Depatment,
223
                    UserName = info.UserName,
224
                });
225
            }
226

    
227
            gridViewMarkup.ItemsSource = this._markupInfo;
228
            SetLoadMakupList(this._StartPageNo);
229
            if (_LoadMakupList.Count() == 0)
230
                chkOnlyMarkup.IsChecked = false;
231

    
232
            this.CurrentPageNo = _StartPageNo;
233
            _definePages = new DefinedPages { DefinedPagesStrings = "", PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
234
            DocumentInfo = _definePages;
235
            this.DataContext = _definePages;
236

    
237
            CheckCommentPages();
238

    
239
            //초기화면 Comment Check된 상태로 보여주기
240
            foreach (var item in _markupInfo)
241
            {
242
                gridViewMarkup.SelectedItems.Add(item);
243
            }
244
            PageChanged(_StartPageNo);
245

    
246

    
247
            sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
248
            this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
249
            this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
250
            this.IsPrint = isPrint;
251

    
252
            if (!IsPrint)
253
            {
254
                GetPrint(false);
255
                btnWholeExport.Visibility = Visibility.Visible;
256
                btnWholePrint.Visibility = Visibility.Collapsed;
257
                Selected_Print.Header = "Export Type";
258
            }
259
            else
260
            {
261
                //PrintList 가져오기
262
                GetPrint(true);
263
                btnWholePrint.Visibility = Visibility.Visible;
264
                btnWholeExport.Visibility = Visibility.Collapsed;
265
            }
266

    
267
            _initializeComponentFinished = true;
268

    
269
            //timm.Interval = 10;
270
            //timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed);
271
            //timm.Enabled = true;
272
        }
273

    
274
        private void _Timer_Elapsed(object sender, ElapsedEventArgs e)
275
        {
276
            timm.Enabled = false;
277
            PageChanged(_StartPageNo);
278
        }
279
        #endregion
280

    
281
        #region Control Event
282
        private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
283
        {
284
            if (_initializeComponentFinished)
285
            {
286
                if (!_IsDagSlider)
287
                {
288
                    this.CurrentPageNo = (int)this.sliderPages.Value;
289
                    PageChanged(this.CurrentPageNo);
290
                    //CheckCommentPages();
291
                }
292
            }
293
        }
294

    
295
        private void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e)
296
        {
297
            _IsDagSlider = false;
298
            this.CurrentPageNo = (int)this.sliderPages.Value;
299
            if (_initializeComponentFinished)
300
            {
301
                PageChanged(this.CurrentPageNo);
302
            }
303
        }
304

    
305
        private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e)
306
        {
307
            _IsDagSlider = true;
308
        }
309

    
310
        private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e)
311
        {
312
            if (_initializeComponentFinished)      //GridRangePages
313
            {
314
                CheckCommentPages();
315
            }
316
        }
317

    
318
        private void PageSelect_Checked(object sender, RoutedEventArgs e)
319
        {
320
            if (!_initializeComponentFinished) return;
321

    
322
            string _ButtonName = (sender as RadRadioButton).Tag.ToString();
323
            CommentPageList.ItemsSource = null;
324

    
325
            switch (_ButtonName)
326
            {
327
                case "Current":
328
                    stPageNo.Value = CurrentPageNo;
329
                    edPageNo.Value = CurrentPageNo;
330

    
331
                    GridCurrentPage.Visibility = Visibility.Visible;
332
                    GridDefinePages.Visibility = Visibility.Collapsed;
333
                    GridRangePages.Visibility = Visibility.Collapsed;
334
                    GridAllPages.Visibility = Visibility.Collapsed;
335

    
336
                    break;
337
                case "RangePrint":
338
                    GridCurrentPage.Visibility = Visibility.Collapsed;
339
                    GridDefinePages.Visibility = Visibility.Visible;
340
                    GridRangePages.Visibility = Visibility.Collapsed;
341
                    GridAllPages.Visibility = Visibility.Collapsed;
342
                    break;
343
                case "UserDefined":
344
                    GridCurrentPage.Visibility = Visibility.Collapsed;
345
                    GridDefinePages.Visibility = Visibility.Collapsed;
346
                    GridRangePages.Visibility = Visibility.Visible;
347
                    GridAllPages.Visibility = Visibility.Collapsed;
348
                    break;
349
                case "AllPrint":
350
                    stPageNo.Value = 1;
351
                    edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT);
352
                    GridCurrentPage.Visibility = Visibility.Collapsed;
353
                    GridDefinePages.Visibility = Visibility.Collapsed;
354
                    GridRangePages.Visibility = Visibility.Collapsed;
355
                    GridAllPages.Visibility = Visibility.Visible;
356
                    break;
357
            }
358

    
359
            CheckCommentPages();
360
        }
361

    
362
        private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e)
363
        {
364
            if (_initializeComponentFinished)      //GridRangePages
365
            {
366
                if (stPageNo.Value > edPageNo.Value)
367
                {
368
                    if (sender.Equals(stPageNo))
369
                        edPageNo.Value = stPageNo.Value;
370
                    else
371
                        stPageNo.Value = edPageNo.Value;
372
                }
373

    
374
                //뷰어잠시제외(강인구)
375
                //this.LayoutRoot.Dispatcher.BeginInvoke(delegate()
376
                //{
377
                CheckCommentPages();
378
                //});
379
            }
380
        }
381

    
382
        private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e)
383
        {
384
            CheckCommentPages();
385
        }
386

    
387
        private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e)
388
        {
389
            txtDefinedPages.Text = "";
390
        }
391

    
392
        private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
393
        {
394
            if (_initializeComponentFinished)
395
                if (CommentPageList.SelectedItem != null)
396
                    this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber;
397
        }
398

    
399
        private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
400
        {
401
            if (_initializeComponentFinished)
402
            {
403
                PageChanged(this.CurrentPageNo);
404
            }
405
        }
406

    
407
        #endregion
408

    
409
        public void PageChanged(int PageNo, bool Flag = false)
410
        {
411
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
412
            {
413
                Load load = new Load();
414
                
415
                _definePages.Back_Image = new ImageBrush();
416
                var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
417

    
418
                printCanvas.Children.Clear();
419

    
420
                ImageBrush background = new ImageBrush(defaultBitmapImage);
421
                printCanvas.Background = background;
422

    
423
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png"));
424
                printCanvas.Width = image.Width;
425
                printCanvas.Height = image.Height;
426

    
427
                foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
428
                {
429
                    load.User_Id = info.UserID;
430
                    load.document_id = _DocInfo.DOCUMENT_ID;
431
                    load.Page_No = PageNo;
432
                    load.DisplayColor = info.DisplayColor;
433
                    load.Markupinfoid = info.MarkupInfoID;
434
                    load.Markup_Load(printCanvas);
435
                }
436

    
437
                printCanvas.UpdateLayout();
438

    
439
                if(Flag)
440
                {
441
                    MemoryStream ms = new MemoryStream();
442
                    BmpBitmapEncoder bbe = new BmpBitmapEncoder();
443
                    bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
444
                    bbe.Save(ms);
445

    
446
                    Printimg = System.Drawing.Image.FromStream(ms);
447
                    Export export = new Export();
448
                    p_img = export.Exporting(printCanvas, Printimg);
449
                    Printimg_List.Add(Printimg_List.Count() + 1, p_img);
450
                }
451
            }));
452
        }
453

    
454
        //Print 버튼 클릭 이벤트
455
        #region Method - 명령
456
        void PrintMethod(object sender, RoutedEventArgs e)
457
        {
458

    
459
            if (this.printIndy.IsBusy == true)
460
                return;
461

    
462
            System.Threading.Tasks.Task.Factory.StartNew(() =>
463
            {
464
                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
465
                {
466
                    this.printIndy.IsBusy = true;
467
                    printIndy.BusyContent = "Printing. . .";
468
                }));
469
            });
470

    
471

    
472
            _lstPrintPageNo = PrintPageCreate();
473

    
474
            if (_lstPrintPageNo.Count == 0)
475
            {
476
                RadWindow.Alert(new DialogParameters
477
                {
478
                    Theme = new VisualStudio2013Theme(),
479
                    Header = "안내",
480
                    Content = "페이지가 지정되지 않았습니다."
481
                });
482
                this.printIndy.IsBusy = false;
483
                return;
484
            }
485
            int cnt = 0;
486
            List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
487

    
488
            Printimg_List = new Dictionary<int, System.Drawing.Image>();
489

    
490
            foreach (int PageNo in _lstPrintPageNo)
491
            {
492
                cnt++;
493
                sliderPages.Value = PageNo;
494
                PageChanged(PageNo, true);
495
                //PageChanged(cnt, true);
496
            }
497
            PrintName = cbPrint.SelectedItem.ToString();
498

    
499
            System.Threading.Tasks.Task.Factory.StartNew(() =>
500
            {
501
                if (cnt == _lstPrintPageNo.Count)
502
                {
503
                    Printing();
504
                }
505
            });
506
        }
507

    
508
        //Export 버튼 클릭 이벤트
509
        void ExportMethod(object sender, RoutedEventArgs e)
510
        {
511
            if (this.printIndy.IsBusy == true)
512
                return;
513

    
514
            this.printIndy.IsBusy = true;
515
            printIndy.BusyContent = "Exporting. . .";
516

    
517
            Export export = new Export();
518
            _lstPrintPageNo = PrintPageCreate();
519

    
520
            if (_lstPrintPageNo.Count == 0)
521
            {
522
                this.printIndy.IsBusy = false;
523
                RadWindow.Alert(new DialogParameters
524
                {
525
                    Theme = new VisualStudio2013Theme(),
526
                    Header = "안내",
527
                    Content = "페이지가 지정되지 않았습니다.",
528
                });
529
                return;
530
            }
531

    
532
            //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png");
533

    
534
            switch (cbPrint.SelectedIndex)
535
            {
536
                case (0):
537
                    {
538
                        SaveDig.Filter = "PDF file format|*.pdf";
539
                        break;
540
                    }
541
                case (1):
542
                    {
543
                        SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
544
                        break;
545
                    }
546
            }
547

    
548
            SaveDig.Title = "Save an PDF File";
549
            SaveDig.ShowDialog();
550
            Printimg_List = new Dictionary<int, System.Drawing.Image>();
551

    
552
            foreach (int PageNo in _lstPrintPageNo)
553
            {
554
                sliderPages.Value = PageNo;
555
                PageChanged(PageNo, true);
556
            }
557

    
558
            //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
559

    
560
            if (SaveDig.FileName != "")
561
            {
562
                switch (cbPrint.SelectedIndex)
563
                {
564
                    case (0):
565
                        {
566
                            using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
567
                            {
568
                                using (Document doc = new Document())
569
                                {
570
                                    using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
571
                                    {
572
                                        doc.Open();
573
                                        foreach (var item in Printimg_List)
574
                                        {
575
                                            Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
576
                                            Export_img.SetAbsolutePosition(0, 0);
577

    
578
                                            Export_img.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height);
579

    
580
                                            doc.NewPage();
581
                                            doc.Add(Export_img);
582
                                        }
583
                                        doc.Close();
584
                                    }
585
                                }
586
                            }
587
                            break;
588
                        }
589
                    case (1):
590
                        {
591
                            foreach (var item in Printimg_List)
592
                            {
593
                                switch(SaveDig.FilterIndex)
594
                                {
595
                                    case (1):
596
                                        {
597
                                            //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
598
                                            (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
599
                                        }
600
                                        break;
601
                                    case (2):
602
                                        {
603
                                            //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
604
                                            (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
605
                                        }
606
                                        break;
607
                                }
608
                            }
609
                            break;
610
                        }
611
                }
612
            }
613
            else
614
            {
615
                this.printIndy.IsBusy = false;
616
                return;
617
            }
618

    
619
         
620

    
621
            //docWriter.EndDocument();
622
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
623
            {
624
                printIndy.IsBusy = false;
625
            }));
626
            PageChanged(_StartPageNo);
627

    
628
            (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
629
        }
630
        #endregion
631

    
632
        #region Method - 처리
633
        void CheckCommentPages()
634
        {
635
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
636
            DoubleCollection _Ticks = new DoubleCollection();
637

    
638

    
639
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
640
            {
641

    
642
                _pages = (from commPage in this._PageMarkupList
643
                          where commPage.PageNumber == CurrentPageNo
644
                          orderby commPage.PageNumber
645
                          select commPage).ToList();
646
            }
647
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
648
            {
649
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
650
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
651

    
652
                int _stPage = (int)stPageNo.Value;
653
                int _edPage = (int)edPageNo.Value;
654

    
655
                _pages = (from commPage in this._PageMarkupList
656
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
657
                          orderby commPage.PageNumber
658
                          select commPage).ToList();
659
            }
660
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
661
            {
662
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
663
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
664

    
665
                int _stPage = (int)stPageNo.Value;
666
                int _edPage = (int)edPageNo.Value;
667

    
668
                //Using DeepView.Common.RangeParser
669
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
670
                _pages = (from commPage in this._PageMarkupList
671
                          from compareData in lst
672
                          where commPage.PageNumber == compareData
673
                          orderby commPage.PageNumber
674
                          select commPage).ToList();
675
            }
676
            else
677
            {
678
                _pages = (from commPage in this._PageMarkupList
679
                          orderby commPage.PageNumber
680
                          select commPage).ToList();
681
            }
682
            CommentPageList.ItemsSource = _pages.ToList();
683
        }
684

    
685
        void SetLoadMakupList(int PageNo)
686
        {
687
            _LoadMakupList.Clear();
688
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
689

    
690
            if (_markupList.Count() > 0)
691
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
692
        }
693

    
694
        #region 프린트 리스트 가져오기
695
        public void GetPrint(bool flag)
696
        {
697
            if (flag)
698
            {
699
                foreach (string printer in PrinterSettings.InstalledPrinters)
700
                {
701
                    this.cbPrint.Items.Add(printer);
702
                }
703
                printDocument = new PrintDocument();
704
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
705
            }
706
            else
707
            {
708
                this.cbPrint.Items.Add("PDF");
709
                this.cbPrint.Items.Add("IMAGE");
710

    
711
                this.cbPrint.SelectedItem = "PDF";
712
            }
713
        }
714
        #endregion
715

    
716
        #region 프린트 실행
717
        public void Printing()
718
        {
719
            PageChanged(1);
720
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
721
            {
722
                printDocument = new PrintDocument();
723
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
724
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
725
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
726
            }
727
            else
728
                printDocument = null;
729

    
730
            #region 인쇄 미리보기 테스트
731
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
732
            {
733
                printDocument.PrinterSettings.MinimumPage = 1;
734
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
735
                printDocument.PrinterSettings.FromPage = 1;
736
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
737

    
738
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
739
                printDocument.PrinterSettings.PrinterName = PrintName;
740

    
741
                dlg.Document = printDocument;
742
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
743
                dlg.ShowDialog();
744
            }
745
            #endregion
746

    
747
            #region 인쇄
748
            //printDocument.PrinterSettings.MinimumPage = 1;
749
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
750
            //printDocument.PrinterSettings.FromPage = 1;
751
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
752

    
753
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
754
            //printDocument.PrinterSettings.PrinterName = PrintName;
755

    
756
            //printDocument.Print();
757
            #endregion
758
        }
759

    
760
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
761
        {
762
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
763
            // This demo only loads one page at a time, so no need to re-set the print page number
764
            PrintDocument document = sender as PrintDocument;
765
            currentPage = document.PrinterSettings.FromPage;
766
        }
767

    
768
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
769
        {
770
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
771

    
772
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
773
            {
774
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
775
                iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
776
                System.Drawing.Rectangle m = e.MarginBounds;
777

    
778
                if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
779
                {
780
                    m.Height = (int)((double)pic.Height / (double)pic.Width * (double)m.Width);
781
                }
782
                else
783
                {
784
                    m.Width = (int)((double)pic.Width / (double)pic.Height * (double)m.Height);
785
                }
786

    
787
                e.Graphics.DrawImage(p_img, m);
788
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
789
                //e.Graphics.DrawImage(p_img, 0, 0);
790

    
791

    
792
            }));
793
            
794
            //다음 페이지
795
            currentPage++;
796
            
797
            ////인쇄를 계속 할지 말지 확인
798
            if (currentPage <= printDocument.PrinterSettings.ToPage)
799
                e.HasMorePages = true;
800
            else
801
                e.HasMorePages = false;
802

    
803
        }
804

    
805
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
806
        {
807
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
808
            {
809
                printIndy.IsBusy = false;
810
            }));
811
        }
812
        #endregion
813

    
814
        #region Selected Pages Check
815
        List<int> PrintPageCreate()
816
        {
817
            List<int> Result = new List<int>();
818

    
819
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
820
            {
821
                Result.Add(CurrentPageNo);
822
            }
823
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
824
            {
825
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
826
                {
827
                    Result.Add(i);
828
                }
829
            }
830
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
831
            {
832
                int _stPage = (int)stPageNo.Value;
833
                int _edPage = (int)edPageNo.Value;
834

    
835
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
836
                Result.AddRange(lst);
837
            }
838
            else
839
            {
840
                for (int i = 1; i <= _definePages.PagesCount; i++)
841
                {
842
                    Result.Add(i);
843
                }
844
            }
845
            if (currentPagePrint)
846
            {
847
                return Result;
848
            }
849

    
850
            if (chkOnlyMarkup.IsChecked.Value)
851
            {
852
                var _result = from result in Result
853
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
854
                              select result;
855
                Result = _result.ToList();
856
            }
857
            return Result;
858
        }
859
        #endregion
860

    
861
        #endregion
862
    }
863
}
클립보드 이미지 추가 (최대 크기: 500 MB)