markus / KCOM / Controls / Symbol.xaml.cs @ 7c0fea12
이력 | 보기 | 이력해설 | 다운로드 (18.6 KB)
1 |
using KCOM.Common; |
---|---|
2 |
using KCOM.Events; |
3 |
using KCOMDataModel.Common; |
4 |
using KCOMDataModel.DataModel; |
5 |
using MarkupToPDF.Common; |
6 |
using System; |
7 |
using System.Collections.Generic; |
8 |
using System.Linq; |
9 |
using System.Text; |
10 |
using System.Windows; |
11 |
using System.Windows.Controls; |
12 |
using System.Windows.Data; |
13 |
using System.Windows.Documents; |
14 |
using System.Windows.Input; |
15 |
using System.Windows.Media; |
16 |
using System.Windows.Media.Imaging; |
17 |
using System.Windows.Navigation; |
18 |
using System.Windows.Shapes; |
19 |
using Telerik.Windows.Controls; |
20 |
using Telerik.Windows.Controls.DragDrop; |
21 |
|
22 |
namespace KCOM.Controls |
23 |
{ |
24 |
public class Symbol_Custom |
25 |
{ |
26 |
public string ID { get; set; } |
27 |
public string Name { get; set; } |
28 |
public string ImageUri { get; set; } |
29 |
} |
30 |
|
31 |
/// <summary> |
32 |
/// Symbol.xaml에 대한 상호 작용 논리 |
33 |
/// </summary> |
34 |
public partial class Symbol : UserControl |
35 |
{ |
36 |
AdornerFinal finalItem; |
37 |
bool IsMouseDown = false; |
38 |
string moveItem_id = ""; |
39 |
public string filename { get; set; } |
40 |
MarkupToPDF.Controls.Parsing.LayerControl layer = new MarkupToPDF.Controls.Parsing.LayerControl(); |
41 |
public MarkupToPDF.Common.Undo_data UndoData; |
42 |
|
43 |
public Symbol() |
44 |
{ |
45 |
InitializeComponent(); |
46 |
|
47 |
DataBind(); |
48 |
} |
49 |
|
50 |
private void OnDragPrivateInfo(object sender, DragDropEventArgs e) |
51 |
{ |
52 |
} |
53 |
|
54 |
private void OnDragPrivateQuery(object sender, DragDropQueryEventArgs e) |
55 |
{ |
56 |
if (e.Options.Status == DragStatus.DragQuery) |
57 |
{ |
58 |
//var draggedListBoxItem = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem; |
59 |
//BitmapImage im = new BitmapImage(new Uri((draggedListBoxItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate).ImageUri)); |
60 |
//ImageSource _source = im; |
61 |
//Image img = new Image(); |
62 |
//img.Source = _source; |
63 |
|
64 |
//e.Options.Payload = im; |
65 |
//var dragCue = new Image(); |
66 |
//dragCue.Source = img.Source; |
67 |
//dragCue.Width = 0; |
68 |
//dragCue.Height = 0; |
69 |
//e.Options.DragCue = dragCue; |
70 |
|
71 |
|
72 |
//PayLoadAdorner = new AdornerFinal(); |
73 |
//DeepView.ServiceDeepView_Symbol.SymbolPrivate tempDragableControl = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate; |
74 |
//var xamldata = tempDragableControl.Data; |
75 |
////this.DeepLayer.markupParse(xamldata, this.DeepLayer._TempLayer, "복사된 데이터_이름으로 수정해야함"); |
76 |
//PayLoadAdorner = this.DeepLayer.markupParseToAdorner(xamldata, this.DeepLayer._SelectLayer, ""); |
77 |
//this.DeepLayer._SelectLayer.Children.Add(PayLoadAdorner); |
78 |
} |
79 |
|
80 |
e.QueryResult = true; |
81 |
e.Handled = true; |
82 |
} |
83 |
|
84 |
private void DataBind() |
85 |
{ |
86 |
//lstSymbolPrivate.ItemsSource = null; |
87 |
//lstSymbolPublic.ItemsSource = null; |
88 |
|
89 |
Symbol_Custom Custom = new Symbol_Custom(); |
90 |
List<Symbol_Custom> Custom_List = new List<Symbol_Custom>(); |
91 |
|
92 |
using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
93 |
{ |
94 |
var symbol_Private = Entity.SYMBOL_PRIVATE.Where(data => data.MEMBER_USER_ID == App.ViewInfo.UserID).ToList(); |
95 |
foreach(var item in symbol_Private) |
96 |
{ |
97 |
Custom.Name = item.NAME; |
98 |
Custom.ImageUri = item.IMAGE_URL; |
99 |
Custom.ID = item.ID; |
100 |
Custom_List.Add(Custom); |
101 |
Custom = new Symbol_Custom(); |
102 |
} |
103 |
lstSymbolPrivate.ItemsSource = Custom_List; |
104 |
|
105 |
Custom = new Symbol_Custom(); |
106 |
Custom_List = new List<Symbol_Custom>(); |
107 |
|
108 |
deptlist.ItemsSource = Entity.SYMBOL_PUBLIC.Select(data => data.DEPARTMENT).ToList(); |
109 |
|
110 |
var symbol_Public = Entity.SYMBOL_PUBLIC.ToList(); |
111 |
|
112 |
if (deptlist.SelectedValue != null) |
113 |
{ |
114 |
symbol_Public = symbol_Public.Where(data => data.DEPARTMENT == deptlist.SelectedValue.ToString()).ToList(); |
115 |
} |
116 |
//var symbol_Public = Entity.SYMBOL_PUBLIC.Where(data => data.DEPARTMENT == "PIPING").ToList(); |
117 |
|
118 |
foreach (var item in symbol_Public) |
119 |
{ |
120 |
Custom.Name = item.NAME; |
121 |
Custom.ImageUri = item.IMAGE_URL; |
122 |
Custom.ID = item.ID; |
123 |
Custom_List.Add(Custom); |
124 |
Custom = new Symbol_Custom(); |
125 |
} |
126 |
lstSymbolPublic.ItemsSource = Custom_List; |
127 |
} |
128 |
} |
129 |
|
130 |
public PngBitmapEncoder symImage(string data) |
131 |
{ |
132 |
|
133 |
Canvas _canvas = new Canvas(); |
134 |
_canvas.Background = Brushes.White; |
135 |
_canvas.Width = finalItem.BorderSize.Width; |
136 |
_canvas.Height = finalItem.BorderSize.Height; |
137 |
//강인구 추가 프로젝트 번호 넣어주기 |
138 |
layer.ProjectNo = App.ViewInfo.ProjectNO; |
139 |
layer.markupParse(data, _canvas, "#FFFF0000", ""); |
140 |
|
141 |
BitmapEncoder encoder = new PngBitmapEncoder(); |
142 |
|
143 |
|
144 |
RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)_canvas.Width + 50, (int)_canvas.Height + 50, 96d, 96d, PixelFormats.Pbgra32); |
145 |
|
146 |
DrawingVisual dv = new DrawingVisual(); |
147 |
|
148 |
_canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50)); |
149 |
//_canvas.Arrange(new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 50, Y = -finalItem.BorderSize.Y - 50 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20))); |
150 |
_canvas.Arrange(new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 20, Y = -finalItem.BorderSize.Y - 20 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20))); |
151 |
|
152 |
using (DrawingContext ctx = dv.RenderOpen()) |
153 |
{ |
154 |
VisualBrush vb = new VisualBrush(_canvas); |
155 |
//ctx.DrawRectangle(vb, null, new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 20, Y = -finalItem.BorderSize.Y - 20 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20))); |
156 |
ctx.DrawRectangle(vb, null, new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X, Y = -finalItem.BorderSize.Y }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20))); |
157 |
} |
158 |
|
159 |
try |
160 |
{ |
161 |
renderBitmap.Render(dv); |
162 |
|
163 |
GC.Collect(); |
164 |
GC.WaitForPendingFinalizers(); |
165 |
GC.Collect(); |
166 |
//bitmap.Render(controlToConvert); |
167 |
// encode png data |
168 |
PngBitmapEncoder pngEncoder = new PngBitmapEncoder(); |
169 |
// puch rendered bitmap into it |
170 |
pngEncoder.Interlace = PngInterlaceOption.Off; |
171 |
pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap)); |
172 |
return pngEncoder; |
173 |
|
174 |
} |
175 |
catch (Exception ex) |
176 |
{ |
177 |
return null; |
178 |
} |
179 |
|
180 |
} |
181 |
|
182 |
public void DialogMessage_Alert(string content, string header) |
183 |
{ |
184 |
var box = new TextBlock(); |
185 |
box.MinWidth = 400; |
186 |
box.FontSize = 11; |
187 |
//box.FontSize = 12; |
188 |
box.Text = content; |
189 |
box.TextWrapping = System.Windows.TextWrapping.Wrap; |
190 |
|
191 |
DialogParameters parameters = new DialogParameters() |
192 |
{ |
193 |
Content = box, |
194 |
Header = header, |
195 |
Theme = new VisualStudio2013Theme(), |
196 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
197 |
}; |
198 |
RadWindow.Alert(parameters); |
199 |
} |
200 |
|
201 |
#region Event |
202 |
|
203 |
#region Symbol Add Event |
204 |
private void Create_Symbol(object sender, RoutedEventArgs e) |
205 |
{ |
206 |
MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn(); |
207 |
|
208 |
if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Count < 1) //선택된 것이 없으면 |
209 |
{ |
210 |
DialogMessage_Alert("Please Select Controls", "Alert"); |
211 |
} |
212 |
else //선택된 것이 있으면 |
213 |
{ |
214 |
string MarkupData = ""; |
215 |
finalItem = new AdornerFinal(); |
216 |
|
217 |
foreach (var item in Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children) |
218 |
{ |
219 |
if (item.GetType().Name == "AdornerFinal") |
220 |
{ |
221 |
finalItem = (item as Controls.AdornerFinal); |
222 |
foreach (var InnerItem in (item as Controls.AdornerFinal).MemberSet.Cast<Controls.AdornerMember>()) |
223 |
{ |
224 |
if (!ViewerDataModel.Instance.MarkupControls.Contains(InnerItem.DrawingData)) |
225 |
{ |
226 |
markupReturn = layer.MarkupToString(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo, App.ViewInfo.UserID); |
227 |
MarkupData += markupReturn.ConvertData; |
228 |
} |
229 |
} |
230 |
} |
231 |
} |
232 |
DialogParameters parameters = new DialogParameters() |
233 |
{ |
234 |
Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args), |
235 |
DefaultPromptResultValue = "Custom State", |
236 |
Content = "Name :", |
237 |
Header = "Insert Custom Symbol Name", |
238 |
Theme = new VisualStudio2013Theme(), |
239 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
240 |
}; |
241 |
RadWindow.Prompt(parameters); |
242 |
} |
243 |
|
244 |
} |
245 |
#endregion |
246 |
|
247 |
#region Symbol Add Close Event |
248 |
private void MarkupNamePromptClose(string data, WindowClosedEventArgs args) |
249 |
{ |
250 |
Save save = new Save(); |
251 |
|
252 |
if (args.DialogResult.Value) |
253 |
{ |
254 |
PngBitmapEncoder _Encoder = symImage(data); |
255 |
|
256 |
System.IO.MemoryStream fs = new System.IO.MemoryStream(); |
257 |
_Encoder.Save(fs); |
258 |
System.Drawing.Image ImgOut = System.Drawing.Image.FromStream(fs); |
259 |
|
260 |
byte[] Img_byte = fs.ToArray(); |
261 |
|
262 |
kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload(); |
263 |
filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, Save.shortGuid() + ".png", Img_byte); |
264 |
|
265 |
save.SymbolSave(args.PromptResult, filename, data); |
266 |
|
267 |
DataBind(); |
268 |
} |
269 |
} |
270 |
#endregion |
271 |
|
272 |
#region Symbol Delete Event |
273 |
private void Remove_Symbol(object sender, RoutedEventArgs e) |
274 |
{ |
275 |
if (lstSymbolPrivate.SelectedItem == null) |
276 |
{ |
277 |
DialogMessage_Alert("Please Select Symbol", "Alert"); |
278 |
return; |
279 |
} |
280 |
|
281 |
using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
282 |
{ |
283 |
string delItem_ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID; |
284 |
var delitem = Entity.SYMBOL_PRIVATE.Where(data => data.ID == delItem_ID).FirstOrDefault(); |
285 |
Entity.SYMBOL_PRIVATE.DeleteObject(delitem); |
286 |
Entity.SaveChanges(); |
287 |
|
288 |
DataBind(); |
289 |
} |
290 |
} |
291 |
#endregion |
292 |
|
293 |
#region Symbol DoubleClick Event |
294 |
private void Move_Symbol(object sender, MouseButtonEventArgs e) |
295 |
{ |
296 |
moveItem_id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID; |
297 |
|
298 |
IsMouseDown = true; |
299 |
|
300 |
//더블 클릭 |
301 |
if (e.ClickCount > 1) |
302 |
{ |
303 |
//string moveItem_id = ((e.Source as ListBox).SelectedItem as Symbol_Custom).ID; |
304 |
string Data_ = ""; |
305 |
|
306 |
using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
307 |
{ |
308 |
if (RadTab.SelectedIndex == 0) |
309 |
Data_ = Entity.SYMBOL_PRIVATE.Where(data => data.ID == moveItem_id).FirstOrDefault().DATA; |
310 |
else |
311 |
Data_ = Entity.SYMBOL_PUBLIC.Where(data => data.ID == moveItem_id).FirstOrDefault().DATA; |
312 |
} |
313 |
|
314 |
if (Data_.Contains("|DZ|")) |
315 |
{ |
316 |
List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>(); |
317 |
|
318 |
string[] delimiterChars = { "|DZ|" }; |
319 |
string[] data = Data_.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
320 |
|
321 |
this.ParentOfType<MainWindow>().dzMainMenu.ReleaseAdorner(); |
322 |
|
323 |
Multi_Undo_data multi_Undo_Data = new Multi_Undo_data(); |
324 |
|
325 |
//강인구 Undo/Redo 보류 |
326 |
UndoData = new Undo_data() |
327 |
{ |
328 |
IsUndo = false, |
329 |
Event = Event_Type.Create, |
330 |
EventTime = DateTime.Now, |
331 |
Markup_List = new List<Multi_Undo_data>() |
332 |
}; |
333 |
|
334 |
ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i => |
335 |
{ |
336 |
ViewerDataModel.Instance.UndoDataList.Remove(i); |
337 |
}); |
338 |
|
339 |
foreach (string parse in data) |
340 |
{ |
341 |
if (parse != "") |
342 |
{ |
343 |
System.Windows.Controls.Control item = layer.markupParse_Paste(parse, ViewerDataModel.Instance.MarkupControls_USER); |
344 |
(item as MarkupToPDF.Common.CommentUserInfo).CommentID = Events.Save.shortGuid(); |
345 |
|
346 |
ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo); |
347 |
ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo); |
348 |
|
349 |
adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo); |
350 |
|
351 |
multi_Undo_Data = this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo); |
352 |
|
353 |
UndoData.Markup_List.Add(multi_Undo_Data); |
354 |
ViewerDataModel.Instance.UndoDataList.Add(UndoData); |
355 |
} |
356 |
} |
357 |
Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet); |
358 |
|
359 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
360 |
} |
361 |
} |
362 |
} |
363 |
#endregion |
364 |
|
365 |
#region Symbol Rename Event |
366 |
private void Rename_Symbol(object sender, RoutedEventArgs e) |
367 |
{ |
368 |
if (lstSymbolPrivate.SelectedItem == null) |
369 |
{ |
370 |
DialogMessage_Alert("Please Select Symbol", "Alert"); |
371 |
return; |
372 |
} |
373 |
|
374 |
DialogParameters parameters = new DialogParameters() |
375 |
{ |
376 |
Closed = (obj, args) => this.MarkupReNamePromptClose("", args), |
377 |
//DefaultPromptResultValue = "Custom State", |
378 |
DefaultPromptResultValue = (lstSymbolPrivate.SelectedItem as Symbol_Custom).Name, |
379 |
Content = "Name :", |
380 |
Header = "Update Custom Symbol Name", |
381 |
Theme = new VisualStudio2013Theme(), |
382 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
383 |
}; |
384 |
RadWindow.Prompt(parameters); |
385 |
|
386 |
} |
387 |
#endregion |
388 |
|
389 |
#region Symbol Rename Close Event |
390 |
private void MarkupReNamePromptClose(string data, WindowClosedEventArgs args) |
391 |
{ |
392 |
if (args.DialogResult != null && args.DialogResult.Value) |
393 |
{ |
394 |
using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
395 |
{ |
396 |
string ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID; |
397 |
var UpdateItem = Entity.SYMBOL_PRIVATE.Where(info => info.ID == ID).FirstOrDefault(); |
398 |
|
399 |
UpdateItem.NAME = args.PromptResult; |
400 |
Entity.SaveChanges(); |
401 |
DataBind(); |
402 |
//args.PromptResult |
403 |
} |
404 |
} |
405 |
} |
406 |
#endregion |
407 |
|
408 |
#region Wheel Event |
409 |
private void lstSymbolPrivate_PreviewMouseWheel(object sender, MouseWheelEventArgs e) |
410 |
{ |
411 |
ScView.ScrollToVerticalOffset(ScView.ContentVerticalOffset - (e.Delta / 2)); |
412 |
} |
413 |
private void lstSymbolPublic_PreviewMouseWheel(object sender, MouseWheelEventArgs e) |
414 |
{ |
415 |
ScView_Public.ScrollToVerticalOffset(ScView_Public.ContentVerticalOffset - (e.Delta / 2)); |
416 |
} |
417 |
#endregion |
418 |
|
419 |
#region Tab Selection Event |
420 |
private void RadTabControl_PreviewSelectionChanged(object sender, RadSelectionChangedEventArgs e) |
421 |
{ |
422 |
foreach (var item in (e.OriginalSource as RadTabControl).Items) |
423 |
{ |
424 |
(item as RadTabItem).FontWeight = FontWeights.Normal; |
425 |
} |
426 |
((e.OriginalSource as RadTabControl).SelectedItem as RadTabItem).FontWeight = FontWeights.Bold; |
427 |
} |
428 |
#endregion |
429 |
|
430 |
#region Department Selection Event |
431 |
private void deptlist_SelectionChanged(object sender, SelectionChangedEventArgs e) |
432 |
{ |
433 |
DataBind(); |
434 |
} |
435 |
#endregion |
436 |
|
437 |
#endregion |
438 |
|
439 |
private void lstSymbolPrivate_PreviewMouseUp(object sender, MouseButtonEventArgs e) |
440 |
{ |
441 |
|
442 |
} |
443 |
|
444 |
private void lstSymbolPrivate_MouseLeave(object sender, MouseEventArgs e) |
445 |
{ |
446 |
|
447 |
} |
448 |
|
449 |
private void lstSymbolPrivate_MouseDown(object sender, MouseButtonEventArgs e) |
450 |
{ |
451 |
|
452 |
} |
453 |
|
454 |
private void StackPanel_MouseLeave(object sender, MouseEventArgs e) |
455 |
{ |
456 |
if(IsMouseDown && e.LeftButton == MouseButtonState.Pressed) |
457 |
{ |
458 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.Symbol_ID = moveItem_id; |
459 |
} |
460 |
else |
461 |
{ |
462 |
IsMouseDown = false; |
463 |
} |
464 |
} |
465 |
|
466 |
private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e) |
467 |
{ |
468 |
IsMouseDown = false; |
469 |
} |
470 |
} |
471 |
} |