프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 77190232

이력 | 보기 | 이력해설 | 다운로드 (36.6 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 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
using System.Net;
25

    
26
namespace KCOM.Control
27
{
28
    public class DefinedPages
29
    {
30
        public int PagesCount { get; set; }
31
        public string vpSlip { get; set; }
32
        public string vpTitle { get; set; }
33
        public string fileUrl { get; set; }
34
        public ImageBrush Back_Image { get; set; }
35

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

    
47
                var _definedPages = value.Replace('-', ',').Split(',');
48
                List<char> _NotEx = new List<char>();
49

    
50
                foreach (var item in _definedPages)
51
                {
52
                    bool _isNum = true;
53

    
54
                    foreach (var chr in item)
55
                    {
56
                        if (!char.IsNumber(chr))
57
                        {
58
                            _NotEx.Add(chr);
59
                            _isNum = false;
60
                        }
61
                    }
62

    
63
                    if (_isNum)
64
                    {
65
                        if (Convert.ToInt32(item) > PagesCount)
66
                            throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount));
67
                    }
68
                }
69

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

    
77

    
78
                try
79
                {
80

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

    
90
            }
91
        }
92
    }
93

    
94
    /// <summary>
95
    /// Interaction logic for Print.xaml
96
    /// </summary>
97
    public partial class PrintControl : UserControl
98
    {
99
        #region Data
100

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

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

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

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

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

    
136
        //RasterCodecs codecs;
137
        int currentPage;
138
        public string PrintName;
139
        public string Type;
140

    
141
        public System.Timers.Timer timm = new System.Timers.Timer();
142

    
143

    
144
        #endregion
145

    
146
        #region Static Property Defines
147
        public static readonly DependencyProperty CurrentPageNoProperty =
148
                   DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl),
149
                   new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged)));
150
        #endregion
151

    
152
        #region Property
153
        public int CurrentPageNo
154
        {
155
            get { return (int)GetValue(CurrentPageNoProperty); }
156
            set { SetValue(CurrentPageNoProperty, value); }
157
        }
158
        #endregion
159

    
160
        #region PropertyChangeMethod
161
        private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
162
        {
163
            var printPage = (PrintControl)d;
164
            var newValue = (int)e.NewValue;
165

    
166
            printPage.sliderPages.Value = newValue;
167
            printPage.SetLoadMakupList(newValue);
168

    
169
        }
170
        #endregion
171

    
172
        #region 생성자
173

    
174
        public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint)
175
        {
176
            InitializeComponent();
177

    
178
            this.IsEnabled = true;
179

    
180
            //Layer Control을 통째로 가져와야 하는건가
181
            this._DocInfo = DocInfo;
182
            this._DefaultTileUri = TileSourceUri;
183
            this.ProjectNo = ProjectNo;
184
            this._StartPageNo = CurrentPageNo;
185

    
186
            markupInfo.ForEach(info => this._markupInfo.Add(info));
187

    
188
            foreach (var info in _markupInfo)
189
            {
190
                if (info.Consolidate == 1)
191
                {
192
                    info.UserName = "Consolidation";
193
                }
194
                info.MarkupList.ForEach(makup =>
195
                {
196
                    var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber);
197
                    var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor };
198

    
199
                    if (_pageMarkup.Count() > 0)
200
                        _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem);
201
                    else
202
                        _PageMarkupList.Add(new MarkupPageItem
203
                        {
204
                            PageNumber = makup.PageNumber,
205
                            DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem }
206
                        });
207
                });
208

    
209
                colorList.Add(new DisplayColorInfo
210
                {
211
                    UserID = info.UserID,
212
                    DisplayColor = info.DisplayColor,
213
                    Department = info.Depatment,
214
                    UserName = info.UserName,
215
                });
216
            }
217

    
218
            gridViewMarkup.ItemsSource = this._markupInfo;
219
            SetLoadMakupList(this._StartPageNo);
220
            if (_LoadMakupList.Count() == 0)
221
                chkOnlyMarkup.IsChecked = false;
222

    
223
            this.CurrentPageNo = _StartPageNo;
224
            _definePages = new DefinedPages { DefinedPagesStrings = "", PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl };
225
            DocumentInfo = _definePages;
226
            this.DataContext = _definePages;
227

    
228
            CheckCommentPages();
229

    
230
            //초기화면 Comment Check된 상태로 보여주기
231
            foreach (var item in _markupInfo)
232
            {
233
                gridViewMarkup.SelectedItems.Add(item);
234
            }
235
            PageChanged(_StartPageNo);
236

    
237

    
238
            sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
239
            this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
240
            this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT);
241
            this.IsPrint = isPrint;
242

    
243
            if (!IsPrint)
244
            {
245
                GetPrint(false);
246
                btnWholeExport.Visibility = Visibility.Visible;
247
                btnWholePrint.Visibility = Visibility.Collapsed;
248
                Selected_Print.Header = "Export Type";
249
            }
250
            else
251
            {
252
                //PrintList 가져오기
253
                GetPrint(true);
254
                btnWholePrint.Visibility = Visibility.Visible;
255
                btnWholeExport.Visibility = Visibility.Collapsed;
256
            }
257

    
258
            _initializeComponentFinished = true;
259

    
260
            //timm.Interval = 10;
261
            //timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed);
262
            //timm.Enabled = true;
263
        }
264

    
265
        private void _Timer_Elapsed(object sender, ElapsedEventArgs e)
266
        {
267
            timm.Enabled = false;
268
            PageChanged(_StartPageNo);
269
        }
270
        #endregion
271

    
272
        #region Control Event
273
        private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
274
        {
275
            if (_initializeComponentFinished)
276
            {
277
                if (!_IsDagSlider)
278
                {
279
                    this.CurrentPageNo = (int)this.sliderPages.Value;
280
                    PageChanged(this.CurrentPageNo);
281

    
282
                    if (_ButtonName == "Current")
283
                    {
284
                        stPageNo.Value = CurrentPageNo;
285
                        edPageNo.Value = CurrentPageNo;
286
                    }
287

    
288
                    //CheckCommentPages();
289
                }
290
            }
291
        }
292

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

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

    
308
        private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e)
309
        {
310
            if (_initializeComponentFinished)      //GridRangePages
311
            {
312
                CheckCommentPages();
313
            }
314
        }
315
        string _ButtonName;
316
        private void PageSelect_Checked(object sender, RoutedEventArgs e)
317
        {
318
            if (!_initializeComponentFinished) return;
319

    
320
            _ButtonName = (sender as RadRadioButton).Tag.ToString();
321
            CommentPageList.ItemsSource = null;
322

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

    
329
                    GridCurrentPage.Visibility = Visibility.Visible;
330
                    GridDefinePages.Visibility = Visibility.Collapsed;
331
                    GridRangePages.Visibility = Visibility.Collapsed;
332
                    GridAllPages.Visibility = Visibility.Collapsed;
333

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

    
357
            CheckCommentPages();
358
        }
359

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

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

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

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

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

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

    
405
        #endregion
406

    
407
        public void PageChanged(int PageNo, bool Flag = false)
408
        {
409
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
410
            {
411
                try
412
                {
413
                    Load load = new Load();
414

    
415
                    _definePages.Back_Image = new ImageBrush();
416
                    //var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png"));
417
                    var buffer = new WebClient().DownloadData(_DefaultTileUri + PageNo + ".png");
418
                    var bitmap = new BitmapImage();
419
                    using (var stream = new MemoryStream(buffer))
420
                    {
421
                        bitmap.BeginInit();
422
                        bitmap.CacheOption = BitmapCacheOption.OnLoad;
423
                        bitmap.StreamSource = stream;
424
                        bitmap.EndInit();
425

    
426
                        printCanvas.Children.Clear();
427

    
428
                        ImageBrush background = new ImageBrush(bitmap);
429
                        printCanvas.Background = background;
430

    
431
                        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png"));
432
                        printCanvas.Width = image.Width;
433
                        printCanvas.Height = image.Height;
434

    
435
                        foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>())
436
                        {
437
                            load.User_Id = info.UserID;
438
                            load.document_id = _DocInfo.DOCUMENT_ID;
439
                            load.Page_No = PageNo;
440
                            load.DisplayColor = info.DisplayColor;
441
                            load.Markupinfoid = info.MarkupInfoID;
442
                            load.Markup_Load(printCanvas);
443
                        }
444

    
445
                        printCanvas.UpdateLayout();
446

    
447
                        if (Flag)
448
                        {
449

    
450
                            //MemoryStream ms = new MemoryStream();
451
                            //BmpBitmapEncoder bbe = new BmpBitmapEncoder();
452
                            //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png")));
453
                            //bbe.Save(ms);
454

    
455
                            //System.Drawing.Image.FromFile()
456
                            Printimg = System.Drawing.Image.FromStream(stream);
457
                            Export export = new Export();
458
                            p_img = export.Exporting(printCanvas, Printimg);
459
                            Printimg_List.Add(Printimg_List.Count() + 1, p_img);
460
                        }
461
                    }
462

    
463
                }
464
                catch (Exception ex)
465
                {
466
                    Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0);
467
                }
468
            }));
469
        }
470
        public static MemoryStream ByteBufferFromImage(BitmapImage imageSource)
471
        {
472
            var ms = new MemoryStream();
473
            var pngEncoder = new PngBitmapEncoder();
474
            pngEncoder.Frames.Add(BitmapFrame.Create(imageSource));
475
            pngEncoder.Save(ms);
476

    
477
            return ms;
478
        }
479
        //Print 버튼 클릭 이벤트
480
        #region Method - 명령
481
        void PrintMethod(object sender, RoutedEventArgs e)
482
        {
483
            try
484
            {
485
                if (this.printIndy.IsBusy == true)
486
                    return;
487

    
488
                System.Threading.Tasks.Task.Factory.StartNew(() =>
489
                {
490
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
491
                    {
492
                        this.printIndy.IsBusy = true;
493
                        printIndy.BusyContent = "Printing. . .";
494
                    }));
495
                });
496

    
497

    
498
                _lstPrintPageNo = PrintPageCreate();
499

    
500
                if (_lstPrintPageNo.Count == 0)
501
                {
502
                    RadWindow.Alert(new DialogParameters
503
                    {
504
                        Owner = Application.Current.MainWindow,
505
                        Theme = new VisualStudio2013Theme(),
506
                        Header = "안내",
507
                        Content = "페이지가 지정되지 않았습니다."
508
                    });
509
                    this.printIndy.IsBusy = false;
510
                    return;
511
                }
512
                int cnt = 0;
513
                List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
514

    
515
                Printimg_List = new Dictionary<int, System.Drawing.Image>();
516

    
517
                foreach (int PageNo in _lstPrintPageNo)
518
                {
519
                    cnt++;
520
                    sliderPages.Value = PageNo;
521
                    PageChanged(PageNo, true);
522
                    //PageChanged(cnt, true);
523
                }
524
                PrintName = cbPrint.SelectedItem.ToString();
525

    
526
                System.Threading.Tasks.Task.Factory.StartNew(() =>
527
                {
528
                    if (cnt == _lstPrintPageNo.Count)
529
                    {
530
                        Printing();
531
                    }
532
                });
533
            }
534
            catch (Exception ex)
535
            {
536
                Logger.sendResLog("PrintMethod", ex.Message, 0);
537
            }
538

    
539
        }
540

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

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

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

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

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

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

    
584
                SaveDig.Title = "Save an PDF File";
585
                if(SaveDig.ShowDialog().Value)
586
                {
587
                    Printimg_List = new Dictionary<int, System.Drawing.Image>();
588

    
589
                    foreach (int PageNo in _lstPrintPageNo)
590
                    {
591
                        sliderPages.Value = PageNo;
592
                        PageChanged(PageNo, true);
593
                    }
594

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

    
597
                    if (SaveDig.FileName != "")
598
                    {
599
                        switch (cbPrint.SelectedIndex)
600
                        {
601
                            case (0):
602
                                {
603
                                    using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
604
                                    {
605
                                        using (Document doc = new Document())
606
                                        {
607
                                            using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
608
                                            {
609
                                                doc.Open();
610
                                                float height = doc.PageSize.Height;
611
                                                float width = doc.PageSize.Width;
612

    
613
                                                foreach (var item in Printimg_List)
614
                                                {
615

    
616
                                                    Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png);
617

    
618

    
619
                                                    if (Export_img.Width > Export_img.Height)
620
                                                    {
621
                                                        doc.SetPageSize(new Rectangle(height, width));
622
                                                        Export_img.ScaleToFit(height, width);
623
                                                    }
624
                                                    else
625
                                                    {
626
                                                        doc.SetPageSize(new Rectangle(width, height));
627
                                                        Export_img.ScaleToFit(width, height);
628
                                                    }
629

    
630
                                                    Export_img.SetAbsolutePosition(0, 0);
631

    
632
                                                    doc.NewPage();
633
                                                    doc.Add(Export_img);
634
                                                }
635
                                                doc.Close();
636
                                            }
637
                                        }
638
                                    }
639
                                    break;
640
                                }
641
                            case (1):
642
                                {
643
                                    foreach (var item in Printimg_List)
644
                                    {
645
                                        switch (SaveDig.FilterIndex)
646
                                        {
647
                                            case (1):
648
                                                {
649
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg);
650
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
651
                                                }
652
                                                break;
653
                                            case (2):
654
                                                {
655
                                                    //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png);
656
                                                    (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png);
657
                                                }
658
                                                break;
659
                                        }
660
                                    }
661
                                    break;
662
                                }
663
                        }
664
                    }
665
                    else
666
                    {
667
                        this.printIndy.IsBusy = false;
668
                        return;
669
                    }
670
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
671
                    {
672
                        printIndy.IsBusy = false;
673
                    }));
674
                    PageChanged(_StartPageNo);
675

    
676
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert");
677
                }else
678
                {
679
                    Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
680
                    {
681
                        printIndy.IsBusy = false;
682
                    }));
683

    
684
                    (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert");
685
                }                
686
            }
687
            catch (Exception ex)
688
            {
689
                Logger.sendResLog("Export Method", ex.Message, 0);
690
                //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message);
691
            }
692

    
693
        }
694
        #endregion
695

    
696
        #region Method - 처리
697
        void CheckCommentPages()
698
        {
699
            List<MarkupPageItem> _pages = new List<MarkupPageItem>();
700
            DoubleCollection _Ticks = new DoubleCollection();
701

    
702

    
703
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible)
704
            {
705

    
706
                _pages = (from commPage in this._PageMarkupList
707
                          where commPage.PageNumber == CurrentPageNo
708
                          orderby commPage.PageNumber
709
                          select commPage).ToList();
710
            }
711
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
712
            {
713
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
714
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
715

    
716
                int _stPage = (int)stPageNo.Value;
717
                int _edPage = (int)edPageNo.Value;
718

    
719
                _pages = (from commPage in this._PageMarkupList
720
                          where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage
721
                          orderby commPage.PageNumber
722
                          select commPage).ToList();
723
            }
724
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
725
            {
726
                stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value;
727
                edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value;
728

    
729
                int _stPage = (int)stPageNo.Value;
730
                int _edPage = (int)edPageNo.Value;
731

    
732
                //Using DeepView.Common.RangeParser
733
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
734
                _pages = (from commPage in this._PageMarkupList
735
                          from compareData in lst
736
                          where commPage.PageNumber == compareData
737
                          orderby commPage.PageNumber
738
                          select commPage).ToList();
739
            }
740
            else
741
            {
742
                _pages = (from commPage in this._PageMarkupList
743
                          orderby commPage.PageNumber
744
                          select commPage).ToList();
745
            }
746
            CommentPageList.ItemsSource = _pages.ToList();
747
        }
748

    
749
        void SetLoadMakupList(int PageNo)
750
        {
751
            _LoadMakupList.Clear();
752
            var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo);
753

    
754
            if (_markupList.Count() > 0)
755
                _LoadMakupList = _markupList.First().DisplayColorItems.ToList();
756
        }
757

    
758
        #region 프린트 리스트 가져오기
759
        public void GetPrint(bool flag)
760
        {
761
            if (flag)
762
            {
763
                foreach (string printer in PrinterSettings.InstalledPrinters)
764
                {
765
                    this.cbPrint.Items.Add(printer);
766
                }
767
                printDocument = new PrintDocument();
768
                this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName;
769
            }
770
            else
771
            {
772
                this.cbPrint.Items.Add("PDF");
773
                this.cbPrint.Items.Add("IMAGE");
774

    
775
                this.cbPrint.SelectedItem = "PDF";
776
            }
777
        }
778
        #endregion
779

    
780
        #region 프린트 실행
781
        public void Printing()
782
        {
783
            PageChanged(1);
784
            if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0)
785
            {
786
                printDocument = new PrintDocument();
787
                printDocument.OriginAtMargins = true;
788
                printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint);
789
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
790
                printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint);
791
            }
792
            else
793
                printDocument = null;
794

    
795
            #region 인쇄 미리보기 테스트
796
            using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog())
797
            {
798
                printDocument.PrinterSettings.MinimumPage = 1;
799
                printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
800
                printDocument.PrinterSettings.FromPage = 1;
801
                printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
802
                printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
803
                printDocument.PrinterSettings.PrinterName = PrintName;
804
                dlg.Document = printDocument;
805
                dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized;
806
                dlg.ShowDialog();
807
            }
808
            #endregion
809

    
810
            #region 인쇄
811
            //printDocument.PrinterSettings.MinimumPage = 1;
812
            //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count();
813
            //printDocument.PrinterSettings.FromPage = 1;
814
            //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count();
815

    
816
            //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
817
            //printDocument.PrinterSettings.PrinterName = PrintName;
818

    
819
            //printDocument.Print();
820
            #endregion
821
        }
822

    
823
        private void printDocument_BeginPrint(object sender, PrintEventArgs e)
824
        {
825
            //Printimg_List = new Dictionary<int, System.Drawing.Image>();
826
            // This demo only loads one page at a time, so no need to re-set the print page number
827
            PrintDocument document = sender as PrintDocument;
828
            currentPage = document.PrinterSettings.FromPage;
829
        }
830

    
831
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
832
        {
833
            //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0);
834

    
835
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
836
            {
837
                p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value;
838

    
839
                if (p_img.Width > p_img.Height)
840
                {
841
                    p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
842
                }
843

    
844
                //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg);
845
                System.Drawing.Image pic = p_img;
846
                System.Drawing.Rectangle m = e.MarginBounds;
847

    
848
                //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider
849
                //{
850
                //    m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16;
851
                //}
852
                //else
853
                //{
854
                //    m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16;
855
                //}
856
                m.Width = (int)e.PageSettings.PrintableArea.Width;
857
                m.Height = (int)e.PageSettings.PrintableArea.Height;
858
                m.X = (int)e.PageSettings.HardMarginX;
859
                m.Y = (int)e.PageSettings.HardMarginY;
860

    
861
                e.Graphics.DrawImage(pic, m);
862
                //e.Graphics.DrawImage(p_img, e.MarginBounds);
863
                //e.Graphics.DrawImage(p_img, 0, 0);
864
            }));
865

    
866
            //다음 페이지
867
            currentPage++;
868

    
869
            ////인쇄를 계속 할지 말지 확인
870
            if (currentPage <= printDocument.PrinterSettings.ToPage)
871
                e.HasMorePages = true;
872
            else
873
                e.HasMorePages = false;
874

    
875
        }
876

    
877
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
878
        {
879
            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
880
            {
881
                printIndy.IsBusy = false;
882
            }));
883
        }
884
        #endregion
885

    
886
        #region Selected Pages Check
887
        List<int> PrintPageCreate()
888
        {
889
            List<int> Result = new List<int>();
890

    
891
            if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint)
892
            {
893
                Result.Add(CurrentPageNo);
894
            }
895
            else if (GridRangePages.Visibility == System.Windows.Visibility.Visible)
896
            {
897
                for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++)
898
                {
899
                    Result.Add(i);
900
                }
901
            }
902
            else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible)
903
            {
904
                int _stPage = (int)stPageNo.Value;
905
                int _edPage = (int)edPageNo.Value;
906

    
907
                var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount);
908
                Result.AddRange(lst);
909
            }
910
            else
911
            {
912
                for (int i = 1; i <= _definePages.PagesCount; i++)
913
                {
914
                    Result.Add(i);
915
                }
916
            }
917
            if (currentPagePrint)
918
            {
919
                return Result;
920
            }
921

    
922
            if (chkOnlyMarkup.IsChecked.Value)
923
            {
924
                var _result = from result in Result
925
                              where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0
926
                              select result;
927
                Result = _result.ToList();
928
            }
929
            return Result;
930
        }
931
        #endregion
932

    
933
        #endregion
934
    }
935
}
클립보드 이미지 추가 (최대 크기: 500 MB)