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