markus / KCOM_API_AutoStamping / AutoStamping.svc.cs @ 95e6fe93
이력 | 보기 | 이력해설 | 다운로드 (32.5 KB)
1 |
using IFinalPDF; |
---|---|
2 |
using KCOMDataModel.Common; |
3 |
using KCOMDataModel.DataModel; |
4 |
using log4net; |
5 |
using log4net.Config; |
6 |
using MarkupToPDF.Controls.Etc; |
7 |
using MarkupToPDF.Controls.Shape; |
8 |
using MarkupToPDF.Controls.Text; |
9 |
using System; |
10 |
using System.Collections.Generic; |
11 |
using System.Configuration; |
12 |
using System.Linq; |
13 |
using System.Runtime.Remoting.Channels.Tcp; |
14 |
using System.Runtime.Serialization; |
15 |
using System.ServiceModel; |
16 |
using System.ServiceModel.Activation; |
17 |
using System.ServiceModel.Web; |
18 |
using System.Text; |
19 |
using System.Threading; |
20 |
using System.Windows; |
21 |
using System.Windows.Controls; |
22 |
using System.Windows.Threading; |
23 |
|
24 |
namespace KCOM_API |
25 |
{ |
26 |
[ServiceContract(Namespace = "")] |
27 |
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] |
28 |
//[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.PerCall)] |
29 |
public class Common : System.Web.Services.WebService |
30 |
{ |
31 |
private static log4net.ILog logger; |
32 |
|
33 |
public Common() |
34 |
{ |
35 |
XmlConfigurator.Configure(); |
36 |
//Get logger |
37 |
logger = LogManager.GetLogger(typeof(Common)); |
38 |
//Start logging |
39 |
logger.Info("KCOM_API Common Call"); |
40 |
} |
41 |
|
42 |
|
43 |
[OperationContract] |
44 |
public string AutoStamping(string project_no, string slip_no, string user_id) |
45 |
{ |
46 |
string result = string.Empty; |
47 |
try |
48 |
{ |
49 |
var waiter = new ManualResetEvent(false); |
50 |
|
51 |
var staThread = new Thread(() => |
52 |
{ |
53 |
result = StampSave(project_no, slip_no, user_id); |
54 |
|
55 |
waiter.Set(); |
56 |
}); |
57 |
|
58 |
staThread.SetApartmentState(ApartmentState.STA); |
59 |
staThread.Start(); |
60 |
|
61 |
var timeout = new TimeSpan(0,1,0); |
62 |
waiter.WaitOne(timeout); |
63 |
} |
64 |
catch (Exception exception) |
65 |
{ |
66 |
logger.Error(exception); |
67 |
|
68 |
result = exception.ToString(); |
69 |
} |
70 |
return result; |
71 |
} |
72 |
|
73 |
[OperationContract] |
74 |
public ProjectInfo[] GetProjectList() |
75 |
{ |
76 |
ProjectInfo[] result = null; |
77 |
|
78 |
try |
79 |
{ |
80 |
using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
81 |
{ |
82 |
result = _entity.RUN_PROJECTS.Where(p=>p.PROJECT_NO != "000000").ToList().Select(x => new ProjectInfo { No = x.PROJECT_NO, Name = $"{x.PROJECT_NO} - {x.PROJECT_NAME}"}).ToArray(); |
83 |
} |
84 |
|
85 |
} |
86 |
catch (Exception) |
87 |
{ |
88 |
} |
89 |
|
90 |
return result; |
91 |
} |
92 |
|
93 |
/// <summary> |
94 |
/// 심볼로 변경 |
95 |
/// </summary> |
96 |
/// <param name="project_no"></param> |
97 |
/// <param name="slip_no"></param> |
98 |
/// <param name="user_id"></param> |
99 |
private string StampSave(string project_no, string slip_no, string user_id) |
100 |
{ |
101 |
string result = string.Empty; |
102 |
try |
103 |
{ |
104 |
logger.Info($"Stamp ProjecNO : {project_no} SlipNO : {slip_no} UserID : {user_id}"); |
105 |
|
106 |
string _stampData = null; |
107 |
|
108 |
using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
109 |
{ |
110 |
var stamp = _entity.PROPERTIES.Where(x=> x.TYPE == "STAMP"); |
111 |
|
112 |
if(stamp.Count() > 0) |
113 |
{ |
114 |
_stampData = stamp.First().VALUE; |
115 |
} |
116 |
else |
117 |
{ |
118 |
result = "STAMP IS NULL."; |
119 |
} |
120 |
}; |
121 |
|
122 |
if (_stampData != null) |
123 |
{ |
124 |
using (CIEntities cIEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString())) |
125 |
{ |
126 |
logger.Info($"Connection CI DataBase :{cIEntity.Connection.Database} DataSource :{cIEntity.Connection.DataSource}"); |
127 |
|
128 |
var list = (from doc in cIEntity.DOCUMENT_ITEM |
129 |
where doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no |
130 |
select doc).ToList(); |
131 |
|
132 |
string userName = null; |
133 |
|
134 |
var user = GetSelectMember(cIEntity, project_no, slip_no, user_id); |
135 |
|
136 |
if (user.SLIP_COUNT == 0) |
137 |
{ |
138 |
result = "Slip No does not exist."; |
139 |
} |
140 |
else |
141 |
{ |
142 |
if (user.IS_ORIGINATOR == 0) |
143 |
{ |
144 |
result = "User ID is not the Originator for that Slip No."; |
145 |
} |
146 |
else |
147 |
{ |
148 |
if (user.USER_NAME == null) |
149 |
{ |
150 |
result = "user name IS NULL."; |
151 |
} |
152 |
else |
153 |
{ |
154 |
userName = user.USER_NAME; |
155 |
|
156 |
foreach (DOCUMENT_ITEM dOCUMENTITEM in list) |
157 |
{ |
158 |
DOCINFO dOCINFO = ( |
159 |
from x in cIEntity.DOCINFO |
160 |
where x.PROJECT_NO == project_no && x.DOCUMENT_ID == dOCUMENTITEM.DOCUMENT_ID |
161 |
select x).FirstOrDefault<DOCINFO>(); |
162 |
|
163 |
MARKUP_INFO mARKUPINFO = ( |
164 |
from x in cIEntity.MARKUP_INFO |
165 |
where x.DOCINFO_ID == dOCINFO.ID && x.AVOID_CONSOLIDATE == 0 && x.CONSOLIDATE == 1 |
166 |
select x).FirstOrDefault<MARKUP_INFO>(); |
167 |
|
168 |
if (mARKUPINFO == null) |
169 |
{ |
170 |
var pageInfo = dOCINFO.DOCPAGE.First(); |
171 |
|
172 |
mARKUPINFO = new MARKUP_INFO() |
173 |
{ |
174 |
ID = shortGuid(), |
175 |
DOCINFO_ID = dOCINFO.ID, |
176 |
USER_ID = user_id, |
177 |
CREATE_TIME = DateTime.Now, |
178 |
CONSOLIDATE = 1, |
179 |
AVOID_CONSOLIDATE = 0, |
180 |
PART_CONSOLIDATE = 0, |
181 |
DESCRIPTION = "", |
182 |
UPDATE_TIME = new DateTime?(DateTime.Now), |
183 |
}; |
184 |
|
185 |
cIEntity.MARKUP_INFO.AddObject(mARKUPINFO); |
186 |
|
187 |
MARKUP_INFO_VERSION mARKUPINFOVERSION = new MARKUP_INFO_VERSION() |
188 |
{ |
189 |
ID = shortGuid(), |
190 |
MARKUPINFO_ID = mARKUPINFO.ID, |
191 |
CREATE_DATE = DateTime.Now |
192 |
}; |
193 |
|
194 |
cIEntity.MARKUP_INFO_VERSION.AddObject(mARKUPINFOVERSION); |
195 |
|
196 |
Point startPoint = new Point(30, 30); |
197 |
|
198 |
var symCtrl = GetSymNControl(Convert.ToDouble(pageInfo.PAGE_WIDTH), Convert.ToDouble(pageInfo.PAGE_HEIGHT), mARKUPINFO.USER_ID, mARKUPINFO.ID, startPoint, _stampData); |
199 |
|
200 |
var bottom = Rect.Offset(symCtrl.ItemRect, new Vector(0, symCtrl.ItemRect.Height)); |
201 |
|
202 |
var txtOriginator = GetTextControl(Convert.ToDouble(pageInfo.PAGE_WIDTH), Convert.ToDouble(pageInfo.PAGE_HEIGHT), mARKUPINFO.USER_ID, mARKUPINFO.ID |
203 |
, userName, 36, System.Windows.Media.Color.FromArgb(255, 0, 0, 255), FontWeights.Bold, TextAlignment.Center, bottom, bottom.Top + 3); |
204 |
|
205 |
var dtfi = new System.Globalization.DateTimeFormatInfo { DateSeparator = "-", ShortDatePattern = @"yyyy/MM/dd" }; |
206 |
|
207 |
var txtDate = GetTextControl(Convert.ToDouble(pageInfo.PAGE_WIDTH), Convert.ToDouble(pageInfo.PAGE_HEIGHT), mARKUPINFO.USER_ID, mARKUPINFO.ID |
208 |
, DateTime.Now.ToString("d", dtfi), 36, System.Windows.Media.Color.FromArgb(255, 255, 0, 0), FontWeights.Bold, TextAlignment.Center, bottom, txtOriginator.StartPoint.Y + txtOriginator.BoxHeight + 2); |
209 |
|
210 |
var symData = symCtrl.GetMarkupData(mARKUPINFO.USER_ID, 1, mARKUPINFOVERSION.ID); |
211 |
cIEntity.MARKUP_DATA.AddObject(symData); |
212 |
cIEntity.MARKUP_DATA.AddObject(txtOriginator.GetMarkupData(mARKUPINFO.USER_ID, 1, mARKUPINFOVERSION.ID)); |
213 |
cIEntity.MARKUP_DATA.AddObject(txtDate.GetMarkupData(mARKUPINFO.USER_ID, 1, mARKUPINFOVERSION.ID)); |
214 |
} |
215 |
cIEntity.SaveChanges(); |
216 |
|
217 |
|
218 |
this.SetFinalPDF(project_no, dOCINFO.ID, mARKUPINFO.ID, user_id); |
219 |
} |
220 |
} |
221 |
} |
222 |
} |
223 |
} |
224 |
} |
225 |
|
226 |
} |
227 |
catch (Exception ex) |
228 |
{ |
229 |
logger.Error($"StampSave ProjectNO : {project_no} slipNo : {slip_no} userID : {user_id}" + ex); |
230 |
result = "Stamp Save Error"; |
231 |
} |
232 |
|
233 |
return result; |
234 |
} |
235 |
|
236 |
private List<MEMBER> GetMemberQuery(System.Data.Objects.ObjectContext context, string UserID) |
237 |
{ |
238 |
List<MEMBER> result = new List<MEMBER>(); |
239 |
|
240 |
try |
241 |
{ |
242 |
string query = "SELECT members.ID,members.NAME,members.DEPARTMENT FROM CIEntities.MEMBER as members where members.ID = @userId"; |
243 |
|
244 |
var param = new[] { new System.Data.Objects.ObjectParameter("userId", UserID) }; |
245 |
|
246 |
System.Data.Objects.ObjectQuery<System.Data.Common.DbDataRecord> memberQuery |
247 |
= context.CreateQuery<System.Data.Common.DbDataRecord>(query, param); |
248 |
|
249 |
if (memberQuery.Count() > 0) |
250 |
{ |
251 |
foreach (var dataRecord in memberQuery) |
252 |
{ |
253 |
MEMBER member = new MEMBER(); |
254 |
|
255 |
string userName = dataRecord["NAME"]?.ToString().Trim(); |
256 |
string ID = dataRecord["ID"]?.ToString().Trim(); |
257 |
string depatment = dataRecord["DEPARTMENT"]?.ToString().Trim(); |
258 |
|
259 |
member.NAME = userName; |
260 |
member.ID = ID; |
261 |
member.DEPARTMENT = depatment; |
262 |
|
263 |
result.Add(member); |
264 |
} |
265 |
} |
266 |
} |
267 |
catch (Exception ex) |
268 |
{ |
269 |
throw new Exception("GetMember(System.Data.Objects.ObjectContext context, string UserID) ", ex); |
270 |
} |
271 |
|
272 |
return result; |
273 |
} |
274 |
|
275 |
private SelectMember GetSelectMember(System.Data.Objects.ObjectContext context,string ProjectNo,string SlipNo, string UserID) |
276 |
{ |
277 |
SelectMember result = new SelectMember(); |
278 |
|
279 |
try |
280 |
{ |
281 |
string query = "SELECT_SLIP_ORIGINATOR @P_PROJECT_NO = @ProjectNo , @P_SLIP_NO = @SlipNo ,@P_USER_ID = @UserID"; |
282 |
|
283 |
var param = new[]{ |
284 |
new System.Data.SqlClient.SqlParameter("ProjectNo", ProjectNo), |
285 |
new System.Data.SqlClient.SqlParameter("SlipNo", SlipNo), |
286 |
new System.Data.SqlClient.SqlParameter("UserID", UserID) |
287 |
|
288 |
}; |
289 |
|
290 |
//var memberQuery = context.ExecuteStoreQuery<System.Data.Common.DbDataRecord>(query, param).ToList(); |
291 |
|
292 |
//if (memberQuery.Count() > 0) |
293 |
//{ |
294 |
// result.USER_NAME = memberQuery.First()["USER_NAME"]?.ToString(); |
295 |
// result.IS_ORIGINATOR = Convert.ToInt32(memberQuery.First()["IS_ORIGINATOR"]); |
296 |
//} |
297 |
|
298 |
var memberQuery = context.ExecuteStoreQuery<SelectMember>(query, param).ToList(); |
299 |
|
300 |
if (memberQuery.Count() > 0) |
301 |
{ |
302 |
result = memberQuery.First(); |
303 |
} |
304 |
} |
305 |
catch (Exception ex) |
306 |
{ |
307 |
throw new Exception("GetMember(System.Data.Objects.ObjectContext context, string UserID) ", ex); |
308 |
} |
309 |
|
310 |
return result; |
311 |
} |
312 |
|
313 |
private void StampSave_NoneSymbol(string project_no, string slip_no, string user_id) |
314 |
{ |
315 |
try |
316 |
{ |
317 |
logger.Info($"Stamp ProjecNO : {project_no} SlipNO : {slip_no} UserID : {user_id}"); |
318 |
|
319 |
using (CIEntities cIEntity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(project_no).ToString())) |
320 |
{ |
321 |
logger.Info($"Connection CI DataBase :{cIEntity.Connection.Database} DataSource :{cIEntity.Connection.DataSource}"); |
322 |
|
323 |
var list = (from doc in cIEntity.DOCUMENT_ITEM |
324 |
where doc.GROUP_NO == slip_no && doc.PROJECT_NO == project_no |
325 |
select doc).ToList(); |
326 |
|
327 |
foreach (DOCUMENT_ITEM dOCUMENTITEM in list) |
328 |
{ |
329 |
DOCINFO dOCINFO = ( |
330 |
from x in cIEntity.DOCINFO |
331 |
where x.PROJECT_NO == project_no && x.DOCUMENT_ID == dOCUMENTITEM.DOCUMENT_ID |
332 |
select x).FirstOrDefault<DOCINFO>(); |
333 |
|
334 |
MARKUP_INFO mARKUPINFO = ( |
335 |
from x in cIEntity.MARKUP_INFO |
336 |
where x.DOCINFO_ID == dOCINFO.ID && x.AVOID_CONSOLIDATE == 0 && x.CONSOLIDATE == 1 |
337 |
select x).FirstOrDefault<MARKUP_INFO>(); |
338 |
|
339 |
if (mARKUPINFO == null) |
340 |
{ |
341 |
var pageInfo = dOCINFO.DOCPAGE.First(); |
342 |
|
343 |
mARKUPINFO = new MARKUP_INFO() |
344 |
{ |
345 |
ID = shortGuid(), |
346 |
DOCINFO_ID = dOCINFO.ID, |
347 |
USER_ID = user_id, |
348 |
CREATE_TIME = DateTime.Now, |
349 |
CONSOLIDATE = 1, |
350 |
AVOID_CONSOLIDATE = 0, |
351 |
PART_CONSOLIDATE = 0, |
352 |
DESCRIPTION = "", |
353 |
UPDATE_TIME = new DateTime?(DateTime.Now), |
354 |
}; |
355 |
|
356 |
cIEntity.MARKUP_INFO.AddObject(mARKUPINFO); |
357 |
|
358 |
MARKUP_INFO_VERSION mARKUPINFOVERSION = new MARKUP_INFO_VERSION() |
359 |
{ |
360 |
ID = shortGuid(), |
361 |
MARKUPINFO_ID = mARKUPINFO.ID, |
362 |
CREATE_DATE = DateTime.Now |
363 |
}; |
364 |
|
365 |
cIEntity.MARKUP_INFO_VERSION.AddObject(mARKUPINFOVERSION); |
366 |
|
367 |
Point startPoint = new Point(15, 15); |
368 |
|
369 |
var rect = Common.GetRectControl(Convert.ToDouble(pageInfo.PAGE_WIDTH), Convert.ToDouble(pageInfo.PAGE_HEIGHT), |
370 |
mARKUPINFO.USER_ID, mARKUPINFO.ID, startPoint); |
371 |
|
372 |
var txtApproved = GetTextControl(Convert.ToDouble(pageInfo.PAGE_WIDTH), Convert.ToDouble(pageInfo.PAGE_HEIGHT), mARKUPINFO.USER_ID, mARKUPINFO.ID, |
373 |
"APPROVED", 30, System.Windows.Media.Color.FromArgb(255, 255, 0, 0), FontWeights.Bold, TextAlignment.Center, rect.ItemRect, 18); |
374 |
|
375 |
var txtCreator = GetTextControl(Convert.ToDouble(pageInfo.PAGE_WIDTH), Convert.ToDouble(pageInfo.PAGE_HEIGHT), mARKUPINFO.USER_ID, mARKUPINFO.ID |
376 |
, "By HYOSUNG", 18, System.Windows.Media.Color.FromArgb(255, 255, 0, 0), FontWeights.Bold, TextAlignment.Center, rect.ItemRect, txtApproved.StartPoint.Y + txtApproved.BoxHeight + 3); |
377 |
|
378 |
var bottom = Rect.Offset(rect.ItemRect, new Vector(0, rect.ItemRect.Height)); |
379 |
|
380 |
var txtOriginator = GetTextControl(Convert.ToDouble(pageInfo.PAGE_WIDTH), Convert.ToDouble(pageInfo.PAGE_HEIGHT), mARKUPINFO.USER_ID, mARKUPINFO.ID |
381 |
, mARKUPINFO.USER_ID, 18,System.Windows.Media.Color.FromArgb(255, 255, 0, 0), FontWeights.Bold, TextAlignment.Left, bottom, bottom.Top + 3); |
382 |
|
383 |
var dtfi = new System.Globalization.DateTimeFormatInfo { DateSeparator = "-", ShortDatePattern = @"yyyy/MM/dd" }; |
384 |
|
385 |
var txtDate = GetTextControl(Convert.ToDouble(pageInfo.PAGE_WIDTH), Convert.ToDouble(pageInfo.PAGE_HEIGHT), mARKUPINFO.USER_ID, mARKUPINFO.ID |
386 |
, DateTime.Now.ToString("d", dtfi), 18, System.Windows.Media.Color.FromArgb(255, 255, 0, 0), FontWeights.Bold, TextAlignment.Left, bottom, txtOriginator.StartPoint.Y + txtOriginator.BoxHeight + 2); |
387 |
|
388 |
var rectData = rect.GetMarkupData(mARKUPINFO.USER_ID, 1, mARKUPINFOVERSION.ID); |
389 |
cIEntity.MARKUP_DATA.AddObject(rectData); |
390 |
|
391 |
cIEntity.MARKUP_DATA.AddObject(txtApproved.GetMarkupData(mARKUPINFO.USER_ID, 1, mARKUPINFOVERSION.ID)); |
392 |
cIEntity.MARKUP_DATA.AddObject(txtCreator.GetMarkupData(mARKUPINFO.USER_ID, 1, mARKUPINFOVERSION.ID)); |
393 |
cIEntity.MARKUP_DATA.AddObject(txtOriginator.GetMarkupData(mARKUPINFO.USER_ID, 1, mARKUPINFOVERSION.ID)); |
394 |
cIEntity.MARKUP_DATA.AddObject(txtDate.GetMarkupData(mARKUPINFO.USER_ID, 1, mARKUPINFOVERSION.ID)); |
395 |
} |
396 |
cIEntity.SaveChanges(); |
397 |
|
398 |
|
399 |
this.SetFinalPDF(project_no, dOCINFO.ID, mARKUPINFO.ID, user_id); |
400 |
} |
401 |
} |
402 |
|
403 |
} |
404 |
catch (Exception ex) |
405 |
{ |
406 |
logger.Error($"StampSave ProjectNO : {project_no} slipNo : {slip_no} userID : {user_id}" + ex); |
407 |
} |
408 |
} |
409 |
|
410 |
private static string shortGuid() |
411 |
{ |
412 |
byte[] bytes = new byte[16]; |
413 |
using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create()) |
414 |
{ |
415 |
provider.GetBytes(bytes); |
416 |
} |
417 |
|
418 |
var guid = new Guid(bytes); |
419 |
|
420 |
return Convert.ToBase64String(guid.ToByteArray()) |
421 |
.Substring(0, 10) |
422 |
.Replace("/", "") |
423 |
.Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x"); |
424 |
} |
425 |
|
426 |
private SymControlN GetSymNControl(double PageWidth, double PageHeight, string userId, string markupInfoId, Point startPosition,string StampData) |
427 |
{ |
428 |
SymControlN result = null; |
429 |
|
430 |
try |
431 |
{ |
432 |
double height = 110; |
433 |
double itemWidth = 280; |
434 |
|
435 |
System.Windows.Point startPoint = new System.Windows.Point(startPosition.X, startPosition.Y); |
436 |
System.Windows.Point endPoint = new System.Windows.Point(startPosition.X + itemWidth, startPosition.Y + height); |
437 |
System.Windows.Point leftBottomPoint = new System.Windows.Point(startPosition.X, startPosition.Y + height); |
438 |
System.Windows.Point topRightPoint = new System.Windows.Point(startPosition.X + itemWidth, startPosition.Y); |
439 |
|
440 |
result = new SymControlN |
441 |
{ |
442 |
CommentID = shortGuid(), |
443 |
MarkupInfoID = markupInfoId, |
444 |
UserID = userId, |
445 |
PointSet = new List<Point> { startPoint, leftBottomPoint, endPoint, topRightPoint }, |
446 |
StartPoint = startPoint, |
447 |
EndPoint = endPoint, |
448 |
CommentAngle = 0, |
449 |
LeftBottomPoint = leftBottomPoint, |
450 |
TopRightPoint = topRightPoint, |
451 |
Opacity = 1, |
452 |
PathXathData = StampData, |
453 |
Memo = null |
454 |
}; |
455 |
|
456 |
} |
457 |
catch (Exception ex) |
458 |
{ |
459 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
460 |
} |
461 |
|
462 |
return result; |
463 |
} |
464 |
|
465 |
|
466 |
private static RectangleControl GetRectControl(double PageWidth, double PageHeight, string USER_ID, string markupInfoId, Point startPosition) |
467 |
{ |
468 |
RectangleControl result = null; |
469 |
|
470 |
try |
471 |
{ |
472 |
double height = 80; |
473 |
double itemWidth = 180; |
474 |
|
475 |
System.Windows.Point startPoint = new System.Windows.Point(startPosition.X, startPosition.Y); |
476 |
System.Windows.Point endPoint = new System.Windows.Point(startPosition.X + itemWidth, startPosition.Y + height); |
477 |
System.Windows.Point leftBottomPoint = new System.Windows.Point(startPosition.X, startPosition.Y + height); |
478 |
System.Windows.Point topRightPoint = new System.Windows.Point(startPosition.X + itemWidth, startPosition.Y); |
479 |
|
480 |
result = new RectangleControl |
481 |
{ |
482 |
CommentID = shortGuid(), |
483 |
MarkupInfoID = markupInfoId, |
484 |
LineSize = 5, |
485 |
Paint = MarkupToPDF.Controls.Common.PaintSet.None, |
486 |
StartPoint = startPoint, |
487 |
EndPoint = endPoint, |
488 |
CommentAngle = 0, |
489 |
StrokeColor = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0x0, 0x0)), |
490 |
//StrokeColor = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 64, 224, 208)), |
491 |
FillColor = null, |
492 |
DashSize = new System.Windows.Media.DoubleCollection(new[] { 999999.0 }), |
493 |
Opacity = 1, |
494 |
LeftBottomPoint = leftBottomPoint, |
495 |
TopRightPoint = topRightPoint, |
496 |
PointSet = new List<Point> { startPoint, leftBottomPoint, endPoint, topRightPoint }, |
497 |
UserID = USER_ID, |
498 |
Memo = null, |
499 |
SymbolID = null |
500 |
|
501 |
}; |
502 |
} |
503 |
catch (Exception ex) |
504 |
{ |
505 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
506 |
} |
507 |
|
508 |
return result; |
509 |
} |
510 |
|
511 |
[STAThread] |
512 |
private static TextControl GetTextControl(double PageWidth, double PageHeight, string USER_ID, string markupInfoId, |
513 |
string Text, double fontSize, System.Windows.Media.Color Foreground, FontWeight fontWeight, TextAlignment textAlignment, Rect parentRect, double positionY) |
514 |
{ |
515 |
TextControl result = null; |
516 |
|
517 |
try |
518 |
{ |
519 |
|
520 |
var txtSize = ShapeMeasure(new TextBlock |
521 |
{ |
522 |
Text = Text, |
523 |
FontSize = fontSize, |
524 |
FontWeight = fontWeight, |
525 |
FontFamily = new System.Windows.Media.FontFamily("Arial") |
526 |
}); |
527 |
|
528 |
double startPositionX = parentRect.X; |
529 |
|
530 |
switch (textAlignment) |
531 |
{ |
532 |
case TextAlignment.Right: |
533 |
startPositionX = parentRect.X + parentRect.Width - txtSize.Width; |
534 |
break; |
535 |
case TextAlignment.Center: |
536 |
startPositionX = parentRect.X + parentRect.Width / 2 - txtSize.Width / 2; |
537 |
break; |
538 |
} |
539 |
|
540 |
Point startPosition = new Point |
541 |
{ |
542 |
X = startPositionX, |
543 |
Y = positionY |
544 |
}; |
545 |
|
546 |
System.Windows.Point startPoint = new System.Windows.Point(startPosition.X, startPosition.Y); |
547 |
System.Windows.Point endPoint = new System.Windows.Point(startPosition.X + txtSize.Width, startPosition.Y + txtSize.Height); |
548 |
System.Windows.Point leftBottomPoint = new System.Windows.Point(startPosition.X, startPosition.Y + txtSize.Height); |
549 |
System.Windows.Point topRightPoint = new System.Windows.Point(startPosition.X + txtSize.Width, startPosition.Y); |
550 |
|
551 |
result = new TextControl |
552 |
{ |
553 |
CommentID = shortGuid(), |
554 |
MarkupInfoID = markupInfoId, |
555 |
Text = Text, |
556 |
StartPoint = startPoint, |
557 |
EndPoint = endPoint, |
558 |
CanvasX = startPosition.X, |
559 |
CanvasY = startPosition.Y, |
560 |
BoxWidth = txtSize.Width, |
561 |
BoxHeight = txtSize.Height, |
562 |
ControlType_No = 0, |
563 |
LineSize = new Thickness(5), |
564 |
TextSize = fontSize, |
565 |
Foreground = new System.Windows.Media.SolidColorBrush(Foreground), |
566 |
FontSize = 10, |
567 |
UserID = USER_ID, |
568 |
IsHighLight = false, |
569 |
CommentAngle = 0, |
570 |
PointSet = new List<Point>(), |
571 |
Opacity = 1, |
572 |
IsSelected = false, |
573 |
TextFamily = new System.Windows.Media.FontFamily("Arial"), |
574 |
TextStyle = FontStyles.Normal, |
575 |
TextWeight = FontWeights.Bold |
576 |
}; |
577 |
|
578 |
} |
579 |
catch (Exception ex) |
580 |
{ |
581 |
throw new Exception("Text Control error"); |
582 |
} |
583 |
|
584 |
return result; |
585 |
} |
586 |
public static Size ShapeMeasure(UIElement e) |
587 |
{ |
588 |
// Measured Size is bounded to be less than maxSize |
589 |
Size maxSize = new Size( |
590 |
double.PositiveInfinity, |
591 |
double.PositiveInfinity); |
592 |
e.Measure(maxSize); |
593 |
return e.DesiredSize; |
594 |
} |
595 |
private void SetTextControl(TextControl textControl) |
596 |
{ |
597 |
textControl.Base_TextBlock.Margin = new Thickness(0, 0, 10, 0); |
598 |
textControl.Base_TextBox.Visibility = Visibility.Collapsed; |
599 |
textControl.Base_TextBlock.Visibility = Visibility.Visible; |
600 |
|
601 |
} |
602 |
|
603 |
#region Final PDF |
604 |
private string _ChanID = null; |
605 |
TcpChannel chan = null; |
606 |
|
607 |
[OperationContract] |
608 |
public FinalPDFResult SetFinalPDF(string ProjectNo, string DocInfoID, string MarkupInfoID, string CreateUSER_ID) |
609 |
{ |
610 |
#region 임시보관 |
611 |
#endregion |
612 |
FinalPDFResult _result = new FinalPDFResult(); |
613 |
RemFinalPDFObject remObj = null; |
614 |
try |
615 |
{ |
616 |
string _finalID = shortGuid(); |
617 |
int _DocTotalPages = -1; |
618 |
string docItemId; |
619 |
|
620 |
logger.Info($"SetFinalPDF ProjectNo :{ProjectNo} DocInfoID :{DocInfoID} MarkupInfoID:{MarkupInfoID} CreateUSER_ID:{CreateUSER_ID}"); |
621 |
|
622 |
//string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString; |
623 |
using (CIEntities _ci = new CIEntities(ConnectStringBuilder.ProjectCIConnectString(ProjectNo).ToString())) |
624 |
{ |
625 |
logger.Info($"Connection CI DataBase :{_ci.Connection.Database} DataSource :{_ci.Connection.DataSource}"); |
626 |
var _doc = _ci.DOCINFO.Where(info => info.ID == DocInfoID); |
627 |
|
628 |
if (_doc.Count() > 0) |
629 |
{ |
630 |
_DocTotalPages = _doc.First().PAGE_COUNT; |
631 |
docItemId = _doc.First().DOCUMENT_ID; |
632 |
} |
633 |
else |
634 |
{ |
635 |
_result.Status = FinalStatus.Error; |
636 |
_result.Exception = "페이지 정보를 가져올 수 없습니다."; |
637 |
return _result; |
638 |
} |
639 |
} |
640 |
if (_DocTotalPages > 0) |
641 |
{ |
642 |
FINAL_PDF fm = new FINAL_PDF() |
643 |
{ |
644 |
ID = _finalID, |
645 |
PROJECT_NO = ProjectNo, |
646 |
DOCINFO_ID = DocInfoID, |
647 |
DOCUMENT_ID = docItemId, |
648 |
MARKUPINFO_ID = MarkupInfoID, |
649 |
CREATE_USER_ID = CreateUSER_ID, |
650 |
TOTAL_PAGE = _DocTotalPages, |
651 |
CREATE_DATETIME = DateTime.Now, |
652 |
STATUS = (int)IFinalPDF.FinalStatus.Insert |
653 |
}; |
654 |
|
655 |
//string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; |
656 |
using (KCOMEntities _entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
657 |
{ |
658 |
logger.Info($"Connection KCOM DataBase :{_entity.Connection.Database} DataSource :{_entity.Connection.DataSource}"); |
659 |
|
660 |
_entity.AddToFINAL_PDF(fm); |
661 |
_entity.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave); |
662 |
}; |
663 |
|
664 |
System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp"); |
665 |
if (_ch == null) |
666 |
{ |
667 |
chan = new TcpChannel(); |
668 |
_ChanID = chan.ChannelName; |
669 |
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false); |
670 |
// Create an instance of the remote object |
671 |
|
672 |
using (KCOMEntities ec = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString())) |
673 |
{ |
674 |
|
675 |
//remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject), |
676 |
// "tcp://localhost:9092/remFinalPDF"); |
677 |
remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject), |
678 |
//"tcp://192.168.0.67:9092/remFinalPDF"); |
679 |
"tcp://localhost:9092/remFinalPDF"); |
680 |
} |
681 |
|
682 |
//"tcp://localhost:8080/remFinalPDF"); |
683 |
|
684 |
_result = remObj.SetFinalPDF(ProjectNo, _finalID); |
685 |
_result.FinalID = _finalID; |
686 |
_result.Status = FinalStatus.Success; |
687 |
|
688 |
//MarkupToPDF.MarkupToPDF fa = new MarkupToPDF.MarkupToPDF(); |
689 |
//fa.MakeFinalPDF(fm); |
690 |
} |
691 |
else |
692 |
{ |
693 |
_ChanID = _ch.ChannelName; |
694 |
} |
695 |
} |
696 |
} |
697 |
catch (Exception ex) |
698 |
{ |
699 |
logger.Error($"SetFinalPDF - " + ex); |
700 |
|
701 |
_result.Status = FinalStatus.Error; |
702 |
|
703 |
if (ex.GetType() == typeof(System.Net.Sockets.SocketException)) |
704 |
_result.Exception = "Final Server Not Connection"; |
705 |
else _result.Exception = ex.ToString(); |
706 |
} |
707 |
finally |
708 |
{ |
709 |
remObj = null; |
710 |
if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null) |
711 |
System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan); |
712 |
|
713 |
GC.Collect(2); |
714 |
} |
715 |
return _result; |
716 |
} |
717 |
#endregion |
718 |
|
719 |
} |
720 |
|
721 |
public class SelectMember |
722 |
{ |
723 |
public string USER_ID { get; set; } |
724 |
|
725 |
public string USER_NAME { get; set; } |
726 |
|
727 |
/// <summary> |
728 |
/// 0보다 크면 originator |
729 |
/// </summary> |
730 |
public int IS_ORIGINATOR { get; set; } |
731 |
|
732 |
/// <summary> |
733 |
/// 해당 SLIP NO가 있는지 |
734 |
/// </summary> |
735 |
public int SLIP_COUNT { get; set; } |
736 |
} |
737 |
|
738 |
|
739 |
[DataContract] |
740 |
public class ProjectInfo |
741 |
{ |
742 |
[DataMember] |
743 |
public string No { get; set; } |
744 |
|
745 |
[DataMember] |
746 |
public string Name { get; set; } |
747 |
} |
748 |
} |