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