hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 7cab536e
이력 | 보기 | 이력해설 | 다운로드 (24.9 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
|
7 |
using System.Data; |
8 |
|
9 |
using ID2.Manager.Data.Models; |
10 |
|
11 |
using Dapper; |
12 |
using System.ComponentModel; |
13 |
using System.Reflection; |
14 |
|
15 |
namespace ID2.Manager.Dapper.Repository |
16 |
{ |
17 |
public class DocumentRepository : BaseRepository |
18 |
{ |
19 |
public DocumentRepository(string connectionStr) : base(connectionStr) { } |
20 |
|
21 |
public IEnumerable<Documents> GetAllDocuments(string projectGroupID) |
22 |
{ |
23 |
var dynamicParameters = new DynamicParameters(); |
24 |
StringBuilder sbWhere = new StringBuilder(); |
25 |
var parameters = new Dictionary<string, object>(); |
26 |
if (!string.IsNullOrEmpty(projectGroupID)) |
27 |
{ |
28 |
sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) "); |
29 |
parameters.Add("RefGroupID", projectGroupID); |
30 |
} |
31 |
|
32 |
try |
33 |
{ |
34 |
string query = $@" |
35 |
select doc.* |
36 |
from dbo.Documents doc |
37 |
where doc.IsDeleted=0 {sbWhere} |
38 |
order by doc.Seq;"; |
39 |
|
40 |
if (parameters.Count > 0) |
41 |
{ |
42 |
dynamicParameters.AddDynamicParams(parameters); |
43 |
} |
44 |
|
45 |
return Query<Documents>(query, dynamicParameters); |
46 |
} |
47 |
catch (Exception ex) |
48 |
{ |
49 |
throw ex; |
50 |
} |
51 |
} |
52 |
static string GetDescriptionFromAttribute(MemberInfo member) |
53 |
{ |
54 |
if (member == null) return null; |
55 |
|
56 |
var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false); |
57 |
return (attrib?.Description ?? member.Name).ToLower(); |
58 |
} |
59 |
|
60 |
|
61 |
public (IEnumerable<Documents> dwgs, int totalCnt) GetDocuments(string projectGroupID, List<string> dateTypes, DateTime? frDate, DateTime? toDate, string projectCode, string personIncharge, string jobLevel, string documentNo, string isToIsDiscussion, string isFrReviewStatus, string isID2Work, string id2Status, string id2Issues, string avevaStatus, string avevaIssues, string prodIsResult, string clientIsResult, string isGateWay, string isRegSystem) |
62 |
{ |
63 |
var map = new CustomPropertyTypeMap(typeof(AttFileInfo), (type, columnName) |
64 |
=> type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName.ToLower())); |
65 |
SqlMapper.SetTypeMap(typeof(AttFileInfo), map); |
66 |
|
67 |
|
68 |
var dynamicParameters = new DynamicParameters(); |
69 |
dynamicParameters.Add("Total", dbType: DbType.Int32, direction: ParameterDirection.Output); |
70 |
|
71 |
StringBuilder sbWhere = new StringBuilder(); |
72 |
StringBuilder sbTotalWhere = new StringBuilder(); |
73 |
var parameters = new Dictionary<string, object>(); |
74 |
if (dateTypes.Count > 0 && (frDate != null || toDate != null)) |
75 |
{ |
76 |
List<string> subWheres = new List<string>(); |
77 |
foreach (string dateType in dateTypes) |
78 |
{ |
79 |
StringBuilder sbSubWhere = new StringBuilder(); |
80 |
if (frDate != null) |
81 |
{ |
82 |
sbSubWhere.Insert(0, $@"convert(datetime, '{Convert.ToDateTime(frDate).AddDays(-1):yyyy-MM-dd 23:59:59.997}') < doc.{dateType}"); |
83 |
} |
84 |
if (toDate != null) |
85 |
{ |
86 |
if (frDate != null) |
87 |
sbSubWhere.Append($@" and "); |
88 |
sbSubWhere.Append($@"doc.{dateType} < convert(datetime, '{Convert.ToDateTime(toDate).AddDays(1):yyyy-MM-dd 00:00:00.000}')"); |
89 |
} |
90 |
|
91 |
if (sbSubWhere.Length > 0) |
92 |
{ |
93 |
subWheres.Add("(" + sbSubWhere.ToString() + ")"); |
94 |
} |
95 |
} |
96 |
|
97 |
if (subWheres.Count > 0) |
98 |
{ |
99 |
sbWhere.Append(" and (" + string.Join(" or ", subWheres) + ") "); |
100 |
} |
101 |
} |
102 |
if (string.IsNullOrEmpty(projectCode)) |
103 |
{ |
104 |
sbWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
105 |
sbTotalWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
106 |
parameters.Add("RefGroupID", projectGroupID); |
107 |
} |
108 |
else |
109 |
{ |
110 |
sbTotalWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
111 |
parameters.Add("RefGroupID", projectGroupID); |
112 |
|
113 |
sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode "); |
114 |
parameters.Add("RefProjectCode", projectCode); |
115 |
} |
116 |
if (!string.IsNullOrEmpty(personIncharge)) |
117 |
{ |
118 |
sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge "); |
119 |
parameters.Add("PersonInCharge", personIncharge); |
120 |
} |
121 |
if (!string.IsNullOrEmpty(jobLevel)) |
122 |
{ |
123 |
sbWhere.Append(" and doc.JobLevel=@JobLevel "); |
124 |
parameters.Add("JobLevel", jobLevel); |
125 |
} |
126 |
if (!string.IsNullOrEmpty(documentNo)) |
127 |
{ |
128 |
sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' "); |
129 |
parameters.Add("DocumentNo", documentNo); |
130 |
} |
131 |
|
132 |
if (!string.IsNullOrEmpty(isToIsDiscussion)) |
133 |
{ |
134 |
sbWhere.Append(" and doc.ToIsDiscussion=@ToIsDiscussion "); |
135 |
parameters.Add("ToIsDiscussion", isToIsDiscussion); |
136 |
} |
137 |
|
138 |
if (!string.IsNullOrEmpty(isFrReviewStatus)) |
139 |
{ |
140 |
sbWhere.Append(" and doc.FrReviewStatus=@FrReviewStatus "); |
141 |
parameters.Add("FrReviewStatus", isFrReviewStatus); |
142 |
} |
143 |
|
144 |
if (!string.IsNullOrEmpty(isID2Work)) |
145 |
{ |
146 |
sbWhere.Append(" and doc.IsID2Work=@IsID2Work "); |
147 |
parameters.Add("IsID2Work", isID2Work); |
148 |
} |
149 |
|
150 |
if (!string.IsNullOrEmpty(id2Status)) |
151 |
{ |
152 |
sbWhere.Append(" and doc.ID2Status=@ID2Status "); |
153 |
parameters.Add("ID2Status", id2Status); |
154 |
} |
155 |
|
156 |
if (!string.IsNullOrEmpty(id2Issues)) |
157 |
{ |
158 |
sbWhere.Append(" and (case when isnull(ltrim(rtrim(doc.ID2Issues)),'') = '' then 'No' else 'Yes' end)=@ID2Issues "); |
159 |
parameters.Add("ID2Issues", id2Issues); |
160 |
} |
161 |
|
162 |
if (!string.IsNullOrEmpty(avevaStatus)) |
163 |
{ |
164 |
sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus "); |
165 |
parameters.Add("AVEVAStatus", avevaStatus); |
166 |
} |
167 |
|
168 |
if (!string.IsNullOrEmpty(avevaIssues)) |
169 |
{ |
170 |
sbWhere.Append(" and (case when isnull(ltrim(rtrim(doc.AVEVAIssues)),'') = '' then 'No' else 'Yes' end)=@AVEVAIssues "); |
171 |
parameters.Add("AVEVAIssues", avevaIssues); |
172 |
} |
173 |
|
174 |
if (!string.IsNullOrEmpty(prodIsResult)) |
175 |
{ |
176 |
sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult "); |
177 |
parameters.Add("ProdIsResult", prodIsResult); |
178 |
} |
179 |
if (!string.IsNullOrEmpty(clientIsResult)) |
180 |
{ |
181 |
sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult "); |
182 |
parameters.Add("ClientIsResult", clientIsResult); |
183 |
} |
184 |
if (!string.IsNullOrEmpty(isGateWay)) |
185 |
{ |
186 |
sbWhere.Append(" and doc.DTIsGateWay=@DTIsGateWay "); |
187 |
parameters.Add("DTIsGateWay", isGateWay); |
188 |
} |
189 |
if (!string.IsNullOrEmpty(isRegSystem)) |
190 |
{ |
191 |
sbWhere.Append(" and doc.DTIsRegSystem=@DTIsRegSystem "); |
192 |
parameters.Add("DTIsRegSystem", isRegSystem); |
193 |
} |
194 |
|
195 |
try |
196 |
{ |
197 |
|
198 |
//files.[FileID],files.[FileID] as AttFileID, files.RefID, files.Category, files.FileType, files.FileName, files.FilePath, files.FileExtension, files.FileData, files.Remark, files.CreatedDate, files.Creator, |
199 |
string query = $@" |
200 |
select doc.*, datediff(SECOND, doc.ID2StartDate, doc.ID2EndDate) as ID2JobTime, |
201 |
files.[FileID] as FileID, files.*, |
202 |
markus.MARKUP_DATA_ID as MARKUP_DATA_ID, markus.* |
203 |
from dbo.Documents doc |
204 |
LEFT OUTER JOIN AttachFIles files ON doc.DocID = fIles.RefID |
205 |
LEFT OUTER JOIN |
206 |
(SELECT [MARKUP_DATA_ID] |
207 |
,[PROJECT_NO] as PROJECT_NO |
208 |
,[DOCUMENT_ID] as DocumentNo |
209 |
|
210 |
,[PAGENUMBER] |
211 |
,[Text] as TEXT |
212 |
,[CREATE_DATE] as CREATE_DATE |
213 |
,[NAME] as CREATE_USER |
214 |
FROM ViewMarkupData) markus |
215 |
ON doc.DocumentNo = markus.DocumentNo |
216 |
where doc.IsDeleted=0 {sbWhere} |
217 |
order by doc.Seq |
218 |
|
219 |
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere} |
220 |
select @Total;"; |
221 |
|
222 |
if (parameters.Count > 0) |
223 |
{ |
224 |
dynamicParameters.AddDynamicParams(parameters); |
225 |
} |
226 |
|
227 |
var docDictionary = new Dictionary<string, Documents>(); |
228 |
|
229 |
var ret = MultiQuery<Documents, AttFileInfo, MarkupText, Documents>(query, |
230 |
(document, attfile, markusText) => |
231 |
{ |
232 |
Documents doc; |
233 |
|
234 |
if (!docDictionary.TryGetValue(document.DocID, out doc)) |
235 |
{ |
236 |
doc = document; |
237 |
docDictionary.Add(doc.DocID, doc); |
238 |
} |
239 |
|
240 |
if (markusText != null) |
241 |
{ |
242 |
doc.Markups = doc.Markups ?? new List<MarkupText>(); |
243 |
|
244 |
if (!doc.Markups.Any(x => x.MARKUP_DATA_ID == markusText.MARKUP_DATA_ID)) |
245 |
{ |
246 |
doc.Markups.Add(markusText); |
247 |
} |
248 |
} |
249 |
|
250 |
if (attfile != null) |
251 |
{ |
252 |
doc.AttFiles = doc.AttFiles ?? new List<AttFileInfo>(); |
253 |
System.Diagnostics.Debug.WriteLine(attfile.FileName); |
254 |
if (!doc.AttFiles.Any(x => x.FileID == attfile.FileID)) |
255 |
{ |
256 |
switch (attfile.Category) |
257 |
{ |
258 |
case "toreview": |
259 |
doc.ToCapture++; |
260 |
break; |
261 |
case "frreview": |
262 |
doc.FrCapture++; |
263 |
break; |
264 |
case "prodvalidation": |
265 |
doc.ProdCapture++; |
266 |
break; |
267 |
case "clientvalidation": |
268 |
doc.ClientCapture++; |
269 |
break; |
270 |
} |
271 |
|
272 |
doc.AttFiles.Add(attfile); |
273 |
} |
274 |
} |
275 |
|
276 |
return doc; |
277 |
|
278 |
}, dynamicParameters, splitOn: "DocID,FileID,MARKUP_DATA_ID").Distinct(); |
279 |
|
280 |
int totalCount = dynamicParameters.Get<int>("Total"); |
281 |
|
282 |
return (ret, totalCount); |
283 |
} |
284 |
catch (Exception ex) |
285 |
{ |
286 |
throw ex; |
287 |
} |
288 |
} |
289 |
|
290 |
public int ExistsDocument(string projectGroupID, List<string> newDwgNos) |
291 |
{ |
292 |
var dynamicParameters = new DynamicParameters(); |
293 |
StringBuilder sbWhere = new StringBuilder(); |
294 |
var parameters = new Dictionary<string, object>(); |
295 |
if (!string.IsNullOrEmpty(projectGroupID)) |
296 |
{ |
297 |
sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) "); |
298 |
parameters.Add("RefGroupID", projectGroupID); |
299 |
} |
300 |
|
301 |
if (newDwgNos.Count > 0) |
302 |
{ |
303 |
string dwgNoList = string.Join("','", newDwgNos.Where(x => !string.IsNullOrEmpty(x)).Select(x => x).ToList()); |
304 |
|
305 |
if (dwgNoList.Length > 0) |
306 |
{ |
307 |
if (!string.IsNullOrEmpty(projectGroupID)) |
308 |
{ |
309 |
sbWhere.Append($@" and doc.DocumentNo in ('{dwgNoList}') "); |
310 |
} |
311 |
} |
312 |
} |
313 |
|
314 |
try |
315 |
{ |
316 |
string query = $@" |
317 |
select count(*) cnt |
318 |
from dbo.Documents doc |
319 |
where doc.IsDeleted=0 {sbWhere}"; |
320 |
|
321 |
if (parameters.Count > 0) |
322 |
{ |
323 |
dynamicParameters.AddDynamicParams(parameters); |
324 |
} |
325 |
|
326 |
return ExecuteScalar<int>(query, dynamicParameters); |
327 |
} |
328 |
catch (Exception ex) |
329 |
{ |
330 |
throw ex; |
331 |
} |
332 |
} |
333 |
|
334 |
public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId) |
335 |
{ |
336 |
bool isSuccess = false; |
337 |
|
338 |
try |
339 |
{ |
340 |
using (var transaction = base.BeginTransaction()) |
341 |
{ |
342 |
string query = string.Empty; |
343 |
|
344 |
if (delDocList.Count > 0) |
345 |
{ |
346 |
string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList()); |
347 |
|
348 |
if (docIDList.Length > 0) |
349 |
{ |
350 |
query = $@" |
351 |
update dbo.Documents |
352 |
set IsDeleted=1 |
353 |
,DeletedDate=getdate(), |
354 |
,DeletedUser=@DeletedUser |
355 |
where DocID in ('{docIDList}');"; |
356 |
base.Execute(query, new { DeletedUser = userId }, transaction); |
357 |
} |
358 |
} |
359 |
|
360 |
foreach (Documents doc in docList) |
361 |
{ |
362 |
if (string.IsNullOrEmpty(doc.DocID)) |
363 |
{ |
364 |
doc.RegisteredUser = userId; |
365 |
query = $@" |
366 |
declare @tbdoc table(docid varchar(36)) |
367 |
insert into dbo.Documents |
368 |
( |
369 |
DocID |
370 |
,DocumentNo |
371 |
,RevisonNo |
372 |
,RefProjectCode |
373 |
,JobLevel |
374 |
,IsTypical |
375 |
,PersonInCharge |
376 |
,RegisteredDate |
377 |
,RegisteredUser |
378 |
,ToIsDiscussion |
379 |
,ToRemarks |
380 |
,ToCreator |
381 |
,ToCapture |
382 |
,ToIsMarkup |
383 |
,FrReviewStatus |
384 |
,FrRemarks |
385 |
,FrCreator |
386 |
,FrCapture |
387 |
,FrIsMarkup |
388 |
,IsID2Work |
389 |
,ID2Connection |
390 |
,ID2StartDate |
391 |
,ID2EndDate |
392 |
,ID2Status |
393 |
,ID2Issues |
394 |
,AVEVAConnection |
395 |
,AVEVAConvertDate |
396 |
,AVEVAReviewDate |
397 |
,AVEVAStatus |
398 |
,AVEVAIssues |
399 |
,ReviewFilePath |
400 |
,ReviewFileName |
401 |
,ProdReviewer |
402 |
,ProdIsResult |
403 |
,ProdRemarks |
404 |
,ClientReviewer |
405 |
,ClientIsResult |
406 |
,ClientRemarks |
407 |
,DTIsGateWay |
408 |
,DTIsImport |
409 |
,DTIsRegSystem |
410 |
,DTRemarks |
411 |
) |
412 |
output inserted.DocID into @tbdoc |
413 |
values |
414 |
( |
415 |
lower(newid()) |
416 |
,@DocumentNo |
417 |
,@RevisonNo |
418 |
,@RefProjectCode |
419 |
,@JobLevel |
420 |
,@IsTypical |
421 |
,@PersonInCharge |
422 |
,getdate() |
423 |
,@RegisteredUser |
424 |
,@ToIsDiscussion |
425 |
,@ToRemarks |
426 |
,@ToCreator |
427 |
,@ToCapture |
428 |
,@ToIsMarkup |
429 |
,@FrReviewStatus |
430 |
,@FrRemarks |
431 |
,@FrCreator |
432 |
,@FrCapture |
433 |
,@FrIsMarkup |
434 |
,@IsID2Work |
435 |
,@ID2Connection |
436 |
,@ID2StartDate |
437 |
,@ID2EndDate |
438 |
,@ID2Status |
439 |
,@ID2Issues |
440 |
,@AVEVAConnection |
441 |
,@AVEVAConvertDate |
442 |
,@AVEVAReviewDate |
443 |
,@AVEVAStatus |
444 |
,@AVEVAIssues |
445 |
,@ReviewFilePath |
446 |
,@ReviewFileName |
447 |
,@ProdReviewer |
448 |
,@ProdIsResult |
449 |
,@ProdRemarks |
450 |
,@ClientReviewer |
451 |
,@ClientIsResult |
452 |
,@ClientRemarks |
453 |
,@DTIsGateWay |
454 |
,@DTIsImport |
455 |
,@DTIsRegSystem |
456 |
,@DTRemarks |
457 |
) |
458 |
|
459 |
if @@rowcount > 0 |
460 |
begin |
461 |
select docid from @tbdoc |
462 |
end |
463 |
else |
464 |
begin |
465 |
select '' |
466 |
end;"; |
467 |
} |
468 |
else |
469 |
{ |
470 |
doc.ModifiedUser = userId; |
471 |
query = $@" |
472 |
update dbo.Documents |
473 |
set DocumentNo=@DocumentNo |
474 |
,RevisonNo=@RevisonNo |
475 |
,RefProjectCode=@RefProjectCode |
476 |
,JobLevel=@JobLevel |
477 |
,IsTypical=@IsTypical |
478 |
,PersonInCharge=@PersonInCharge |
479 |
,ModifiedDate=getdate() |
480 |
,ModifiedUser=@ModifiedUser |
481 |
,ToIsDiscussion=@ToIsDiscussion |
482 |
,ToRemarks=@ToRemarks |
483 |
,ToCreator=@ToCreator |
484 |
,ToCapture=@ToCapture |
485 |
,ToIsMarkup=@ToIsMarkup |
486 |
,FrReviewStatus=@FrReviewStatus |
487 |
,FrRemarks=@FrRemarks |
488 |
,FrCreator=@FrCreator |
489 |
,FrCapture=@FrCapture |
490 |
,FrIsMarkup=@FrIsMarkup |
491 |
,IsID2Work=@IsID2Work |
492 |
,ID2Connection=@ID2Connection |
493 |
,ID2StartDate=@ID2StartDate |
494 |
,ID2EndDate=@ID2EndDate |
495 |
,ID2Status=@ID2Status |
496 |
,ID2Issues=@ID2Issues |
497 |
,AVEVAConnection=@AVEVAConnection |
498 |
,AVEVAConvertDate=@AVEVAConvertDate |
499 |
,AVEVAReviewDate=@AVEVAReviewDate |
500 |
,AVEVAStatus=@AVEVAStatus |
501 |
,AVEVAIssues=@AVEVAIssues |
502 |
,ReviewFilePath=@ReviewFilePath |
503 |
,ReviewFileName=@ReviewFileName |
504 |
,ProdReviewer=@ProdReviewer |
505 |
,ProdIsResult=@ProdIsResult |
506 |
,ProdRemarks=@ProdRemarks |
507 |
,ClientReviewer=@ClientReviewer |
508 |
,ClientIsResult=@ClientIsResult |
509 |
,ClientRemarks=@ClientRemarks |
510 |
,DTIsGateWay=@DTIsGateWay |
511 |
,DTIsImport=@DTIsImport |
512 |
,DTIsRegSystem=@DTIsRegSystem |
513 |
,DTRemarks=@DTRemarks |
514 |
where DocID=@DocID |
515 |
|
516 |
if @@rowcount > 0 |
517 |
begin |
518 |
select @DocID |
519 |
end |
520 |
else |
521 |
begin |
522 |
select '' |
523 |
end;"; |
524 |
} |
525 |
string refID = base.QueryFirstOrDefault<string>(query, doc, transaction); |
526 |
|
527 |
if (doc.AttFiles != null && doc.AttFiles.Count > 0) |
528 |
{ |
529 |
string attDelIDList = string.Join("','", doc.AttFiles.Where(x => !string.IsNullOrEmpty(x.FileID)).Select(x => x.FileID).ToList()); |
530 |
|
531 |
if (!string.IsNullOrEmpty(refID) && attDelIDList.Length > 0) |
532 |
{ |
533 |
query = $@" |
534 |
delete from dbo.AttachFIles |
535 |
where RefID=@RefID and FileID in ('{attDelIDList}');"; |
536 |
base.Execute(query, new { RefID = refID }, transaction); |
537 |
} |
538 |
|
539 |
foreach (AttFileInfo attFile in doc.AttFiles) |
540 |
{ |
541 |
if (string.IsNullOrEmpty(attFile.RefID)) |
542 |
{ |
543 |
attFile.RefID = refID; |
544 |
attFile.Creator = userId; |
545 |
|
546 |
query = $@" |
547 |
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator) |
548 |
values |
549 |
( |
550 |
lower(newid()) |
551 |
,@RefID |
552 |
,@Category |
553 |
,@FileType |
554 |
,@FileName |
555 |
,@FilePath |
556 |
,@FileExtension |
557 |
,@FileData |
558 |
,@Creator |
559 |
)"; |
560 |
|
561 |
base.Execute(query, attFile, transaction); |
562 |
} |
563 |
} |
564 |
} |
565 |
} |
566 |
|
567 |
transaction.Commit(); |
568 |
isSuccess = true; |
569 |
} |
570 |
} |
571 |
catch (Exception ex) |
572 |
{ |
573 |
throw ex; |
574 |
} |
575 |
|
576 |
return isSuccess; |
577 |
} |
578 |
|
579 |
public Documents SetDocumentDataField(Documents doc, string userId) |
580 |
{ |
581 |
Documents resultData = null; |
582 |
|
583 |
try |
584 |
{ |
585 |
using (var transaction = base.BeginTransaction()) |
586 |
{ |
587 |
string query = string.Empty; |
588 |
|
589 |
if (!string.IsNullOrEmpty(doc.DocID)) |
590 |
{ |
591 |
StringBuilder sbSet = new StringBuilder(); |
592 |
var parameters = new Dictionary<string, object>(); |
593 |
|
594 |
#region Update 할 목록 |
595 |
if (doc.ID2StartDate != null) |
596 |
{ |
597 |
sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) "); |
598 |
parameters.Add("ID2StartDate", doc.ID2StartDate); |
599 |
} |
600 |
|
601 |
if (doc.Worker != null) |
602 |
{ |
603 |
sbSet.Append(" ,Worker=@Worker "); |
604 |
parameters.Add("Worker", doc.Worker); |
605 |
} |
606 |
#endregion |
607 |
|
608 |
if (parameters.Count > 0) |
609 |
{ |
610 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
611 |
parameters.Add("ModifiedUser", userId); |
612 |
|
613 |
parameters.Add("DocID", doc.DocID); |
614 |
|
615 |
query = $@" |
616 |
declare @DateTimeNow datetime |
617 |
set @DateTimeNow = getdate() |
618 |
|
619 |
update dbo.Documents |
620 |
set ModifiedDate=@DateTimeNow {sbSet} |
621 |
where [DocID]=@DocID |
622 |
|
623 |
if @@rowcount > 0 |
624 |
begin |
625 |
select *, datediff(SECOND, ID2StartDate, ID2EndDate) as ID2JobTime from dbo.Documents where DocID=@DocID |
626 |
end |
627 |
else |
628 |
begin |
629 |
select *, 0 as ID2JobTime from dbo.Documents where 1=2 |
630 |
end;"; |
631 |
resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction); |
632 |
} |
633 |
} |
634 |
|
635 |
transaction.Commit(); |
636 |
} |
637 |
} |
638 |
catch (Exception ex) |
639 |
{ |
640 |
throw ex; |
641 |
} |
642 |
|
643 |
return resultData; |
644 |
} |
645 |
|
646 |
public bool SetDocumentDatasField(List<Documents> docs, string userId) |
647 |
{ |
648 |
bool isSuccess = false; |
649 |
|
650 |
try |
651 |
{ |
652 |
using (var transaction = base.BeginTransaction()) |
653 |
{ |
654 |
foreach (Documents doc in docs) |
655 |
{ |
656 |
string query = string.Empty; |
657 |
|
658 |
if (!string.IsNullOrEmpty(doc.DocID)) |
659 |
{ |
660 |
StringBuilder sbSet = new StringBuilder(); |
661 |
var parameters = new Dictionary<string, object>(); |
662 |
|
663 |
#region Update 할 목록 |
664 |
if (doc.ID2EndDate != null) |
665 |
{ |
666 |
sbSet.Append(" ,ID2EndDate=@ID2EndDate "); |
667 |
parameters.Add("ID2EndDate", doc.ID2EndDate); |
668 |
} |
669 |
#endregion |
670 |
|
671 |
if (parameters.Count > 0) |
672 |
{ |
673 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
674 |
parameters.Add("ModifiedUser", userId); |
675 |
|
676 |
parameters.Add("DocID", doc.DocID); |
677 |
|
678 |
query = $@" |
679 |
update dbo.Documents |
680 |
set ModifiedDate=getdate() {sbSet} |
681 |
where [DocID]=@DocID;"; |
682 |
base.Execute(query, parameters, transaction); |
683 |
} |
684 |
} |
685 |
} |
686 |
transaction.Commit(); |
687 |
isSuccess = true; |
688 |
} |
689 |
} |
690 |
catch (Exception ex) |
691 |
{ |
692 |
throw ex; |
693 |
} |
694 |
|
695 |
return isSuccess; |
696 |
} |
697 |
|
698 |
|
699 |
//ID2 |
700 |
public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info) |
701 |
{ |
702 |
try |
703 |
{ |
704 |
string query = $@" |
705 |
select @Name PROJECTNAME |
706 |
,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME |
707 |
,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME] |
708 |
,dw.OCCUPIED, dw.[Image] |
709 |
from |
710 |
( |
711 |
select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx |
712 |
from dbo.Drawings |
713 |
) dw;"; |
714 |
return Query<ID2Drawings>(query, id2Info); |
715 |
} |
716 |
catch (Exception ex) |
717 |
{ |
718 |
throw ex; |
719 |
} |
720 |
} |
721 |
} |
722 |
} |