markus / KCOM / Controls / PrintControl.xaml.cs.bak @ ffcc8124
이력 | 보기 | 이력해설 | 다운로드 (34.5 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 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 Leadtools.Windows.Controls; |
||
23 | using IKCOM; |
||
24 | //강인구 추가 |
||
25 | namespace KCOM.Control |
||
26 | { |
||
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 | string _DefinedPagesStrings; |
||
35 | /// <summary> |
||
36 | /// 사용자 정의 페이지를 입력시 오류를 방지하기 위해 적용 |
||
37 | /// </summary> |
||
38 | public string DefinedPagesStrings |
||
39 | { |
||
40 | get { return _DefinedPagesStrings; } |
||
41 | set |
||
42 | { |
||
43 | if (string.IsNullOrWhiteSpace(value)) return; |
||
44 | |||
45 | var _definedPages = value.Replace('-', ',').Split(','); |
||
46 | List<char> _NotEx = new List<char>(); |
||
47 | |||
48 | foreach (var item in _definedPages) |
||
49 | { |
||
50 | bool _isNum = true; |
||
51 | |||
52 | foreach (var chr in item) |
||
53 | { |
||
54 | if (!char.IsNumber(chr)) |
||
55 | { |
||
56 | _NotEx.Add(chr); |
||
57 | _isNum = false; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | if (_isNum) |
||
62 | { |
||
63 | if (Convert.ToInt32(item) > PagesCount) |
||
64 | throw new Exception(string.Format("Max Page Number is '{0}'!!.", PagesCount)); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | if (_NotEx.Count() > 0) |
||
69 | { |
||
70 | string _notString = ""; |
||
71 | _NotEx.ForEach(s => _notString += s.ToString()); |
||
72 | throw new Exception(string.Format("'{0}' Can not be added.", _notString)); |
||
73 | } |
||
74 | |||
75 | |||
76 | try |
||
77 | { |
||
78 | |||
79 | string _notString2 = ""; |
||
80 | _NotEx.ForEach(s => _notString2 += s.ToString()); |
||
81 | _DefinedPagesStrings = value; |
||
82 | } |
||
83 | catch (Exception) |
||
84 | { |
||
85 | throw new Exception(string.Format("Can not be added.")); |
||
86 | } |
||
87 | |||
88 | } |
||
89 | } |
||
90 | } |
||
91 | |||
92 | |||
93 | /// <summary> |
||
94 | /// Interaction logic for Print.xaml |
||
95 | /// </summary> |
||
96 | public partial class PrintControl : UserControl |
||
97 | { |
||
98 | #region Data |
||
99 | |||
100 | int OldCount = 0; |
||
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 | RasterImage backimg; //백그라운드 이미지 |
||
131 | RasterImage PrintImg; //프린트 이미지 |
||
132 | RasterCodecs codecs; |
||
133 | int currentPage; |
||
134 | public string PrintName; |
||
135 | public string Type; |
||
136 | |||
137 | public System.Timers.Timer timm = new System.Timers.Timer(); |
||
138 | |||
139 | |||
140 | #endregion |
||
141 | |||
142 | #region Static Property Defines |
||
143 | public static readonly DependencyProperty CurrentPageNoProperty = |
||
144 | DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl), |
||
145 | new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged))); |
||
146 | #endregion |
||
147 | |||
148 | #region Property |
||
149 | public int CurrentPageNo |
||
150 | { |
||
151 | get { return (int)GetValue(CurrentPageNoProperty); } |
||
152 | set { SetValue(CurrentPageNoProperty, value); } |
||
153 | } |
||
154 | #endregion |
||
155 | |||
156 | #region PropertyChangeMethod |
||
157 | private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
||
158 | { |
||
159 | var printPage = (PrintControl)d; |
||
160 | var newValue = (int)e.NewValue; |
||
161 | |||
162 | printPage.sliderPages.Value = newValue; |
||
163 | printPage.SetLoadMakupList(newValue); |
||
164 | |||
165 | } |
||
166 | #endregion |
||
167 | |||
168 | |||
169 | |||
170 | #region 생성자 |
||
171 | //public PrintControl() |
||
172 | //{ |
||
173 | //} |
||
174 | //public PrintControl(LayerControl LayerControl, string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<ServiceInterface.MarkupInfoItem> |
||
175 | // markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint) |
||
176 | public PrintControl(string TileSourceUri, string ProjectNo, DOCINFO DocInfo, List<IKCOM.MarkupInfoItem> markupInfo, int CurrentPageNo, string slip, string title, string fileurl, bool isPrint) |
||
177 | { |
||
178 | InitializeComponent(); |
||
179 | |||
180 | this.IsEnabled = true; |
||
181 | |||
182 | //Layer Control을 통째로 가져와야 하는건가 |
||
183 | //this.LayerControl = LayerControl; |
||
184 | this._DocInfo = DocInfo; |
||
185 | this._DefaultTileUri = TileSourceUri; |
||
186 | this.ProjectNo = ProjectNo; |
||
187 | this._StartPageNo = CurrentPageNo; |
||
188 | |||
189 | markupInfo.ForEach(info => this._markupInfo.Add(info)); |
||
190 | |||
191 | foreach (var info in _markupInfo) |
||
192 | { |
||
193 | if (info.Consolidate == 1) |
||
194 | { |
||
195 | info.UserName = "Consolidation"; |
||
196 | } |
||
197 | info.MarkupList.ForEach(makup => |
||
198 | { |
||
199 | var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber); |
||
200 | var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor }; |
||
201 | |||
202 | if (_pageMarkup.Count() > 0) |
||
203 | _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem); |
||
204 | else |
||
205 | _PageMarkupList.Add(new MarkupPageItem |
||
206 | { |
||
207 | PageNumber = makup.PageNumber, |
||
208 | DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem } |
||
209 | }); |
||
210 | }); |
||
211 | |||
212 | colorList.Add(new DisplayColorInfo |
||
213 | { |
||
214 | UserID = info.UserID, |
||
215 | DisplayColor = info.DisplayColor, |
||
216 | Department = info.Depatment, |
||
217 | UserName = info.UserName, |
||
218 | }); |
||
219 | } |
||
220 | |||
221 | gridViewMarkup.ItemsSource = this._markupInfo; |
||
222 | SetLoadMakupList(this._StartPageNo); |
||
223 | if (_LoadMakupList.Count() == 0) |
||
224 | chkOnlyMarkup.IsChecked = false; |
||
225 | |||
226 | this.CurrentPageNo = _StartPageNo; |
||
227 | _definePages = new DefinedPages { DefinedPagesStrings = "", PagesCount = Convert.ToInt32(this._DocInfo.PAGE_COUNT), vpSlip = slip, vpTitle = title, fileUrl = fileurl }; |
||
228 | DocumentInfo = _definePages; |
||
229 | this.DataContext = _definePages; |
||
230 | |||
231 | CheckCommentPages(); |
||
232 | |||
233 | //초기화면 Comment Check된 상태로 보여주기 |
||
234 | foreach (var item in _markupInfo) |
||
235 | { |
||
236 | gridViewMarkup.SelectedItems.Add(item); |
||
237 | } |
||
238 | PageChanged(_StartPageNo); |
||
239 | |||
240 | |||
241 | sliderPages.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
||
242 | this.stPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
||
243 | this.edPageNo.Maximum = Convert.ToDouble(this._DocInfo.PAGE_COUNT); |
||
244 | this.IsPrint = isPrint; |
||
245 | |||
246 | if (!IsPrint) |
||
247 | { |
||
248 | GetPrint(false); |
||
249 | btnWholeExport.Visibility = Visibility.Visible; |
||
250 | btnWholePrint.Visibility = Visibility.Collapsed; |
||
251 | Selected_Print.Header = "Export Type"; |
||
252 | } |
||
253 | else |
||
254 | { |
||
255 | //PrintList 가져오기 |
||
256 | GetPrint(true); |
||
257 | btnWholePrint.Visibility = Visibility.Visible; |
||
258 | btnWholeExport.Visibility = Visibility.Collapsed; |
||
259 | } |
||
260 | |||
261 | _initializeComponentFinished = true; |
||
262 | |||
263 | //timm.Interval = 10; |
||
264 | //timm.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed); |
||
265 | //timm.Enabled = true; |
||
266 | } |
||
267 | |||
268 | private void _Timer_Elapsed(object sender, ElapsedEventArgs e) |
||
269 | { |
||
270 | timm.Enabled = false; |
||
271 | PageChanged(_StartPageNo); |
||
272 | } |
||
273 | #endregion |
||
274 | |||
275 | #region Control Event |
||
276 | private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
277 | { |
||
278 | if (_initializeComponentFinished) |
||
279 | { |
||
280 | if (!_IsDagSlider) |
||
281 | { |
||
282 | this.CurrentPageNo = (int)this.sliderPages.Value; |
||
283 | PageChanged(this.CurrentPageNo); |
||
284 | //CheckCommentPages(); |
||
285 | } |
||
286 | } |
||
287 | } |
||
288 | |||
289 | private void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e) |
||
290 | { |
||
291 | _IsDagSlider = false; |
||
292 | this.CurrentPageNo = (int)this.sliderPages.Value; |
||
293 | if (_initializeComponentFinished) |
||
294 | { |
||
295 | PageChanged(this.CurrentPageNo); |
||
296 | } |
||
297 | } |
||
298 | |||
299 | private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e) |
||
300 | { |
||
301 | _IsDagSlider = true; |
||
302 | } |
||
303 | |||
304 | private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e) |
||
305 | { |
||
306 | if (_initializeComponentFinished) //GridRangePages |
||
307 | { |
||
308 | CheckCommentPages(); |
||
309 | } |
||
310 | } |
||
311 | |||
312 | private void PageSelect_Checked(object sender, RoutedEventArgs e) |
||
313 | { |
||
314 | if (!_initializeComponentFinished) return; |
||
315 | |||
316 | string _ButtonName = (sender as RadRadioButton).Tag.ToString(); |
||
317 | totalPage_Whole.Text = ""; |
||
318 | CommentPageList.ItemsSource = null; |
||
319 | |||
320 | switch (_ButtonName) |
||
321 | { |
||
322 | case "Current": |
||
323 | stPageNo.Value = CurrentPageNo; |
||
324 | edPageNo.Value = CurrentPageNo; |
||
325 | |||
326 | GridCurrentPage.Visibility = Visibility.Visible; |
||
327 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
328 | GridRangePages.Visibility = Visibility.Collapsed; |
||
329 | GridAllPages.Visibility = Visibility.Collapsed; |
||
330 | |||
331 | break; |
||
332 | case "RangePrint": |
||
333 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
334 | GridDefinePages.Visibility = Visibility.Visible; |
||
335 | GridRangePages.Visibility = Visibility.Collapsed; |
||
336 | GridAllPages.Visibility = Visibility.Collapsed; |
||
337 | break; |
||
338 | case "UserDefined": |
||
339 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
340 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
341 | GridRangePages.Visibility = Visibility.Visible; |
||
342 | GridAllPages.Visibility = Visibility.Collapsed; |
||
343 | break; |
||
344 | case "AllPrint": |
||
345 | stPageNo.Value = 1; |
||
346 | edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT); |
||
347 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
348 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
349 | GridRangePages.Visibility = Visibility.Collapsed; |
||
350 | GridAllPages.Visibility = Visibility.Visible; |
||
351 | break; |
||
352 | } |
||
353 | |||
354 | CheckCommentPages(); |
||
355 | } |
||
356 | |||
357 | private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e) |
||
358 | { |
||
359 | if (_initializeComponentFinished) //GridRangePages |
||
360 | { |
||
361 | if (stPageNo.Value > edPageNo.Value) |
||
362 | { |
||
363 | if (sender.Equals(stPageNo)) |
||
364 | edPageNo.Value = stPageNo.Value; |
||
365 | else |
||
366 | stPageNo.Value = edPageNo.Value; |
||
367 | } |
||
368 | |||
369 | //뷰어잠시제외(강인구) |
||
370 | //this.LayoutRoot.Dispatcher.BeginInvoke(delegate() |
||
371 | //{ |
||
372 | CheckCommentPages(); |
||
373 | //}); |
||
374 | } |
||
375 | } |
||
376 | |||
377 | private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e) |
||
378 | { |
||
379 | CheckCommentPages(); |
||
380 | } |
||
381 | |||
382 | private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e) |
||
383 | { |
||
384 | txtDefinedPages.Text = ""; |
||
385 | } |
||
386 | |||
387 | private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) |
||
388 | { |
||
389 | if (_initializeComponentFinished) |
||
390 | if (CommentPageList.SelectedItem != null) |
||
391 | this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber; |
||
392 | } |
||
393 | |||
394 | private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e) |
||
395 | { |
||
396 | //_PageMarkupList.Clear(); |
||
397 | |||
398 | if (gridViewMarkup.SelectedItems.Count() > 0) |
||
399 | { |
||
400 | //foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>()) |
||
401 | //{ |
||
402 | // info.MarkupList.ForEach(makup => |
||
403 | // { |
||
404 | // var _pageMarkup = _PageMarkupList.Where(item => item.PageNumber == makup.PageNumber); |
||
405 | // var _SetMarkupItem = new SetColorMarkupItem { markupID = makup.ID, DisplayColor = info.DisplayColor }; |
||
406 | |||
407 | // if (_pageMarkup.Count() > 0) |
||
408 | // _pageMarkup.First().DisplayColorItems.Add(_SetMarkupItem); |
||
409 | // else |
||
410 | // _PageMarkupList.Add(new MarkupPageItem |
||
411 | // { |
||
412 | // PageNumber = makup.PageNumber, |
||
413 | // DisplayColorItems = new List<SetColorMarkupItem> { _SetMarkupItem } |
||
414 | // }); |
||
415 | // }); |
||
416 | //} |
||
417 | |||
418 | //SetLoadMakupList(this.CurrentPageNo); |
||
419 | |||
420 | //페이지 보여주는 부분 변경(강인구) |
||
421 | totalPage_Selected.Text = gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>().Sum(p => p.MarkupList.GroupBy(c => c.PageNumber).Count()).ToString(); |
||
422 | } |
||
423 | else |
||
424 | { |
||
425 | totalPage_Selected.Text = "0"; |
||
426 | } |
||
427 | |||
428 | if (_initializeComponentFinished) |
||
429 | { |
||
430 | PageChanged(this.CurrentPageNo); |
||
431 | //CheckCommentPages(); |
||
432 | } |
||
433 | } |
||
434 | |||
435 | #endregion |
||
436 | |||
437 | public void PageChanged(int PageNo) |
||
438 | { |
||
439 | |||
440 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
441 | { |
||
442 | Load load = new Load(); |
||
443 | codecs = new RasterCodecs(); |
||
444 | _viewer = new RasterImageViewer(); |
||
445 | printCanvas.Children.Clear(); |
||
446 | |||
447 | Uri uri = new Uri(_DefaultTileUri + PageNo + ".cmp"); |
||
448 | backimg = codecs.Load(uri); |
||
449 | _viewer.Image = backimg; |
||
450 | |||
451 | printCanvas.Width = backimg.ImageWidth; |
||
452 | printCanvas.Height = backimg.ImageHeight; |
||
453 | printCanvas.Children.Add(_viewer); |
||
454 | |||
455 | foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>()) |
||
456 | { |
||
457 | load.User_Id = info.UserID; |
||
458 | load.document_id = _DocInfo.DOCUMENT_ID; |
||
459 | load.Page_No = PageNo; |
||
460 | load.DisplayColor = info.DisplayColor; |
||
461 | load.Markup_Load(printCanvas); |
||
462 | } |
||
463 | printCanvas.UpdateLayout(); |
||
464 | })); |
||
465 | } |
||
466 | |||
467 | #region Print RasterImage Setting |
||
468 | public System.Drawing.Image RasterImage_Set(int PageNo) |
||
469 | { |
||
470 | System.Drawing.Image cmtimage = RasterImageConverter.ConvertToImage(backimg, ConvertToImageOptions.None); |
||
471 | |||
472 | System.Drawing.Bitmap Resultimg = new System.Drawing.Bitmap(cmtimage, cmtimage.Width, cmtimage.Height); |
||
473 | Resultimg.SetResolution(96, 96); |
||
474 | Size size = new Size((int)printCanvas.Width, (int)printCanvas.Height); |
||
475 | System.Windows.Media.Imaging.BitmapEncoder encoder = new System.Windows.Media.Imaging.PngBitmapEncoder(); |
||
476 | RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32); |
||
477 | renderBitmap.Render(printCanvas); |
||
478 | MemoryStream mystream = new MemoryStream(); |
||
479 | encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); |
||
480 | encoder.Save(mystream); |
||
481 | System.Drawing.Image myImage; |
||
482 | myImage = System.Drawing.Image.FromStream(mystream); |
||
483 | |||
484 | using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(Resultimg)) |
||
485 | { |
||
486 | gr.DrawImage(myImage, new System.Drawing.Point(0, 0)); |
||
487 | } |
||
488 | return Resultimg; |
||
489 | } |
||
490 | #endregion |
||
491 | |||
492 | //Print 버튼 클릭 이벤트 |
||
493 | #region Method - 명령 |
||
494 | void PrintMethod(object sender, RoutedEventArgs e) |
||
495 | { |
||
496 | System.Drawing.Image Resultimg; |
||
497 | |||
498 | if (this.printIndy.IsBusy == true) |
||
499 | return; |
||
500 | |||
501 | System.Threading.Tasks.Task.Factory.StartNew(() => |
||
502 | { |
||
503 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
504 | { |
||
505 | this.printIndy.IsBusy = true; |
||
506 | printIndy.BusyContent = "Printing. . ."; |
||
507 | })); |
||
508 | }); |
||
509 | |||
510 | PrintImg = null; |
||
511 | |||
512 | _lstPrintPageNo = PrintPageCreate(); |
||
513 | |||
514 | if (_lstPrintPageNo.Count == 0) |
||
515 | { |
||
516 | this.printIndy.IsBusy = false; |
||
517 | RadWindow.Alert(new DialogParameters |
||
518 | { |
||
519 | Theme = new VisualStudio2013Theme(), |
||
520 | Header = "안내", |
||
521 | Content = "페이지가 지정되지 않았습니다." |
||
522 | }); |
||
523 | return; |
||
524 | } |
||
525 | int cnt = 0; |
||
526 | List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>(); |
||
527 | |||
528 | |||
529 | foreach (int PageNo in _lstPrintPageNo) |
||
530 | { |
||
531 | PageChanged(PageNo); |
||
532 | //printIndy.BusyContent = "Downloding. . ." + PageNo; |
||
533 | printCanvas.Children.Remove(_viewer); |
||
534 | if (printCanvas.Children.Count > 0) |
||
535 | { |
||
536 | Resultimg = RasterImage_Set(PageNo); |
||
537 | |||
538 | if (PrintImg == null) |
||
539 | { |
||
540 | PrintImg = RasterImageConverter.ConvertFromImage(Resultimg, ConvertFromImageOptions.None); |
||
541 | } |
||
542 | else |
||
543 | { |
||
544 | PrintImg.InsertPage(PrintImg.PageCount + 1, RasterImageConverter.ConvertFromImage(Resultimg, ConvertFromImageOptions.None)); |
||
545 | } |
||
546 | } |
||
547 | else |
||
548 | { |
||
549 | if (PrintImg == null) |
||
550 | { |
||
551 | PrintImg = backimg; |
||
552 | } |
||
553 | else |
||
554 | { |
||
555 | PrintImg.InsertPage(PrintImg.PageCount + 1, backimg); |
||
556 | } |
||
557 | } |
||
558 | cnt++; |
||
559 | } |
||
560 | PrintName = cbPrint.SelectedItem.ToString(); |
||
561 | |||
562 | System.Threading.Tasks.Task.Factory.StartNew(() => |
||
563 | { |
||
564 | |||
565 | if (cnt == _lstPrintPageNo.Count) |
||
566 | { |
||
567 | Printing(); |
||
568 | } |
||
569 | }); |
||
570 | } |
||
571 | //Export 버튼 클릭 이벤트 |
||
572 | void ExportMethod(object sender, RoutedEventArgs e) |
||
573 | { |
||
574 | if (this.printIndy.IsBusy == true) |
||
575 | return; |
||
576 | |||
577 | this.printIndy.IsBusy = true; |
||
578 | printIndy.BusyContent = "Exporting. . ."; |
||
579 | |||
580 | Export export = new Export(); |
||
581 | _lstPrintPageNo = PrintPageCreate(); |
||
582 | |||
583 | if (_lstPrintPageNo.Count == 0) |
||
584 | { |
||
585 | this.printIndy.IsBusy = false; |
||
586 | RadWindow.Alert(new DialogParameters |
||
587 | { |
||
588 | Theme = new VisualStudio2013Theme(), |
||
589 | Header = "안내", |
||
590 | Content = "페이지가 지정되지 않았습니다.", |
||
591 | }); |
||
592 | return; |
||
593 | } |
||
594 | |||
595 | RasterImage ex_image; |
||
596 | var docWriter = new Leadtools.Forms.DocumentWriters.DocumentWriter(); |
||
597 | //string outputFileName = (@"C:\temp\Example_1.pdf"); |
||
598 | codecs = new RasterCodecs(); |
||
599 | |||
600 | switch (cbPrint.SelectedIndex) |
||
601 | { |
||
602 | case (0): |
||
603 | { |
||
604 | SaveDig.Filter = "PDF file format|*.pdf"; |
||
605 | break; |
||
606 | } |
||
607 | case (1): |
||
608 | { |
||
609 | SaveDig.Filter = "DOC fileformat|*.docx"; |
||
610 | break; |
||
611 | } |
||
612 | } |
||
613 | |||
614 | SaveDig.Title = "Save an PDF File"; |
||
615 | SaveDig.ShowDialog(); |
||
616 | |||
617 | if (SaveDig.FileName != "") |
||
618 | { |
||
619 | switch (cbPrint.SelectedIndex) |
||
620 | { |
||
621 | case (0): |
||
622 | { |
||
623 | docWriter.BeginDocument(SaveDig.FileName, Leadtools.Forms.DocumentWriters.DocumentFormat.Pdf); |
||
624 | break; |
||
625 | } |
||
626 | case (1): |
||
627 | { |
||
628 | docWriter.BeginDocument(SaveDig.FileName, Leadtools.Forms.DocumentWriters.DocumentFormat.Docx); |
||
629 | break; |
||
630 | } |
||
631 | } |
||
632 | } |
||
633 | else |
||
634 | { |
||
635 | this.printIndy.IsBusy = false; |
||
636 | return; |
||
637 | } |
||
638 | foreach (int PageNo in _lstPrintPageNo) |
||
639 | { |
||
640 | //강인구 테스트 |
||
641 | Uri uri = new Uri(_DefaultTileUri + PageNo + ".cmp"); |
||
642 | backimg = codecs.Load(uri); |
||
643 | |||
644 | codecs.Options.Save.UseImageDitheringMethod = true; |
||
645 | |||
646 | PageChanged(PageNo); |
||
647 | |||
648 | System.Drawing.Image cmtimage = RasterImageConverter.ConvertToImage(backimg, ConvertToImageOptions.None); |
||
649 | |||
650 | printCanvas.Children.Remove(_viewer); |
||
651 | |||
652 | if (printCanvas.Children.Count > 0) |
||
653 | { |
||
654 | ex_image = export.Exporting(printCanvas, cmtimage); |
||
655 | } |
||
656 | else |
||
657 | { |
||
658 | ex_image = RasterImageConverter.ConvertFromImage(cmtimage, ConvertFromImageOptions.None); |
||
659 | } |
||
660 | var rasterPage = new Leadtools.Forms.DocumentWriters.DocumentRasterPage(); |
||
661 | rasterPage.Image = ex_image; |
||
662 | docWriter.AddPage(rasterPage); |
||
663 | |||
664 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
665 | { |
||
666 | printIndy.BusyContent = "Exporting. . . " + currentPage + "/" + PageNo; |
||
667 | })); |
||
668 | } |
||
669 | |||
670 | docWriter.EndDocument(); |
||
671 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
672 | { |
||
673 | printIndy.IsBusy = false; |
||
674 | })); |
||
675 | PageChanged(_StartPageNo); |
||
676 | MessageBox.Show("Success"); |
||
677 | } |
||
678 | |||
679 | #endregion |
||
680 | |||
681 | #region Method - 처리 |
||
682 | void CheckCommentPages() |
||
683 | { |
||
684 | List<MarkupPageItem> _pages = new List<MarkupPageItem>(); |
||
685 | DoubleCollection _Ticks = new DoubleCollection(); |
||
686 | |||
687 | |||
688 | if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible) |
||
689 | { |
||
690 | |||
691 | _pages = (from commPage in this._PageMarkupList |
||
692 | where commPage.PageNumber == CurrentPageNo |
||
693 | orderby commPage.PageNumber |
||
694 | select commPage).ToList(); |
||
695 | |||
696 | if (chkOnlyMarkup.IsChecked == true) |
||
697 | { |
||
698 | totalPage_Whole.Text = _pages.Count().ToString(); |
||
699 | } |
||
700 | else |
||
701 | { |
||
702 | totalPage_Whole.Text = "1"; |
||
703 | } |
||
704 | } |
||
705 | else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
||
706 | { |
||
707 | stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
||
708 | edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
||
709 | |||
710 | int _stPage = (int)stPageNo.Value; |
||
711 | int _edPage = (int)edPageNo.Value; |
||
712 | |||
713 | _pages = (from commPage in this._PageMarkupList |
||
714 | where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage |
||
715 | orderby commPage.PageNumber |
||
716 | select commPage).ToList(); |
||
717 | |||
718 | if (chkOnlyMarkup.IsChecked == true) |
||
719 | { |
||
720 | totalPage_Whole.Text = _pages.Count().ToString(); |
||
721 | } |
||
722 | else |
||
723 | { |
||
724 | if (_stPage == _edPage) |
||
725 | { |
||
726 | totalPage_Whole.Text = "1"; |
||
727 | } |
||
728 | else |
||
729 | { |
||
730 | totalPage_Whole.Text = ((_edPage - _stPage) + 1).ToString(); |
||
731 | } |
||
732 | } |
||
733 | } |
||
734 | |||
735 | |||
736 | |||
737 | else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
||
738 | { |
||
739 | stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
||
740 | edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
||
741 | |||
742 | int _stPage = (int)stPageNo.Value; |
||
743 | int _edPage = (int)edPageNo.Value; |
||
744 | |||
745 | //Using DeepView.Common.RangeParser |
||
746 | var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
||
747 | _pages = (from commPage in this._PageMarkupList |
||
748 | from compareData in lst |
||
749 | where commPage.PageNumber == compareData |
||
750 | orderby commPage.PageNumber |
||
751 | select commPage).ToList(); |
||
752 | |||
753 | if (chkOnlyMarkup.IsChecked == true) |
||
754 | { |
||
755 | totalPage_Whole.Text = _pages.Count().ToString(); |
||
756 | } |
||
757 | else |
||
758 | { |
||
759 | totalPage_Whole.Text = lst.Count().ToString(); |
||
760 | } |
||
761 | } |
||
762 | else |
||
763 | { |
||
764 | _pages = (from commPage in this._PageMarkupList |
||
765 | orderby commPage.PageNumber |
||
766 | select commPage).ToList(); |
||
767 | |||
768 | if (chkOnlyMarkup.IsChecked == true) |
||
769 | { |
||
770 | totalPage_Whole.Text = _pages.Count().ToString(); |
||
771 | |||
772 | } |
||
773 | else |
||
774 | { |
||
775 | totalPage_Whole.Text = _definePages.PagesCount.ToString(); |
||
776 | } |
||
777 | } |
||
778 | CommentPageList.ItemsSource = _pages.ToList(); |
||
779 | } |
||
780 | |||
781 | void SetLoadMakupList(int PageNo) |
||
782 | { |
||
783 | _LoadMakupList.Clear(); |
||
784 | var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo); |
||
785 | |||
786 | if (_markupList.Count() > 0) |
||
787 | _LoadMakupList = _markupList.First().DisplayColorItems.ToList(); |
||
788 | } |
||
789 | |||
790 | #region 프린트 리스트 가져오기 |
||
791 | public void GetPrint(bool flag) |
||
792 | { |
||
793 | if (flag) |
||
794 | { |
||
795 | foreach (string printer in PrinterSettings.InstalledPrinters) |
||
796 | { |
||
797 | this.cbPrint.Items.Add(printer); |
||
798 | } |
||
799 | printDocument = new PrintDocument(); |
||
800 | this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName; |
||
801 | } |
||
802 | else |
||
803 | { |
||
804 | this.cbPrint.Items.Add("PDF"); |
||
805 | this.cbPrint.Items.Add("DOC"); |
||
806 | |||
807 | this.cbPrint.SelectedItem = "PDF"; |
||
808 | } |
||
809 | } |
||
810 | #endregion |
||
811 | |||
812 | #region 프린트 실행 |
||
813 | public void Printing() |
||
814 | { |
||
815 | PageChanged(1); |
||
816 | if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) |
||
817 | { |
||
818 | printDocument = new PrintDocument(); |
||
819 | printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint); |
||
820 | printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage); |
||
821 | printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint); |
||
822 | } |
||
823 | else |
||
824 | printDocument = null; |
||
825 | |||
826 | #region 인쇄 미리보기 테스트 |
||
827 | using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog()) |
||
828 | { |
||
829 | printDocument.PrinterSettings.MinimumPage = 1; |
||
830 | printDocument.PrinterSettings.MaximumPage = PrintImg.PageCount; |
||
831 | printDocument.PrinterSettings.FromPage = 1; |
||
832 | printDocument.PrinterSettings.ToPage = PrintImg.PageCount; |
||
833 | |||
834 | printDocument.PrinterSettings.PrinterName = PrintName; |
||
835 | |||
836 | dlg.Document = printDocument; |
||
837 | dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized; |
||
838 | dlg.ShowDialog(); |
||
839 | } |
||
840 | #endregion |
||
841 | |||
842 | #region 인쇄 |
||
843 | //printDocument.PrinterSettings.MinimumPage = 1; |
||
844 | //printDocument.PrinterSettings.MaximumPage = PrintImg.PageCount; |
||
845 | //printDocument.PrinterSettings.FromPage = 1; |
||
846 | //printDocument.PrinterSettings.ToPage = PrintImg.PageCount; |
||
847 | //printDocument.Print(); |
||
848 | #endregion |
||
849 | } |
||
850 | |||
851 | private void printDocument_BeginPrint(object sender, PrintEventArgs e) |
||
852 | { |
||
853 | // This demo only loads one page at a time, so no need to re-set the print page number |
||
854 | PrintDocument document = sender as PrintDocument; |
||
855 | currentPage = document.PrinterSettings.FromPage; |
||
856 | } |
||
857 | |||
858 | private void printDocument_PrintPage(object sender, PrintPageEventArgs e) |
||
859 | { |
||
860 | PrintDocument document = sender as PrintDocument; |
||
861 | RasterImagePrinter printer = new RasterImagePrinter(); |
||
862 | printer.PrintDocument = document; |
||
863 | |||
864 | printer.SizeMode = RasterPaintSizeMode.FitAlways; |
||
865 | printer.HorizontalAlignMode = RasterPaintAlignMode.Center; |
||
866 | printer.VerticalAlignMode = RasterPaintAlignMode.Center; |
||
867 | printer.UseDpi = true; |
||
868 | |||
869 | printer.ImageRectangle = System.Drawing.Rectangle.Empty; |
||
870 | printer.PageRectangle = System.Drawing.RectangleF.Empty; |
||
871 | |||
872 | printer.UseMargins = false; |
||
873 | |||
874 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
875 | { |
||
876 | printIndy.BusyContent = printIndy.BusyContent = "Printing. . . " + currentPage + "/" + PrintImg.PageCount; |
||
877 | })); |
||
878 | |||
879 | //현재 페이지 인쇄 |
||
880 | printer.Print(PrintImg, currentPage, e); |
||
881 | |||
882 | //다음 페이지 |
||
883 | currentPage++; |
||
884 | |||
885 | //인쇄를 계속 할지 말지 확인 |
||
886 | if (currentPage <= printDocument.PrinterSettings.ToPage) |
||
887 | e.HasMorePages = true; |
||
888 | else |
||
889 | e.HasMorePages = false; |
||
890 | |||
891 | printer.PrintDocument = null; |
||
892 | } |
||
893 | |||
894 | private void printDocument_EndPrint(object sender, PrintEventArgs e) |
||
895 | { |
||
896 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
897 | { |
||
898 | printIndy.IsBusy = false; |
||
899 | })); |
||
900 | } |
||
901 | #endregion |
||
902 | |||
903 | #region Selected Pages Check |
||
904 | List<int> PrintPageCreate() |
||
905 | { |
||
906 | List<int> Result = new List<int>(); |
||
907 | |||
908 | if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint) |
||
909 | { |
||
910 | Result.Add(CurrentPageNo); |
||
911 | } |
||
912 | else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
||
913 | { |
||
914 | for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++) |
||
915 | { |
||
916 | Result.Add(i); |
||
917 | } |
||
918 | } |
||
919 | else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
||
920 | { |
||
921 | int _stPage = (int)stPageNo.Value; |
||
922 | int _edPage = (int)edPageNo.Value; |
||
923 | |||
924 | var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
||
925 | Result.AddRange(lst); |
||
926 | } |
||
927 | else |
||
928 | { |
||
929 | for (int i = 1; i <= _definePages.PagesCount; i++) |
||
930 | { |
||
931 | Result.Add(i); |
||
932 | } |
||
933 | } |
||
934 | if (currentPagePrint) |
||
935 | { |
||
936 | return Result; |
||
937 | } |
||
938 | |||
939 | if (chkOnlyMarkup.IsChecked.Value) |
||
940 | { |
||
941 | var _result = from result in Result |
||
942 | where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0 |
||
943 | select result; |
||
944 | Result = _result.ToList(); |
||
945 | } |
||
946 | return Result; |
||
947 | } |
||
948 | #endregion |
||
949 | |||
950 | #endregion |
||
951 | } |
||
952 | } |