hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ ab3c1c74
이력 | 보기 | 이력해설 | 다운로드 (23.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 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(id2Status)) |
145 |
{ |
146 |
sbWhere.Append(" and doc.ID2Status=@ID2Status "); |
147 |
parameters.Add("ID2Status", id2Status); |
148 |
} |
149 |
|
150 |
if (!string.IsNullOrEmpty(id2Issues)) |
151 |
{ |
152 |
sbWhere.Append(" and (case when isnull(ltrim(rtrim(doc.ID2Issues)),'') = '' then 'No' else 'Yes' end)=@ID2Issues "); |
153 |
parameters.Add("ID2Issues", id2Issues); |
154 |
} |
155 |
|
156 |
if (!string.IsNullOrEmpty(avevaStatus)) |
157 |
{ |
158 |
sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus "); |
159 |
parameters.Add("AVEVAStatus", avevaStatus); |
160 |
} |
161 |
|
162 |
if (!string.IsNullOrEmpty(avevaIssues)) |
163 |
{ |
164 |
sbWhere.Append(" and (case when isnull(ltrim(rtrim(doc.AVEVAIssues)),'') = '' then 'No' else 'Yes' end)=@AVEVAIssues "); |
165 |
parameters.Add("AVEVAIssues", avevaIssues); |
166 |
} |
167 |
|
168 |
if (!string.IsNullOrEmpty(prodIsResult)) |
169 |
{ |
170 |
sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult "); |
171 |
parameters.Add("ProdIsResult", prodIsResult); |
172 |
} |
173 |
if (!string.IsNullOrEmpty(clientIsResult)) |
174 |
{ |
175 |
sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult "); |
176 |
parameters.Add("ClientIsResult", clientIsResult); |
177 |
} |
178 |
if (!string.IsNullOrEmpty(isGateWay)) |
179 |
{ |
180 |
sbWhere.Append(" and doc.DTIsGateWay=@DTIsGateWay "); |
181 |
parameters.Add("DTIsGateWay", isGateWay); |
182 |
} |
183 |
if (!string.IsNullOrEmpty(isRegSystem)) |
184 |
{ |
185 |
sbWhere.Append(" and doc.DTIsRegSystem=@DTIsRegSystem "); |
186 |
parameters.Add("DTIsRegSystem", isRegSystem); |
187 |
} |
188 |
|
189 |
try |
190 |
{ |
191 |
|
192 |
//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, |
193 |
string query = $@" |
194 |
select doc.*, |
195 |
files.[FileID] as FileID, files.*, |
196 |
markus.PROJECT_NO as PROJECT_NO, markus.* |
197 |
from dbo.Documents doc |
198 |
LEFT OUTER JOIN AttachFIles files ON doc.DocID = fIles.RefID |
199 |
LEFT OUTER JOIN |
200 |
(SELECT [PROJECT_NO] as PROJECT_NO |
201 |
,[DOCUMENT_ID] as DocumentNo |
202 |
|
203 |
,[PAGENUMBER] |
204 |
,[Text] as TEXT |
205 |
,[CREATE_DATE] as CREATE_DATE |
206 |
,[NAME] as CREATE_USER |
207 |
FROM ViewMarkupData) markus |
208 |
ON doc.DocumentNo = markus.DocumentNo |
209 |
where doc.IsDeleted=0 {sbWhere} |
210 |
order by doc.Seq |
211 |
|
212 |
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere} |
213 |
select @Total;"; |
214 |
|
215 |
if (parameters.Count > 0) |
216 |
{ |
217 |
dynamicParameters.AddDynamicParams(parameters); |
218 |
} |
219 |
|
220 |
var docDictionary = new Dictionary<string, Documents>(); |
221 |
|
222 |
var ret = MultiQuery<Documents, AttFileInfo, MarkupText, Documents>(query, |
223 |
(document, attfile, markusText) => |
224 |
{ |
225 |
Documents doc; |
226 |
|
227 |
if (!docDictionary.TryGetValue(document.DocID, out doc)) |
228 |
{ |
229 |
doc = document; |
230 |
docDictionary.Add(doc.DocID, doc); |
231 |
} |
232 |
|
233 |
if (markusText != null) |
234 |
{ |
235 |
doc.Markups = doc.Markups ?? new List<MarkupText>(); |
236 |
|
237 |
if (!doc.Markups.Any(x => x.Equals(markusText))) |
238 |
{ |
239 |
doc.Markups.Add(markusText); |
240 |
} |
241 |
} |
242 |
|
243 |
if (attfile != null) |
244 |
{ |
245 |
doc.AttFiles = doc.AttFiles ?? new List<AttFileInfo>(); |
246 |
System.Diagnostics.Debug.WriteLine(attfile.FileName); |
247 |
if (!doc.AttFiles.Any(x => x.FileID == attfile.FileID)) |
248 |
{ |
249 |
switch (attfile.Category) |
250 |
{ |
251 |
case "toreview": |
252 |
doc.ToCapture++; |
253 |
break; |
254 |
case "frreview": |
255 |
doc.FrCapture++; |
256 |
break; |
257 |
case "prodvalidation": |
258 |
doc.ProdCapture++; |
259 |
break; |
260 |
case "clientvalidation": |
261 |
doc.ClientCapture++; |
262 |
break; |
263 |
} |
264 |
|
265 |
doc.AttFiles.Add(attfile); |
266 |
} |
267 |
} |
268 |
|
269 |
return doc; |
270 |
|
271 |
}, dynamicParameters, splitOn: "DocID,FileID,PROJECT_NO").Distinct(); |
272 |
|
273 |
int totalCount = dynamicParameters.Get<int>("Total"); |
274 |
|
275 |
return (ret, totalCount); |
276 |
} |
277 |
catch (Exception ex) |
278 |
{ |
279 |
throw ex; |
280 |
} |
281 |
} |
282 |
|
283 |
public int ExistsDocument(string projectGroupID, List<string> newDwgNos) |
284 |
{ |
285 |
var dynamicParameters = new DynamicParameters(); |
286 |
StringBuilder sbWhere = new StringBuilder(); |
287 |
var parameters = new Dictionary<string, object>(); |
288 |
if (!string.IsNullOrEmpty(projectGroupID)) |
289 |
{ |
290 |
sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) "); |
291 |
parameters.Add("RefGroupID", projectGroupID); |
292 |
} |
293 |
|
294 |
if (newDwgNos.Count > 0) |
295 |
{ |
296 |
string dwgNoList = string.Join("','", newDwgNos.Where(x => !string.IsNullOrEmpty(x)).Select(x => x).ToList()); |
297 |
|
298 |
if (dwgNoList.Length > 0) |
299 |
{ |
300 |
if (!string.IsNullOrEmpty(projectGroupID)) |
301 |
{ |
302 |
sbWhere.Append($@" and doc.DocumentNo in ('{dwgNoList}') "); |
303 |
} |
304 |
} |
305 |
} |
306 |
|
307 |
try |
308 |
{ |
309 |
string query = $@" |
310 |
select count(*) cnt |
311 |
from dbo.Documents doc |
312 |
where doc.IsDeleted=0 {sbWhere}"; |
313 |
|
314 |
if (parameters.Count > 0) |
315 |
{ |
316 |
dynamicParameters.AddDynamicParams(parameters); |
317 |
} |
318 |
|
319 |
return ExecuteScalar<int>(query, dynamicParameters); |
320 |
} |
321 |
catch (Exception ex) |
322 |
{ |
323 |
throw ex; |
324 |
} |
325 |
} |
326 |
|
327 |
public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId) |
328 |
{ |
329 |
bool isSuccess = false; |
330 |
|
331 |
try |
332 |
{ |
333 |
using (var transaction = base.BeginTransaction()) |
334 |
{ |
335 |
string query = string.Empty; |
336 |
|
337 |
if (delDocList.Count > 0) |
338 |
{ |
339 |
string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList()); |
340 |
|
341 |
if (docIDList.Length > 0) |
342 |
{ |
343 |
query = $@" |
344 |
update dbo.Documents |
345 |
set IsDeleted=1 |
346 |
,DeletedDate=getdate(), |
347 |
,DeletedUser=@DeletedUser |
348 |
where DocID in ('{docIDList}');"; |
349 |
base.Execute(query, new { DeletedUser = userId }, transaction); |
350 |
} |
351 |
} |
352 |
|
353 |
foreach (Documents doc in docList) |
354 |
{ |
355 |
if (string.IsNullOrEmpty(doc.DocID)) |
356 |
{ |
357 |
doc.RegisteredUser = userId; |
358 |
query = $@" |
359 |
declare @tbdoc table(docid varchar(36)) |
360 |
insert into dbo.Documents |
361 |
( |
362 |
DocID |
363 |
,DocumentNo |
364 |
,RevisonNo |
365 |
,System |
366 |
,SubSystemCode |
367 |
,RefProjectCode |
368 |
,JobLevel |
369 |
,PersonInCharge |
370 |
,RegisteredDate |
371 |
,RegisteredUser |
372 |
,ToIsDiscussion |
373 |
,ToRemarks |
374 |
,ToCreator |
375 |
,FrReviewStatus |
376 |
,FrRemarks |
377 |
,FrCreator |
378 |
,ID2StartDate |
379 |
,ID2EndDate |
380 |
,ID2Status |
381 |
,ID2Issues |
382 |
,ReplyModifications |
383 |
,ReplyRequester |
384 |
,IsConvert |
385 |
,AVEVAPersonInCharge |
386 |
,AVEVAWorker |
387 |
,AVEVAConvertDate |
388 |
,AVEVAReviewDate |
389 |
,AVEVAWorkDate |
390 |
,AVEVAStatus |
391 |
,AVEVAIssues |
392 |
,ProdReviewer |
393 |
,ProdIsResult |
394 |
,ProdRemarks |
395 |
,ClientReviewer |
396 |
,ClientIsResult |
397 |
,ClientRemarks |
398 |
,DTIsGateWay |
399 |
,DTIsImport |
400 |
,DTIsRegSystem |
401 |
,DTRemarks |
402 |
) |
403 |
output inserted.DocID into @tbdoc |
404 |
values |
405 |
( |
406 |
lower(newid()) |
407 |
,@DocumentNo |
408 |
,@RevisonNo |
409 |
,@System |
410 |
,@SubSystemCode |
411 |
,@RefProjectCode |
412 |
,@JobLevel |
413 |
,@PersonInCharge |
414 |
,getdate() |
415 |
,@RegisteredUser |
416 |
,@ToIsDiscussion |
417 |
,@ToRemarks |
418 |
,@ToCreator |
419 |
,@FrReviewStatus |
420 |
,@FrRemarks |
421 |
,@FrCreator |
422 |
,@ID2StartDate |
423 |
,@ID2EndDate |
424 |
,@ID2Status |
425 |
,@ID2Issues |
426 |
,@ReplyModifications |
427 |
,@ReplyRequester |
428 |
,@IsConvert |
429 |
,@AVEVAPersonInCharge |
430 |
,@AVEVAWorker |
431 |
,@AVEVAConvertDate |
432 |
,@AVEVAReviewDate |
433 |
,@AVEVAWorkDate |
434 |
,@AVEVAStatus |
435 |
,@AVEVAIssues |
436 |
,@ProdReviewer |
437 |
,@ProdIsResult |
438 |
,@ProdRemarks |
439 |
,@ClientReviewer |
440 |
,@ClientIsResult |
441 |
,@ClientRemarks |
442 |
,@DTIsGateWay |
443 |
,@DTIsImport |
444 |
,@DTIsRegSystem |
445 |
,@DTRemarks |
446 |
) |
447 |
|
448 |
if @@rowcount > 0 |
449 |
begin |
450 |
select docid from @tbdoc |
451 |
end |
452 |
else |
453 |
begin |
454 |
select '' |
455 |
end;"; |
456 |
} |
457 |
else |
458 |
{ |
459 |
doc.ModifiedUser = userId; |
460 |
query = $@" |
461 |
update dbo.Documents |
462 |
set DocumentNo=@DocumentNo |
463 |
,RevisonNo=@RevisonNo |
464 |
,System=@System |
465 |
,SubSystemCode=@SubSystemCode |
466 |
,RefProjectCode=@RefProjectCode |
467 |
,JobLevel=@JobLevel |
468 |
,PersonInCharge=@PersonInCharge |
469 |
,ModifiedDate=getdate() |
470 |
,ModifiedUser=@ModifiedUser |
471 |
,ToIsDiscussion=@ToIsDiscussion |
472 |
,ToRemarks=@ToRemarks |
473 |
,ToCreator=@ToCreator |
474 |
,FrReviewStatus=@FrReviewStatus |
475 |
,FrRemarks=@FrRemarks |
476 |
,FrCreator=@FrCreator |
477 |
,ID2StartDate=@ID2StartDate |
478 |
,ID2EndDate=@ID2EndDate |
479 |
,ID2Status=@ID2Status |
480 |
,ID2Issues=@ID2Issues |
481 |
,ReplyModifications=@ReplyModifications |
482 |
,ReplyRequester=@ReplyRequester |
483 |
,IsConvert=@IsConvert |
484 |
,AVEVAPersonInCharge=@AVEVAPersonInCharge |
485 |
,AVEVAWorker=@AVEVAWorker |
486 |
,AVEVAConvertDate=@AVEVAConvertDate |
487 |
,AVEVAReviewDate=@AVEVAReviewDate |
488 |
,AVEVAWorkDate=@AVEVAWorkDate |
489 |
,AVEVAStatus=@AVEVAStatus |
490 |
,AVEVAIssues=@AVEVAIssues |
491 |
,ProdReviewer=@ProdReviewer |
492 |
,ProdIsResult=@ProdIsResult |
493 |
,ProdRemarks=@ProdRemarks |
494 |
,ClientReviewer=@ClientReviewer |
495 |
,ClientIsResult=@ClientIsResult |
496 |
,ClientRemarks=@ClientRemarks |
497 |
,DTIsGateWay=@DTIsGateWay |
498 |
,DTIsImport=@DTIsImport |
499 |
,DTIsRegSystem=@DTIsRegSystem |
500 |
,DTRemarks=@DTRemarks |
501 |
where DocID=@DocID |
502 |
|
503 |
if @@rowcount > 0 |
504 |
begin |
505 |
select @DocID |
506 |
end |
507 |
else |
508 |
begin |
509 |
select '' |
510 |
end;"; |
511 |
} |
512 |
string refID = base.QueryFirstOrDefault<string>(query, doc, transaction); |
513 |
|
514 |
if (doc.AttFiles != null && doc.AttFiles.Count > 0) |
515 |
{ |
516 |
string attDelIDList = string.Join("','", doc.AttFiles.Where(x => !string.IsNullOrEmpty(x.FileID)).Select(x => x.FileID).ToList()); |
517 |
|
518 |
if (!string.IsNullOrEmpty(refID) && attDelIDList.Length > 0) |
519 |
{ |
520 |
query = $@" |
521 |
delete from dbo.AttachFIles |
522 |
where RefID=@RefID and FileID in ('{attDelIDList}');"; |
523 |
base.Execute(query, new { RefID = refID }, transaction); |
524 |
} |
525 |
|
526 |
foreach (AttFileInfo attFile in doc.AttFiles) |
527 |
{ |
528 |
if (string.IsNullOrEmpty(attFile.RefID)) |
529 |
{ |
530 |
attFile.RefID = refID; |
531 |
attFile.Creator = userId; |
532 |
|
533 |
query = $@" |
534 |
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator) |
535 |
values |
536 |
( |
537 |
lower(newid()) |
538 |
,@RefID |
539 |
,@Category |
540 |
,@FileType |
541 |
,@FileName |
542 |
,@FilePath |
543 |
,@FileExtension |
544 |
,@FileData |
545 |
,@Creator |
546 |
)"; |
547 |
|
548 |
base.Execute(query, attFile, transaction); |
549 |
} |
550 |
} |
551 |
} |
552 |
} |
553 |
|
554 |
transaction.Commit(); |
555 |
isSuccess = true; |
556 |
} |
557 |
} |
558 |
catch (Exception ex) |
559 |
{ |
560 |
throw ex; |
561 |
} |
562 |
|
563 |
return isSuccess; |
564 |
} |
565 |
|
566 |
public Documents SetDocumentDataField(Documents doc, string userId) |
567 |
{ |
568 |
Documents resultData = null; |
569 |
|
570 |
try |
571 |
{ |
572 |
using (var transaction = base.BeginTransaction()) |
573 |
{ |
574 |
string query = string.Empty; |
575 |
|
576 |
if (!string.IsNullOrEmpty(doc.DocID)) |
577 |
{ |
578 |
StringBuilder sbSet = new StringBuilder(); |
579 |
var parameters = new Dictionary<string, object>(); |
580 |
|
581 |
#region Update 할 목록 |
582 |
if (doc.ID2StartDate != null) |
583 |
{ |
584 |
sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) "); |
585 |
parameters.Add("ID2StartDate", doc.ID2StartDate); |
586 |
} |
587 |
|
588 |
if (doc.Worker != null) |
589 |
{ |
590 |
sbSet.Append(" ,Worker=@Worker "); |
591 |
parameters.Add("Worker", doc.Worker); |
592 |
} |
593 |
#endregion |
594 |
|
595 |
if (parameters.Count > 0) |
596 |
{ |
597 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
598 |
parameters.Add("ModifiedUser", userId); |
599 |
|
600 |
parameters.Add("DocID", doc.DocID); |
601 |
|
602 |
query = $@" |
603 |
declare @DateTimeNow datetime |
604 |
set @DateTimeNow = getdate() |
605 |
|
606 |
update dbo.Documents |
607 |
set ModifiedDate=@DateTimeNow {sbSet} |
608 |
where [DocID]=@DocID |
609 |
|
610 |
if @@rowcount > 0 |
611 |
begin |
612 |
select * from dbo.Documents where DocID=@DocID |
613 |
end |
614 |
else |
615 |
begin |
616 |
select * from dbo.Documents where 1=2 |
617 |
end;"; |
618 |
resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction); |
619 |
} |
620 |
} |
621 |
|
622 |
transaction.Commit(); |
623 |
} |
624 |
} |
625 |
catch (Exception ex) |
626 |
{ |
627 |
throw ex; |
628 |
} |
629 |
|
630 |
return resultData; |
631 |
} |
632 |
|
633 |
public bool SetDocumentDatasField(List<Documents> docs, string userId) |
634 |
{ |
635 |
bool isSuccess = false; |
636 |
|
637 |
try |
638 |
{ |
639 |
using (var transaction = base.BeginTransaction()) |
640 |
{ |
641 |
foreach (Documents doc in docs) |
642 |
{ |
643 |
string query = string.Empty; |
644 |
|
645 |
if (!string.IsNullOrEmpty(doc.DocID)) |
646 |
{ |
647 |
StringBuilder sbSet = new StringBuilder(); |
648 |
var parameters = new Dictionary<string, object>(); |
649 |
|
650 |
#region Update 할 목록 |
651 |
if (doc.ID2EndDate != null) |
652 |
{ |
653 |
sbSet.Append(" ,ID2EndDate=@ID2EndDate "); |
654 |
parameters.Add("ID2EndDate", doc.ID2EndDate); |
655 |
} |
656 |
#endregion |
657 |
|
658 |
if (parameters.Count > 0) |
659 |
{ |
660 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
661 |
parameters.Add("ModifiedUser", userId); |
662 |
|
663 |
parameters.Add("DocID", doc.DocID); |
664 |
|
665 |
query = $@" |
666 |
update dbo.Documents |
667 |
set ModifiedDate=getdate() {sbSet} |
668 |
where [DocID]=@DocID;"; |
669 |
base.Execute(query, parameters, transaction); |
670 |
} |
671 |
} |
672 |
} |
673 |
transaction.Commit(); |
674 |
isSuccess = true; |
675 |
} |
676 |
} |
677 |
catch (Exception ex) |
678 |
{ |
679 |
throw ex; |
680 |
} |
681 |
|
682 |
return isSuccess; |
683 |
} |
684 |
|
685 |
|
686 |
//ID2 |
687 |
public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info) |
688 |
{ |
689 |
try |
690 |
{ |
691 |
string query = $@" |
692 |
select @Name PROJECTNAME |
693 |
,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME |
694 |
,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME] |
695 |
,dw.OCCUPIED, dw.[Image] |
696 |
from |
697 |
( |
698 |
select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx |
699 |
from dbo.Drawings |
700 |
) dw;"; |
701 |
return Query<ID2Drawings>(query, id2Info); |
702 |
} |
703 |
catch (Exception ex) |
704 |
{ |
705 |
throw ex; |
706 |
} |
707 |
} |
708 |
} |
709 |
} |