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