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