markus / KCOM / Controls / PrintControl.xaml.cs @ 0b75c341
이력 | 보기 | 이력해설 | 다운로드 (37.4 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 | e3a15e22 | djkim | |
26 | 787a4489 | KangIngu | 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 | 0b75c341 | taeseongkim | private List<PemssService.Requirement> requirementList = new List<PemssService.Requirement>(); |
112 | |||
113 | 787a4489 | KangIngu | PrintDocument printDocument = new PrintDocument(); //프린터도큐먼트 생성 |
114 | |||
115 | //LayerControl LayerControl = null; // 레이어 컨트롤 |
||
116 | ObservableCollection<IKCOM.MarkupInfoItem> _markupInfo = new ObservableCollection<IKCOM.MarkupInfoItem>(); //마크업 정보 |
||
117 | List<MarkupPageItem> _PageMarkupList = new List<MarkupPageItem>(); |
||
118 | List<SetColorMarkupItem> _LoadMakupList = new List<SetColorMarkupItem>(); |
||
119 | List<int> _lstPrintPageNo = new List<int>(); |
||
120 | |||
121 | System.Windows.Threading.DispatcherTimer tm = new System.Windows.Threading.DispatcherTimer(); |
||
122 | bool _initializeComponentFinished; //이벤트 |
||
123 | bool _IsDagSlider = false; //드래그 상태인가 |
||
124 | List<DisplayColorInfo> colorList = new List<DisplayColorInfo>(); |
||
125 | DefinedPages DocumentInfo { get; set; } //문서정보 정의 |
||
126 | //PdfSharp.Pdf.PdfDocument document { get; set; } // pdfsharp 인데 아직 왜 넣었는지 모름 |
||
127 | delegate void PrintEventHandler(); //프린트 핸들러 |
||
128 | SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그 |
||
129 | //SaveFileDialog SaveFile { get; set; } //저장할 때 사용 |
||
130 | |||
131 | //RasterImageViewer _viewer; //이미지 뷰어 |
||
132 | 53880c83 | ljiyeon | //System.Windows.Controls.Image backimg; //백그라운드 이미지 |
133 | 787a4489 | KangIngu | System.Drawing.Image Printimg; //프린트 이미지 |
134 | System.Drawing.Image p_img; //프린트 이미지 |
||
135 | iTextSharp.text.Image Export_img; |
||
136 | 481c3fb9 | djkim | Dictionary<int, System.Drawing.Image> Printimg_List; //프린트 이미지 |
137 | 787a4489 | KangIngu | |
138 | //RasterCodecs codecs; |
||
139 | int currentPage; |
||
140 | public string PrintName; |
||
141 | public string Type; |
||
142 | |||
143 | public System.Timers.Timer timm = new System.Timers.Timer(); |
||
144 | |||
145 | |||
146 | #endregion |
||
147 | |||
148 | #region Static Property Defines |
||
149 | public static readonly DependencyProperty CurrentPageNoProperty = |
||
150 | DependencyProperty.Register("CurrentPageNo", typeof(int), typeof(PrintControl), |
||
151 | new PropertyMetadata(new PropertyChangedCallback(CurrentPageNoPropertyChanged))); |
||
152 | #endregion |
||
153 | |||
154 | #region Property |
||
155 | public int CurrentPageNo |
||
156 | { |
||
157 | get { return (int)GetValue(CurrentPageNoProperty); } |
||
158 | set { SetValue(CurrentPageNoProperty, value); } |
||
159 | } |
||
160 | #endregion |
||
161 | |||
162 | #region PropertyChangeMethod |
||
163 | private static void CurrentPageNoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
||
164 | { |
||
165 | var printPage = (PrintControl)d; |
||
166 | var newValue = (int)e.NewValue; |
||
167 | |||
168 | printPage.sliderPages.Value = newValue; |
||
169 | printPage.SetLoadMakupList(newValue); |
||
170 | |||
171 | } |
||
172 | #endregion |
||
173 | |||
174 | #region 생성자 |
||
175 | 481c3fb9 | djkim | |
176 | 787a4489 | KangIngu | 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 | 481c3fb9 | djkim | |
180 | 787a4489 | KangIngu | 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 | 0b75c341 | taeseongkim | var pemssServiceClient = new PemssService.PemssServiceClient(App._binding, App._PemssEndPoint); |
262 | var result = pemssServiceClient.GetrequirementListAsync(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID).ConfigureAwait(false); |
||
263 | |||
264 | requirementList = result.GetAwaiter().GetResult(); |
||
265 | |||
266 | 787a4489 | KangIngu | _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 | PageChanged(_StartPageNo); |
||
277 | } |
||
278 | #endregion |
||
279 | |||
280 | #region Control Event |
||
281 | private void sliderPages_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) |
||
282 | { |
||
283 | if (_initializeComponentFinished) |
||
284 | { |
||
285 | if (!_IsDagSlider) |
||
286 | { |
||
287 | this.CurrentPageNo = (int)this.sliderPages.Value; |
||
288 | PageChanged(this.CurrentPageNo); |
||
289 | 481c3fb9 | djkim | |
290 | if (_ButtonName == "Current") |
||
291 | 114015fd | ljiyeon | { |
292 | stPageNo.Value = CurrentPageNo; |
||
293 | edPageNo.Value = CurrentPageNo; |
||
294 | 481c3fb9 | djkim | } |
295 | 114015fd | ljiyeon | |
296 | 787a4489 | KangIngu | //CheckCommentPages(); |
297 | } |
||
298 | } |
||
299 | } |
||
300 | |||
301 | private void sliderPages_DragCompleted(object sender, RadDragCompletedEventArgs e) |
||
302 | { |
||
303 | _IsDagSlider = false; |
||
304 | this.CurrentPageNo = (int)this.sliderPages.Value; |
||
305 | if (_initializeComponentFinished) |
||
306 | { |
||
307 | PageChanged(this.CurrentPageNo); |
||
308 | } |
||
309 | } |
||
310 | |||
311 | private void sliderPages_DragStarted(object sender, RadDragStartedEventArgs e) |
||
312 | { |
||
313 | _IsDagSlider = true; |
||
314 | } |
||
315 | |||
316 | private void chkOnlyMarkup_Checked(object sender, RoutedEventArgs e) |
||
317 | { |
||
318 | if (_initializeComponentFinished) //GridRangePages |
||
319 | { |
||
320 | CheckCommentPages(); |
||
321 | } |
||
322 | } |
||
323 | 114015fd | ljiyeon | string _ButtonName; |
324 | 787a4489 | KangIngu | private void PageSelect_Checked(object sender, RoutedEventArgs e) |
325 | { |
||
326 | if (!_initializeComponentFinished) return; |
||
327 | |||
328 | 114015fd | ljiyeon | _ButtonName = (sender as RadRadioButton).Tag.ToString(); |
329 | 787a4489 | KangIngu | CommentPageList.ItemsSource = null; |
330 | |||
331 | switch (_ButtonName) |
||
332 | { |
||
333 | case "Current": |
||
334 | stPageNo.Value = CurrentPageNo; |
||
335 | edPageNo.Value = CurrentPageNo; |
||
336 | |||
337 | GridCurrentPage.Visibility = Visibility.Visible; |
||
338 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
339 | GridRangePages.Visibility = Visibility.Collapsed; |
||
340 | GridAllPages.Visibility = Visibility.Collapsed; |
||
341 | |||
342 | break; |
||
343 | case "RangePrint": |
||
344 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
345 | GridDefinePages.Visibility = Visibility.Visible; |
||
346 | GridRangePages.Visibility = Visibility.Collapsed; |
||
347 | GridAllPages.Visibility = Visibility.Collapsed; |
||
348 | break; |
||
349 | case "UserDefined": |
||
350 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
351 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
352 | GridRangePages.Visibility = Visibility.Visible; |
||
353 | GridAllPages.Visibility = Visibility.Collapsed; |
||
354 | break; |
||
355 | case "AllPrint": |
||
356 | stPageNo.Value = 1; |
||
357 | edPageNo.Value = Convert.ToDouble(_DocInfo.PAGE_COUNT); |
||
358 | GridCurrentPage.Visibility = Visibility.Collapsed; |
||
359 | GridDefinePages.Visibility = Visibility.Collapsed; |
||
360 | GridRangePages.Visibility = Visibility.Collapsed; |
||
361 | GridAllPages.Visibility = Visibility.Visible; |
||
362 | break; |
||
363 | } |
||
364 | |||
365 | CheckCommentPages(); |
||
366 | } |
||
367 | |||
368 | private void PageNo_ValueChanged(object sender, RadRangeBaseValueChangedEventArgs e) |
||
369 | { |
||
370 | if (_initializeComponentFinished) //GridRangePages |
||
371 | { |
||
372 | if (stPageNo.Value > edPageNo.Value) |
||
373 | { |
||
374 | if (sender.Equals(stPageNo)) |
||
375 | edPageNo.Value = stPageNo.Value; |
||
376 | else |
||
377 | stPageNo.Value = edPageNo.Value; |
||
378 | } |
||
379 | |||
380 | //뷰어잠시제외(강인구) |
||
381 | //this.LayoutRoot.Dispatcher.BeginInvoke(delegate() |
||
382 | //{ |
||
383 | CheckCommentPages(); |
||
384 | //}); |
||
385 | } |
||
386 | } |
||
387 | |||
388 | private void txtDefinedPages_TextChanged(object sender, TextChangedEventArgs e) |
||
389 | { |
||
390 | CheckCommentPages(); |
||
391 | } |
||
392 | |||
393 | private void btnClearDefinedPages_Click(object sender, RoutedEventArgs e) |
||
394 | { |
||
395 | txtDefinedPages.Text = ""; |
||
396 | } |
||
397 | |||
398 | private void CommentPageList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) |
||
399 | { |
||
400 | if (_initializeComponentFinished) |
||
401 | if (CommentPageList.SelectedItem != null) |
||
402 | this.CurrentPageNo = (CommentPageList.SelectedItem as MarkupPageItem).PageNumber; |
||
403 | } |
||
404 | |||
405 | private void gridViewMarkup_SelectionChanged(object sender, SelectionChangeEventArgs e) |
||
406 | { |
||
407 | if (_initializeComponentFinished) |
||
408 | { |
||
409 | PageChanged(this.CurrentPageNo); |
||
410 | } |
||
411 | } |
||
412 | |||
413 | #endregion |
||
414 | |||
415 | public void PageChanged(int PageNo, bool Flag = false) |
||
416 | { |
||
417 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
418 | { |
||
419 | 481c3fb9 | djkim | try |
420 | { |
||
421 | Load load = new Load(); |
||
422 | 787a4489 | KangIngu | |
423 | 481c3fb9 | djkim | _definePages.Back_Image = new ImageBrush(); |
424 | //var defaultBitmapImage = new BitmapImage(new Uri(_DefaultTileUri + PageNo + ".png")); |
||
425 | var buffer = new WebClient().DownloadData(_DefaultTileUri + PageNo + ".png"); |
||
426 | var bitmap = new BitmapImage(); |
||
427 | using (var stream = new MemoryStream(buffer)) |
||
428 | { |
||
429 | bitmap.BeginInit(); |
||
430 | bitmap.CacheOption = BitmapCacheOption.OnLoad; |
||
431 | bitmap.StreamSource = stream; |
||
432 | bitmap.EndInit(); |
||
433 | 787a4489 | KangIngu | |
434 | 481c3fb9 | djkim | printCanvas.Children.Clear(); |
435 | 787a4489 | KangIngu | |
436 | 481c3fb9 | djkim | ImageBrush background = new ImageBrush(bitmap); |
437 | printCanvas.Background = background; |
||
438 | 787a4489 | KangIngu | |
439 | 481c3fb9 | djkim | iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(_DefaultTileUri + PageNo + ".png")); |
440 | printCanvas.Width = image.Width; |
||
441 | printCanvas.Height = image.Height; |
||
442 | |||
443 | 0b75c341 | taeseongkim | List<string> removeMarkupItems = new List<string>(); |
444 | |||
445 | 481c3fb9 | djkim | foreach (var info in gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>()) |
446 | { |
||
447 | 0b75c341 | taeseongkim | if (IsRequirement.IsChecked != true) |
448 | { |
||
449 | removeMarkupItems =requirementList.SelectMany(x => x.VpComments.SelectMany(c => c.commentId.Split(','))).ToList(); |
||
450 | } |
||
451 | |||
452 | 481c3fb9 | djkim | load.User_Id = info.UserID; |
453 | load.document_id = _DocInfo.DOCUMENT_ID; |
||
454 | load.Page_No = PageNo; |
||
455 | load.DisplayColor = info.DisplayColor; |
||
456 | load.Markupinfoid = info.MarkupInfoID; |
||
457 | 0b75c341 | taeseongkim | load.Markup_Load(printCanvas, removeMarkupItems); |
458 | 481c3fb9 | djkim | } |
459 | |||
460 | printCanvas.UpdateLayout(); |
||
461 | |||
462 | if (Flag) |
||
463 | { |
||
464 | 787a4489 | KangIngu | |
465 | 481c3fb9 | djkim | //MemoryStream ms = new MemoryStream(); |
466 | //BmpBitmapEncoder bbe = new BmpBitmapEncoder(); |
||
467 | //bbe.Frames.Add(BitmapFrame.Create(new Uri(_DefaultTileUri + PageNo + ".png"))); |
||
468 | //bbe.Save(ms); |
||
469 | 787a4489 | KangIngu | |
470 | 481c3fb9 | djkim | //System.Drawing.Image.FromFile() |
471 | Printimg = System.Drawing.Image.FromStream(stream); |
||
472 | Export export = new Export(); |
||
473 | p_img = export.Exporting(printCanvas, Printimg); |
||
474 | Printimg_List.Add(Printimg_List.Count() + 1, p_img); |
||
475 | } |
||
476 | } |
||
477 | |||
478 | } |
||
479 | catch (Exception ex) |
||
480 | 787a4489 | KangIngu | { |
481 | 481c3fb9 | djkim | Logger.sendResLog("PrintControl.PageChanged", ex.Message, 0); |
482 | 787a4489 | KangIngu | } |
483 | })); |
||
484 | } |
||
485 | 481c3fb9 | djkim | public static MemoryStream ByteBufferFromImage(BitmapImage imageSource) |
486 | { |
||
487 | var ms = new MemoryStream(); |
||
488 | var pngEncoder = new PngBitmapEncoder(); |
||
489 | pngEncoder.Frames.Add(BitmapFrame.Create(imageSource)); |
||
490 | pngEncoder.Save(ms); |
||
491 | 787a4489 | KangIngu | |
492 | 481c3fb9 | djkim | return ms; |
493 | } |
||
494 | 787a4489 | KangIngu | //Print 버튼 클릭 이벤트 |
495 | #region Method - 명령 |
||
496 | void PrintMethod(object sender, RoutedEventArgs e) |
||
497 | { |
||
498 | 481c3fb9 | djkim | try |
499 | { |
||
500 | if (this.printIndy.IsBusy == true) |
||
501 | return; |
||
502 | 787a4489 | KangIngu | |
503 | 481c3fb9 | djkim | System.Threading.Tasks.Task.Factory.StartNew(() => |
504 | { |
||
505 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
506 | { |
||
507 | this.printIndy.IsBusy = true; |
||
508 | printIndy.BusyContent = "Printing. . ."; |
||
509 | })); |
||
510 | }); |
||
511 | 787a4489 | KangIngu | |
512 | 481c3fb9 | djkim | |
513 | _lstPrintPageNo = PrintPageCreate(); |
||
514 | |||
515 | if (_lstPrintPageNo.Count == 0) |
||
516 | 787a4489 | KangIngu | { |
517 | 481c3fb9 | djkim | RadWindow.Alert(new DialogParameters |
518 | { |
||
519 | Owner = Application.Current.MainWindow, |
||
520 | Theme = new VisualStudio2013Theme(), |
||
521 | Header = "안내", |
||
522 | Content = "페이지가 지정되지 않았습니다." |
||
523 | }); |
||
524 | this.printIndy.IsBusy = false; |
||
525 | return; |
||
526 | } |
||
527 | int cnt = 0; |
||
528 | List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>(); |
||
529 | 787a4489 | KangIngu | |
530 | 481c3fb9 | djkim | Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
531 | 787a4489 | KangIngu | |
532 | 481c3fb9 | djkim | foreach (int PageNo in _lstPrintPageNo) |
533 | { |
||
534 | cnt++; |
||
535 | sliderPages.Value = PageNo; |
||
536 | PageChanged(PageNo, true); |
||
537 | //PageChanged(cnt, true); |
||
538 | } |
||
539 | PrintName = cbPrint.SelectedItem.ToString(); |
||
540 | 787a4489 | KangIngu | |
541 | 481c3fb9 | djkim | System.Threading.Tasks.Task.Factory.StartNew(() => |
542 | 787a4489 | KangIngu | { |
543 | 481c3fb9 | djkim | if (cnt == _lstPrintPageNo.Count) |
544 | { |
||
545 | Printing(); |
||
546 | } |
||
547 | 787a4489 | KangIngu | }); |
548 | } |
||
549 | 481c3fb9 | djkim | catch (Exception ex) |
550 | 787a4489 | KangIngu | { |
551 | 481c3fb9 | djkim | Logger.sendResLog("PrintMethod", ex.Message, 0); |
552 | 787a4489 | KangIngu | } |
553 | |||
554 | } |
||
555 | |||
556 | //Export 버튼 클릭 이벤트 |
||
557 | void ExportMethod(object sender, RoutedEventArgs e) |
||
558 | { |
||
559 | 481c3fb9 | djkim | try |
560 | { |
||
561 | if (this.printIndy.IsBusy == true) |
||
562 | return; |
||
563 | 787a4489 | KangIngu | |
564 | 481c3fb9 | djkim | this.printIndy.IsBusy = true; |
565 | printIndy.BusyContent = "Exporting. . ."; |
||
566 | 787a4489 | KangIngu | |
567 | 481c3fb9 | djkim | Export export = new Export(); |
568 | _lstPrintPageNo = PrintPageCreate(); |
||
569 | 787a4489 | KangIngu | |
570 | 481c3fb9 | djkim | if (_lstPrintPageNo.Count == 0) |
571 | 787a4489 | KangIngu | { |
572 | 481c3fb9 | djkim | this.printIndy.IsBusy = false; |
573 | RadWindow.Alert(new DialogParameters |
||
574 | 787a4489 | KangIngu | { |
575 | 481c3fb9 | djkim | Owner = Application.Current.MainWindow, |
576 | Theme = new VisualStudio2013Theme(), |
||
577 | Header = "안내", |
||
578 | Content = "페이지가 지정되지 않았습니다.", |
||
579 | }); |
||
580 | return; |
||
581 | } |
||
582 | 787a4489 | KangIngu | |
583 | 481c3fb9 | djkim | //FileDialogFilter filterImage = new FileDialogFilter("Image Files", "*.jpg", "*.png"); |
584 | 787a4489 | KangIngu | |
585 | switch (cbPrint.SelectedIndex) |
||
586 | { |
||
587 | case (0): |
||
588 | { |
||
589 | 481c3fb9 | djkim | SaveDig.Filter = "PDF file format|*.pdf"; |
590 | break; |
||
591 | } |
||
592 | case (1): |
||
593 | { |
||
594 | SaveDig.Filter = "Image Files (*.jpg, *.Jpeg)|*.jpg;*.Jpeg|Image Files (*.png)|*.png"; |
||
595 | break; |
||
596 | } |
||
597 | } |
||
598 | |||
599 | SaveDig.Title = "Save an PDF File"; |
||
600 | if(SaveDig.ShowDialog().Value) |
||
601 | { |
||
602 | Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
||
603 | |||
604 | foreach (int PageNo in _lstPrintPageNo) |
||
605 | { |
||
606 | sliderPages.Value = PageNo; |
||
607 | PageChanged(PageNo, true); |
||
608 | } |
||
609 | |||
610 | //using (FileStream fs = new FileStream(@"D:\Temp\Text.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) |
||
611 | |||
612 | if (SaveDig.FileName != "") |
||
613 | { |
||
614 | switch (cbPrint.SelectedIndex) |
||
615 | { |
||
616 | case (0): |
||
617 | 787a4489 | KangIngu | { |
618 | 481c3fb9 | djkim | using (FileStream fs = new FileStream(SaveDig.FileName, FileMode.Create, FileAccess.Write, FileShare.None)) |
619 | 787a4489 | KangIngu | { |
620 | 481c3fb9 | djkim | using (Document doc = new Document()) |
621 | 787a4489 | KangIngu | { |
622 | 481c3fb9 | djkim | using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) |
623 | e3a15e22 | djkim | { |
624 | 481c3fb9 | djkim | doc.Open(); |
625 | float height = doc.PageSize.Height; |
||
626 | float width = doc.PageSize.Width; |
||
627 | |||
628 | foreach (var item in Printimg_List) |
||
629 | { |
||
630 | 787a4489 | KangIngu | |
631 | 481c3fb9 | djkim | Export_img = iTextSharp.text.Image.GetInstance(item.Value, System.Drawing.Imaging.ImageFormat.Png); |
632 | |||
633 | |||
634 | if (Export_img.Width > Export_img.Height) |
||
635 | { |
||
636 | doc.SetPageSize(new Rectangle(height, width)); |
||
637 | Export_img.ScaleToFit(height, width); |
||
638 | } |
||
639 | else |
||
640 | { |
||
641 | doc.SetPageSize(new Rectangle(width, height)); |
||
642 | Export_img.ScaleToFit(width, height); |
||
643 | } |
||
644 | |||
645 | Export_img.SetAbsolutePosition(0, 0); |
||
646 | |||
647 | doc.NewPage(); |
||
648 | doc.Add(Export_img); |
||
649 | } |
||
650 | doc.Close(); |
||
651 | } |
||
652 | 787a4489 | KangIngu | } |
653 | } |
||
654 | 481c3fb9 | djkim | break; |
655 | 787a4489 | KangIngu | } |
656 | 481c3fb9 | djkim | case (1): |
657 | 787a4489 | KangIngu | { |
658 | 481c3fb9 | djkim | foreach (var item in Printimg_List) |
659 | { |
||
660 | switch (SaveDig.FilterIndex) |
||
661 | 787a4489 | KangIngu | { |
662 | 481c3fb9 | djkim | case (1): |
663 | { |
||
664 | //(item.Value as System.Drawing.Image).Save(SaveDig.FileName + item.Key, System.Drawing.Imaging.ImageFormat.Jpeg); |
||
665 | (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".jpg", "_" + item.Key.ToString()) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); |
||
666 | } |
||
667 | break; |
||
668 | case (2): |
||
669 | { |
||
670 | //(item.Value as System.Drawing.Image).Save(SaveDig.FileName, System.Drawing.Imaging.ImageFormat.Png); |
||
671 | (item.Value as System.Drawing.Image).Save(SaveDig.FileName.Replace(".png", "_" + item.Key.ToString()) + ".png", System.Drawing.Imaging.ImageFormat.Png); |
||
672 | } |
||
673 | break; |
||
674 | 787a4489 | KangIngu | } |
675 | 481c3fb9 | djkim | } |
676 | break; |
||
677 | 787a4489 | KangIngu | } |
678 | } |
||
679 | 481c3fb9 | djkim | } |
680 | else |
||
681 | { |
||
682 | this.printIndy.IsBusy = false; |
||
683 | return; |
||
684 | } |
||
685 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
686 | { |
||
687 | printIndy.IsBusy = false; |
||
688 | })); |
||
689 | PageChanged(_StartPageNo); |
||
690 | 787a4489 | KangIngu | |
691 | 481c3fb9 | djkim | (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Success", "Alert"); |
692 | }else |
||
693 | { |
||
694 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
695 | { |
||
696 | printIndy.IsBusy = false; |
||
697 | })); |
||
698 | 787a4489 | KangIngu | |
699 | 481c3fb9 | djkim | (Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Cancel", "Alert"); |
700 | } |
||
701 | } |
||
702 | catch (Exception ex) |
||
703 | 787a4489 | KangIngu | { |
704 | 481c3fb9 | djkim | Logger.sendResLog("Export Method", ex.Message, 0); |
705 | //(Application.Current.MainWindow as MainWindow).dzMainMenu.DialogMessage_Alert("Alert", "관리자 확인이 필요합니다. 다시 시도해 주세요.\n"+ex.Message); |
||
706 | } |
||
707 | 787a4489 | KangIngu | |
708 | } |
||
709 | #endregion |
||
710 | |||
711 | #region Method - 처리 |
||
712 | void CheckCommentPages() |
||
713 | { |
||
714 | List<MarkupPageItem> _pages = new List<MarkupPageItem>(); |
||
715 | DoubleCollection _Ticks = new DoubleCollection(); |
||
716 | |||
717 | |||
718 | if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible) |
||
719 | { |
||
720 | |||
721 | _pages = (from commPage in this._PageMarkupList |
||
722 | where commPage.PageNumber == CurrentPageNo |
||
723 | orderby commPage.PageNumber |
||
724 | select commPage).ToList(); |
||
725 | } |
||
726 | else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
||
727 | { |
||
728 | stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
||
729 | edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
||
730 | |||
731 | int _stPage = (int)stPageNo.Value; |
||
732 | int _edPage = (int)edPageNo.Value; |
||
733 | |||
734 | _pages = (from commPage in this._PageMarkupList |
||
735 | where commPage.PageNumber >= _stPage && commPage.PageNumber <= _edPage |
||
736 | orderby commPage.PageNumber |
||
737 | select commPage).ToList(); |
||
738 | } |
||
739 | else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
||
740 | { |
||
741 | stPageNo.Value = stPageNo.Value == null ? 1 : stPageNo.Value; |
||
742 | edPageNo.Value = edPageNo.Value == null ? 1 : edPageNo.Value; |
||
743 | |||
744 | int _stPage = (int)stPageNo.Value; |
||
745 | int _edPage = (int)edPageNo.Value; |
||
746 | |||
747 | //Using DeepView.Common.RangeParser |
||
748 | var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
||
749 | _pages = (from commPage in this._PageMarkupList |
||
750 | from compareData in lst |
||
751 | where commPage.PageNumber == compareData |
||
752 | orderby commPage.PageNumber |
||
753 | select commPage).ToList(); |
||
754 | } |
||
755 | else |
||
756 | { |
||
757 | _pages = (from commPage in this._PageMarkupList |
||
758 | orderby commPage.PageNumber |
||
759 | select commPage).ToList(); |
||
760 | } |
||
761 | CommentPageList.ItemsSource = _pages.ToList(); |
||
762 | } |
||
763 | |||
764 | void SetLoadMakupList(int PageNo) |
||
765 | { |
||
766 | _LoadMakupList.Clear(); |
||
767 | var _markupList = _PageMarkupList.Where(page => page.PageNumber == PageNo); |
||
768 | |||
769 | if (_markupList.Count() > 0) |
||
770 | _LoadMakupList = _markupList.First().DisplayColorItems.ToList(); |
||
771 | } |
||
772 | |||
773 | #region 프린트 리스트 가져오기 |
||
774 | public void GetPrint(bool flag) |
||
775 | { |
||
776 | if (flag) |
||
777 | { |
||
778 | foreach (string printer in PrinterSettings.InstalledPrinters) |
||
779 | { |
||
780 | this.cbPrint.Items.Add(printer); |
||
781 | } |
||
782 | printDocument = new PrintDocument(); |
||
783 | this.cbPrint.SelectedItem = printDocument.PrinterSettings.PrinterName; |
||
784 | } |
||
785 | else |
||
786 | { |
||
787 | this.cbPrint.Items.Add("PDF"); |
||
788 | this.cbPrint.Items.Add("IMAGE"); |
||
789 | |||
790 | this.cbPrint.SelectedItem = "PDF"; |
||
791 | } |
||
792 | } |
||
793 | #endregion |
||
794 | |||
795 | #region 프린트 실행 |
||
796 | public void Printing() |
||
797 | { |
||
798 | PageChanged(1); |
||
799 | if (PrinterSettings.InstalledPrinters != null && PrinterSettings.InstalledPrinters.Count > 0) |
||
800 | { |
||
801 | 481c3fb9 | djkim | printDocument = new PrintDocument(); |
802 | 408e4218 | ljiyeon | printDocument.OriginAtMargins = true; |
803 | 787a4489 | KangIngu | printDocument.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_BeginPrint); |
804 | printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage); |
||
805 | printDocument.EndPrint += new System.Drawing.Printing.PrintEventHandler(printDocument_EndPrint); |
||
806 | } |
||
807 | else |
||
808 | printDocument = null; |
||
809 | |||
810 | #region 인쇄 미리보기 테스트 |
||
811 | using (System.Windows.Forms.PrintPreviewDialog dlg = new System.Windows.Forms.PrintPreviewDialog()) |
||
812 | { |
||
813 | printDocument.PrinterSettings.MinimumPage = 1; |
||
814 | printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
||
815 | printDocument.PrinterSettings.FromPage = 1; |
||
816 | 408e4218 | ljiyeon | printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
817 | 787a4489 | KangIngu | printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
818 | 481c3fb9 | djkim | printDocument.PrinterSettings.PrinterName = PrintName; |
819 | dlg.Document = printDocument; |
||
820 | 787a4489 | KangIngu | dlg.WindowState = System.Windows.Forms.FormWindowState.Maximized; |
821 | dlg.ShowDialog(); |
||
822 | } |
||
823 | #endregion |
||
824 | |||
825 | #region 인쇄 |
||
826 | //printDocument.PrinterSettings.MinimumPage = 1; |
||
827 | //printDocument.PrinterSettings.MaximumPage = _lstPrintPageNo.Count(); |
||
828 | //printDocument.PrinterSettings.FromPage = 1; |
||
829 | //printDocument.PrinterSettings.ToPage = _lstPrintPageNo.Count(); |
||
830 | |||
831 | //printDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); |
||
832 | //printDocument.PrinterSettings.PrinterName = PrintName; |
||
833 | |||
834 | //printDocument.Print(); |
||
835 | #endregion |
||
836 | } |
||
837 | |||
838 | private void printDocument_BeginPrint(object sender, PrintEventArgs e) |
||
839 | { |
||
840 | //Printimg_List = new Dictionary<int, System.Drawing.Image>(); |
||
841 | // This demo only loads one page at a time, so no need to re-set the print page number |
||
842 | 481c3fb9 | djkim | PrintDocument document = sender as PrintDocument; |
843 | 787a4489 | KangIngu | currentPage = document.PrinterSettings.FromPage; |
844 | } |
||
845 | 481c3fb9 | djkim | |
846 | 787a4489 | KangIngu | private void printDocument_PrintPage(object sender, PrintPageEventArgs e) |
847 | { |
||
848 | //e.Graphics.DrawImage(Printimg_List.Where(info => info.Key == currentPage).FirstOrDefault().Value, 0, 0); |
||
849 | |||
850 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
851 | { |
||
852 | p_img = Printimg_List.Where(data => data.Key == currentPage).FirstOrDefault().Value; |
||
853 | 2024d8d1 | ljiyeon | |
854 | 481c3fb9 | djkim | if (p_img.Width > p_img.Height) |
855 | 2024d8d1 | ljiyeon | { |
856 | p_img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); |
||
857 | } |
||
858 | 408e4218 | ljiyeon | |
859 | //iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(p_img, System.Drawing.Imaging.ImageFormat.Jpeg); |
||
860 | System.Drawing.Image pic = p_img; |
||
861 | 787a4489 | KangIngu | System.Drawing.Rectangle m = e.MarginBounds; |
862 | |||
863 | 408e4218 | ljiyeon | //if ((double)pic.Width / (double)pic.Height > (double)m.Width / (double)m.Height) // image is wider |
864 | //{ |
||
865 | // m.Height = 1135;//(int)((double)pic.Height / (double)pic.Width * (double)m.Width) - 16; |
||
866 | //} |
||
867 | //else |
||
868 | //{ |
||
869 | // m.Width = 793;//(int)((double)pic.Width / (double)pic.Height * (double)m.Height) - 16; |
||
870 | //} |
||
871 | m.Width = (int)e.PageSettings.PrintableArea.Width; |
||
872 | m.Height = (int)e.PageSettings.PrintableArea.Height; |
||
873 | m.X = (int)e.PageSettings.HardMarginX; |
||
874 | m.Y = (int)e.PageSettings.HardMarginY; |
||
875 | |||
876 | e.Graphics.DrawImage(pic, m); |
||
877 | 787a4489 | KangIngu | //e.Graphics.DrawImage(p_img, e.MarginBounds); |
878 | //e.Graphics.DrawImage(p_img, 0, 0); |
||
879 | })); |
||
880 | 481c3fb9 | djkim | |
881 | 787a4489 | KangIngu | //다음 페이지 |
882 | currentPage++; |
||
883 | 481c3fb9 | djkim | |
884 | 787a4489 | KangIngu | ////인쇄를 계속 할지 말지 확인 |
885 | if (currentPage <= printDocument.PrinterSettings.ToPage) |
||
886 | e.HasMorePages = true; |
||
887 | else |
||
888 | e.HasMorePages = false; |
||
889 | |||
890 | } |
||
891 | |||
892 | private void printDocument_EndPrint(object sender, PrintEventArgs e) |
||
893 | { |
||
894 | Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
||
895 | { |
||
896 | printIndy.IsBusy = false; |
||
897 | })); |
||
898 | } |
||
899 | #endregion |
||
900 | |||
901 | #region Selected Pages Check |
||
902 | List<int> PrintPageCreate() |
||
903 | { |
||
904 | List<int> Result = new List<int>(); |
||
905 | |||
906 | if (GridCurrentPage.Visibility == System.Windows.Visibility.Visible || currentPagePrint) |
||
907 | { |
||
908 | Result.Add(CurrentPageNo); |
||
909 | } |
||
910 | else if (GridRangePages.Visibility == System.Windows.Visibility.Visible) |
||
911 | { |
||
912 | for (int i = Convert.ToInt32(stPageNo.Value); i <= Convert.ToInt32(edPageNo.Value); i++) |
||
913 | { |
||
914 | Result.Add(i); |
||
915 | } |
||
916 | } |
||
917 | else if (GridDefinePages.Visibility == System.Windows.Visibility.Visible) |
||
918 | { |
||
919 | int _stPage = (int)stPageNo.Value; |
||
920 | int _edPage = (int)edPageNo.Value; |
||
921 | |||
922 | var lst = RangeParser.Parse(txtDefinedPages.Text, _stPage, _definePages.PagesCount); |
||
923 | Result.AddRange(lst); |
||
924 | } |
||
925 | else |
||
926 | { |
||
927 | for (int i = 1; i <= _definePages.PagesCount; i++) |
||
928 | { |
||
929 | Result.Add(i); |
||
930 | } |
||
931 | } |
||
932 | if (currentPagePrint) |
||
933 | { |
||
934 | return Result; |
||
935 | } |
||
936 | |||
937 | if (chkOnlyMarkup.IsChecked.Value) |
||
938 | { |
||
939 | var _result = from result in Result |
||
940 | where _PageMarkupList.Where(page => page.PageNumber == result).Count() > 0 |
||
941 | select result; |
||
942 | Result = _result.ToList(); |
||
943 | } |
||
944 | return Result; |
||
945 | } |
||
946 | #endregion |
||
947 | |||
948 | #endregion |
||
949 | } |
||
950 | } |