프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 787a4489

이력 | 보기 | 이력해설 | 다운로드 (35.3 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
            totalPage_Whole.Text = "";
324
            CommentPageList.ItemsSource = null;
325

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

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

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

    
360
            CheckCommentPages();
361
        }
362

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

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

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

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

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

    
400
        private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e)
401
        {
402
            //_PageMarkupList.Clear();
403

    
404
            if (gridViewMarkup.SelectedItems.Count() > 0)
405
            {
406
                //foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
407
                //{
408
                //    info.MarkupList.ForEach(makup =>
409
                //    {
410
                //        var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber);
411
                //        var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor };
412

    
413
                //        if (_pageMarkup.Count() > 0)
414
                //            _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem);
415
                //        else
416
                //            _PageMarkupList.Add(new MarkupPageItem
417
                //            {
418
                //                PageNumber = makup.PageNumber,
419
                //                DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem }
420
                //            });
421
                //    });
422
                //}
423

    
424
                //SetLoadMakupList(this.CurrentPageNo);
425

    
426
                //페이지 보여주는 부분 변경(강인구)
427
                totalPage_Selected.Text = gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>().Sum(p => p.MarkupList.GroupBy(c => c.PageNumber).Count()).ToString();
428
            }
429
            else
430
            {
431
                totalPage_Selected.Text = "0";
432
            }
433

    
434
            if (_initializeComponentFinished)
435
            {
436
                PageChanged(this.CurrentPageNo);
437
                //CheckCommentPages();
438
            }
439
        }
440

    
441
        #endregion
442

    
443
        public void PageChanged(int PageNo, bool Flag = false)
444
        {
445
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
446
            {
447
                Load load = new Load();
448
                
449
                _definePages.Back_Image = new ImageBrush();
450
                var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
451

    
452
                printCanvas.Children.Clear();
453

    
454
                ImageBrush background = new ImageBrush(defaultBitmapImage);
455
                printCanvas.Background = background;
456

    
457
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png"));
458
                printCanvas.Width = image.Width;
459
                printCanvas.Height = image.Height;
460

    
461
                foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
462
                {
463
                    load.User_Id = info.UserID;
464
                    load.document_id = _DocInfo.DOCUMENT_ID;
465
                    load.Page_No = PageNo;
466
                    load.DisplayColor = info.DisplayColor;
467
                    load.Markupinfoid = info.MarkupInfoID;
468
                    load.Markup_Load(printCanvas);
469
                }
470

    
471
                printCanvas.UpdateLayout();
472

    
473
                if(Flag)
474
                {
475
                    MemoryStream ms = new MemoryStream();
476
                    BmpBitmapEncoder bbe = new BmpBitmapEncoder();
477
                    bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
478
                    bbe.Save(ms);
479

    
480
                    Printimg = System.Drawing.Image.FromStream(ms);
481
                    Export export = new Export();
482
                    p_img = export.Exporting(printCanvas, Printimg);
483
                    Printimg_List.Add(Printimg_List.Count() + 1, p_img);
484
                }
485
            }));
486
        }
487

    
488
        //Print 버튼 클릭 이벤트
489
        #region Method - 명령
490
        void PrintMethod(object sender, RoutedEventArgs e)
491
        {
492

    
493
            if (this.printIndy.IsBusy == true)
494
                return;
495

    
496
            System.Threading.Tasks.Task.Factory.StartNew(() =>
497
            {
498
                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
499
                {
500
                    this.printIndy.IsBusy = true;
501
                    printIndy.BusyContent = "Printing. . .";
502
                }));
503
            });
504

    
505

    
506
            _lstPrintPageNo = PrintPageCreate();
507

    
508
            if (_lstPrintPageNo.Count == 0)
509
            {
510
                RadWindow.Alert(new DialogParameters
511
                {
512
                    Theme = new VisualStudio2013Theme(),
513
                    Header = "안내",
514
                    Content = "페이지가 지정되지 않았습니다."
515
                });
516
                this.printIndy.IsBusy = false;
517
                return;
518
            }
519
            int cnt = 0;
520
            List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
521

    
522
            Printimg_List = new Dictionary<int, System.Drawing.Image>();
523

    
524
            foreach (int PageNo in _lstPrintPageNo)
525
            {
526
                cnt++;
527
                sliderPages.Value = PageNo;
528
                PageChanged(PageNo, true);
529
                //PageChanged(cnt, true);
530
            }
531
            PrintName = cbPrint.SelectedItem.ToString();
532

    
533
            System.Threading.Tasks.Task.Factory.StartNew(() =>
534
            {
535
                if (cnt == _lstPrintPageNo.Count)
536
                {
537
                    Printing();
538
                }
539
            });
540
        }
541

    
542
        //Export 버튼 클릭 이벤트
543
        void ExportMethod(object sender, RoutedEventArgs e)
544
        {
545
            if (this.printIndy.IsBusy == true)
546
                return;
547

    
548
            this.printIndy.IsBusy = true;
549
            printIndy.BusyContent = "Exporting. . .";
550

    
551
            Export export = new Export();
552
            _lstPrintPageNo = PrintPageCreate();
553

    
554
            if (_lstPrintPageNo.Count == 0)
555
            {
556
                this.printIndy.IsBusy = false;
557
                RadWindow.Alert(new DialogParameters
558
                {
559
                    Theme = new VisualStudio2013Theme(),
560
                    Header = "안내",
561
                    Content = "페이지가 지정되지 않았습니다.",
562
                });
563
                return;
564
            }
565

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

    
568
            switch (cbPrint.SelectedIndex)
569
            {
570
                case (0):
571
                    {
572
                        SaveDig.Filter = "PDF file format|*.pdf";
573
                        break;
574
                    }
575
                case (1):
576
                    {
577
                        SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png";
578
                        break;
579
                    }
580
            }
581

    
582
            SaveDig.Title = "Save an PDF File";
583
            SaveDig.ShowDialog();
584
            Printimg_List = new Dictionary<int, System.Drawing.Image>();
585

    
586
            foreach (int PageNo in _lstPrintPageNo)
587
            {
588
                sliderPages.Value = PageNo;
589
                PageChanged(PageNo, true);
590
            }
591

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

    
594
            if (SaveDig.FileName != "")
595
            {
596
                switch (cbPrint.SelectedIndex)
597
                {
598
                    case (0):
599
                        {
600
                            using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
601
                            {
602
                                using (Document doc = new Document())
603
                                {
604
                                    using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
605
                                    {
606
                                        doc.Open();
607
                                        foreach (var item in Printimg_List)
608
                                        {
609
                                            Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
610
                                            Export_img.SetAbsolutePosition(0, 0);
611

    
612
                                            Export_img.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height);
613

    
614
                                            doc.NewPage();
615
                                            doc.Add(Export_img);
616
                                        }
617
                                        doc.Close();
618
                                    }
619
                                }
620
                            }
621
                            break;
622
                        }
623
                    case (1):
624
                        {
625
                            foreach (var item in Printimg_List)
626
                            {
627
                                switch(SaveDig.FilterIndex)
628
                                {
629
                                    case (1):
630
                                        {
631
                                            //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
632
                                            (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
633
                                        }
634
                                        break;
635
                                    case (2):
636
                                        {
637
                                            //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
638
                                            (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
639
                                        }
640
                                        break;
641
                                }
642
                            }
643
                            break;
644
                        }
645
                }
646
            }
647
            else
648
            {
649
                this.printIndy.IsBusy = false;
650
                return;
651
            }
652

    
653
         
654

    
655
            //docWriter.EndDocument();
656
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
657
            {
658
                printIndy.IsBusy = false;
659
            }));
660
            PageChanged(_StartPageNo);
661

    
662
            (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
663
        }
664
        #endregion
665

    
666
        #region Method - 처리
667
        void CheckCommentPages()
668
        {
669
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
670
            DoubleCollection _Ticks = new DoubleCollection();
671

    
672

    
673
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
674
            {
675

    
676
                _pages = (from commPage in this._PageMarkupList
677
                          where commPage.PageNumber == CurrentPageNo
678
                          orderby commPage.PageNumber
679
                          select commPage).ToList();
680

    
681
                if (chkOnlyMarkup.IsChecked == true)
682
                {
683
                    totalPage_Whole.Text = _pages.Count().ToString();
684
                }
685
                else
686
                {
687
                    totalPage_Whole.Text = "1";
688
                }
689
            }
690
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
691
            {
692
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
693
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
694

    
695
                int _stPage = (int)stPageNo.Value;
696
                int _edPage = (int)edPageNo.Value;
697

    
698
                _pages = (from commPage in this._PageMarkupList
699
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
700
                          orderby commPage.PageNumber
701
                          select commPage).ToList();
702

    
703
                if (chkOnlyMarkup.IsChecked == true)
704
                {
705
                    totalPage_Whole.Text = _pages.Count().ToString();
706
                }
707
                else
708
                {
709
                    if (_stPage == _edPage)
710
                    {
711
                        totalPage_Whole.Text = "1";
712
                    }
713
                    else
714
                    {
715
                        totalPage_Whole.Text = ((_edPage - _stPage) + 1).ToString();
716
                    }
717
                }
718
            }
719

    
720

    
721

    
722
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
723
            {
724
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
725
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
726

    
727
                int _stPage = (int)stPageNo.Value;
728
                int _edPage = (int)edPageNo.Value;
729

    
730
                //Using DeepView.Common.RangeParser
731
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
732
                _pages = (from commPage in this._PageMarkupList
733
                          from compareData in lst
734
                          where commPage.PageNumber == compareData
735
                          orderby commPage.PageNumber
736
                          select commPage).ToList();
737

    
738
                if (chkOnlyMarkup.IsChecked == true)
739
                {
740
                    totalPage_Whole.Text = _pages.Count().ToString();
741
                }
742
                else
743
                {
744
                    totalPage_Whole.Text = lst.Count().ToString();
745
                }
746
            }
747
            else
748
            {
749
                _pages = (from commPage in this._PageMarkupList
750
                          orderby commPage.PageNumber
751
                          select commPage).ToList();
752

    
753
                if (chkOnlyMarkup.IsChecked == true)
754
                {
755
                    totalPage_Whole.Text = _pages.Count().ToString();
756

    
757
                }
758
                else
759
                {
760
                    totalPage_Whole.Text = _definePages.PagesCount.ToString();
761
                }
762
            }
763
            CommentPageList.ItemsSource = _pages.ToList();
764
        }
765

    
766
        void SetLoadMakupList(int PageNo)
767
        {
768
            _LoadMakupList.Clear();
769
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
770

    
771
            if (_markupList.Count() > 0)
772
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
773
        }
774

    
775
        #region 프린트 리스트 가져오기
776
        public void GetPrint(bool flag)
777
        {
778
            if (flag)
779
            {
780
                foreach (string printer in PrinterSettings.InstalledPrinters)
781
                {
782
                    this.cbPrint.Items.Add(printer);
783
                }
784
                printDocument = new PrintDocument();
785
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
786
            }
787
            else
788
            {
789
                this.cbPrint.Items.Add("PDF");
790
                this.cbPrint.Items.Add("IMAGE");
791

    
792
                this.cbPrint.SelectedItem = "PDF";
793
            }
794
        }
795
        #endregion
796

    
797
        #region 프린트 실행
798
        public void Printing()
799
        {
800
            PageChanged(1);
801
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
802
            {
803
                printDocument = new PrintDocument();
804
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
805
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
806
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
807
            }
808
            else
809
                printDocument = null;
810

    
811
            #region 인쇄 미리보기 테스트
812
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
813
            {
814
                printDocument.PrinterSettings.MinimumPage = 1;
815
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
816
                printDocument.PrinterSettings.FromPage = 1;
817
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
818

    
819
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
820
                printDocument.PrinterSettings.PrinterName = PrintName;
821

    
822
                dlg.Document = printDocument;
823
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
824
                dlg.ShowDialog();
825
            }
826
            #endregion
827

    
828
            #region 인쇄
829
            //printDocument.PrinterSettings.MinimumPage = 1;
830
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
831
            //printDocument.PrinterSettings.FromPage = 1;
832
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
833

    
834
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
835
            //printDocument.PrinterSettings.PrinterName = PrintName;
836

    
837
            //printDocument.Print();
838
            #endregion
839
        }
840

    
841
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
842
        {
843
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
844
            // This demo only loads one page at a time, so no need to re-set the print page number
845
            PrintDocument document = sender as PrintDocument;
846
            currentPage = document.PrinterSettings.FromPage;
847
        }
848

    
849
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
850
        {
851
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
852

    
853
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
854
            {
855
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
856
                iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
857
                System.Drawing.Rectangle m = e.MarginBounds;
858

    
859
                if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
860
                {
861
                    m.Height = (int)((double)pic.Height / (double)pic.Width * (double)m.Width);
862
                }
863
                else
864
                {
865
                    m.Width = (int)((double)pic.Width / (double)pic.Height * (double)m.Height);
866
                }
867

    
868
                e.Graphics.DrawImage(p_img, m);
869
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
870
                //e.Graphics.DrawImage(p_img, 0, 0);
871

    
872

    
873
            }));
874
            
875
            //다음 페이지
876
            currentPage++;
877
            
878
            ////인쇄를 계속 할지 말지 확인
879
            if (currentPage <= printDocument.PrinterSettings.ToPage)
880
                e.HasMorePages = true;
881
            else
882
                e.HasMorePages = false;
883

    
884
        }
885

    
886
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
887
        {
888
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
889
            {
890
                printIndy.IsBusy = false;
891
            }));
892
        }
893
        #endregion
894

    
895
        #region Selected Pages Check
896
        List<int> PrintPageCreate()
897
        {
898
            List<int> Result = new List<int>();
899

    
900
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
901
            {
902
                Result.Add(CurrentPageNo);
903
            }
904
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
905
            {
906
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
907
                {
908
                    Result.Add(i);
909
                }
910
            }
911
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
912
            {
913
                int _stPage = (int)stPageNo.Value;
914
                int _edPage = (int)edPageNo.Value;
915

    
916
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
917
                Result.AddRange(lst);
918
            }
919
            else
920
            {
921
                for (int i = 1; i <= _definePages.PagesCount; i++)
922
                {
923
                    Result.Add(i);
924
                }
925
            }
926
            if (currentPagePrint)
927
            {
928
                return Result;
929
            }
930

    
931
            if (chkOnlyMarkup.IsChecked.Value)
932
            {
933
                var _result = from result in Result
934
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
935
                              select result;
936
                Result = _result.ToList();
937
            }
938
            return Result;
939
        }
940
        #endregion
941

    
942
        #endregion
943
    }
944
}
클립보드 이미지 추가 (최대 크기: 500 MB)