프로젝트

일반

사용자정보

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

markus / KCOM / Controls / PrintControl.xaml.cs @ 1e901a8d

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

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