프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ d62e37ef

이력 | 보기 | 이력해설 | 다운로드 (24.6 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
                    string query = $@"
200 f044f53d taeseongkim
                            select  doc.*, datediff(SECOND, doc.ID2StartDate, doc.ID2EndDate) as ID2JobTime,
201 08499f5f taeseongkim
                            files.[FileID] as FileID, files.*,
202 a37dc9a7 taeseongkim
                            markus.PROJECT_NO as PROJECT_NO, markus.*
203 e458a996 taeseongkim
                            from     dbo.Documents doc
204 08499f5f taeseongkim
	                        LEFT OUTER JOIN AttachFIles files ON doc.DocID = fIles.RefID 
205 e458a996 taeseongkim
                            LEFT OUTER JOIN 
206 a37dc9a7 taeseongkim
                                    (SELECT [PROJECT_NO] as PROJECT_NO
207 e458a996 taeseongkim
                                          ,[DOCUMENT_ID] as DocumentNo
208 08499f5f taeseongkim
                                          
209 e458a996 taeseongkim
                                          ,[PAGENUMBER]
210
                                          ,[Text] as TEXT
211
                                          ,[CREATE_DATE] as CREATE_DATE
212
                                          ,[NAME] as CREATE_USER
213 08499f5f taeseongkim
                                      FROM ViewMarkupData) markus 
214 e458a996 taeseongkim
                            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
    ,RefProjectCode
372
    ,JobLevel
373
    ,IsTypical
374
    ,PersonInCharge
375
    ,RegisteredDate
376
    ,RegisteredUser
377
    ,ToIsDiscussion
378
    ,ToRemarks
379
    ,ToCreator
380
    ,ToIsMarkup
381
    ,FrReviewStatus
382
    ,FrRemarks
383
    ,FrCreator
384
    ,FrIsMarkup
385
    ,IsID2Work
386
    ,ID2Connection
387
    ,ID2StartDate
388
    ,ID2EndDate
389
    ,ID2Status
390
    ,ID2Issues
391
    ,AVEVAConnection
392
    ,AVEVAConvertDate
393
    ,AVEVAReviewDate
394
    ,AVEVAStatus
395
    ,AVEVAIssues
396
    ,ReviewFilePath
397
    ,ReviewFileName
398
    ,ProdReviewer
399
    ,ProdIsResult
400
    ,ProdRemarks
401
    ,ClientReviewer
402
    ,ClientIsResult
403
    ,ClientRemarks
404
    ,DTIsGateWay
405
    ,DTIsImport
406
    ,DTIsRegSystem
407
    ,DTRemarks
408 482f6326 yoush97
)
409 b1591ae6 yoush97
output inserted.DocID into @tbdoc
410 482f6326 yoush97
values 
411
(
412
     lower(newid())
413
    ,@DocumentNo
414
    ,@RevisonNo
415 36a31d25 yoush97
    ,@RefProjectCode
416 482f6326 yoush97
    ,@JobLevel
417
    ,@IsTypical
418
    ,@PersonInCharge
419 54977253 yoush97
    ,getdate()
420
    ,@RegisteredUser
421 482f6326 yoush97
    ,@ToIsDiscussion
422
    ,@ToRemarks
423
    ,@ToCreator
424
    ,@ToIsMarkup
425
    ,@FrReviewStatus
426
    ,@FrRemarks
427
    ,@FrCreator
428
    ,@FrIsMarkup
429
    ,@IsID2Work
430
    ,@ID2Connection
431
    ,@ID2StartDate
432
    ,@ID2EndDate
433
    ,@ID2Status
434
    ,@ID2Issues
435
    ,@AVEVAConnection
436
    ,@AVEVAConvertDate
437
    ,@AVEVAReviewDate
438
    ,@AVEVAStatus
439
    ,@AVEVAIssues
440
    ,@ReviewFilePath
441
    ,@ReviewFileName
442
    ,@ProdReviewer
443
    ,@ProdIsResult
444
    ,@ProdRemarks
445
    ,@ClientReviewer
446
    ,@ClientIsResult
447
    ,@ClientRemarks
448
    ,@DTIsGateWay
449
    ,@DTIsImport
450
    ,@DTIsRegSystem
451
    ,@DTRemarks
452 b1591ae6 yoush97
)
453
454
if @@rowcount > 0
455
begin
456
    select docid from @tbdoc
457
end
458
else
459
begin
460
    select ''
461
end;";
462 482f6326 yoush97
                        }
463
                        else
464
                        {
465 54977253 yoush97
                            doc.ModifiedUser = userId;
466 482f6326 yoush97
                            query = $@"
467
update dbo.Documents
468 54977253 yoush97
set    DocumentNo=@DocumentNo
469
      ,RevisonNo=@RevisonNo
470
      ,RefProjectCode=@RefProjectCode
471
      ,JobLevel=@JobLevel
472
      ,IsTypical=@IsTypical
473
      ,PersonInCharge=@PersonInCharge
474
      ,ModifiedDate=getdate()
475
      ,ModifiedUser=@ModifiedUser
476
      ,ToIsDiscussion=@ToIsDiscussion
477
      ,ToRemarks=@ToRemarks
478
      ,ToCreator=@ToCreator
479
      ,ToIsMarkup=@ToIsMarkup
480
      ,FrReviewStatus=@FrReviewStatus
481
      ,FrRemarks=@FrRemarks
482
      ,FrCreator=@FrCreator
483
      ,FrIsMarkup=@FrIsMarkup
484
      ,IsID2Work=@IsID2Work
485
      ,ID2Connection=@ID2Connection
486
      ,ID2StartDate=@ID2StartDate
487
      ,ID2EndDate=@ID2EndDate
488
      ,ID2Status=@ID2Status
489
      ,ID2Issues=@ID2Issues
490
      ,AVEVAConnection=@AVEVAConnection
491
      ,AVEVAConvertDate=@AVEVAConvertDate
492
      ,AVEVAReviewDate=@AVEVAReviewDate
493
      ,AVEVAStatus=@AVEVAStatus
494
      ,AVEVAIssues=@AVEVAIssues
495
      ,ReviewFilePath=@ReviewFilePath
496
      ,ReviewFileName=@ReviewFileName
497
      ,ProdReviewer=@ProdReviewer
498
      ,ProdIsResult=@ProdIsResult
499
      ,ProdRemarks=@ProdRemarks
500
      ,ClientReviewer=@ClientReviewer
501
      ,ClientIsResult=@ClientIsResult
502
      ,ClientRemarks=@ClientRemarks
503
      ,DTIsGateWay=@DTIsGateWay
504
      ,DTIsImport=@DTIsImport
505
      ,DTIsRegSystem=@DTIsRegSystem
506
      ,DTRemarks=@DTRemarks
507 b1591ae6 yoush97
where  DocID=@DocID
508
509
if @@rowcount > 0
510
begin
511
    select @DocID
512
end
513
else
514
begin
515
    select ''
516
end;";
517
                        }
518
                        string refID = base.QueryFirstOrDefault<string>(query, doc, transaction);
519
520
                        if (doc.AttFiles != null && doc.AttFiles.Count > 0)
521
                        {
522
                            string attDelIDList = string.Join("','", doc.AttFiles.Where(x => !string.IsNullOrEmpty(x.FileID)).Select(x => x.FileID).ToList());
523
524
                            if (!string.IsNullOrEmpty(refID) && attDelIDList.Length > 0)
525
                            {
526
                                query = $@"
527
delete from dbo.AttachFIles
528
where  RefID=@RefID and FileID in ('{attDelIDList}');";
529
                                base.Execute(query, new { RefID = refID }, transaction);
530
                            }
531
532
                            foreach (AttFileInfo attFile in doc.AttFiles)
533
                            {
534 e5ade387 yoush97
                                if (string.IsNullOrEmpty(attFile.RefID))
535
                                {
536
                                    attFile.RefID = refID;
537
                                    attFile.Creator = userId;
538 b1591ae6 yoush97
539 e5ade387 yoush97
                                    query = $@"
540 b1591ae6 yoush97
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator)
541
values
542
(
543
    lower(newid())
544
   ,@RefID
545
   ,@Category
546
   ,@FileType
547
   ,@FileName
548
   ,@FilePath
549
   ,@FileExtension
550
   ,@FileData
551
   ,@Creator
552
)";
553
554 e5ade387 yoush97
                                    base.Execute(query, attFile, transaction);
555
                                }
556 b1591ae6 yoush97
                            }
557 482f6326 yoush97
                        }
558
                    }
559
560
                    transaction.Commit();
561
                    isSuccess = true;
562
                }
563
            }
564
            catch (Exception ex)
565
            {
566
                throw ex;
567
            }
568
569
            return isSuccess;
570
        }
571 978488b0 yoush97
572
        public Documents SetDocumentDataField(Documents doc, string userId)
573
        {
574
            Documents resultData = null;
575
576
            try
577
            {
578
                using (var transaction = base.BeginTransaction())
579
                {
580
                    string query = string.Empty;
581
582
                    if (!string.IsNullOrEmpty(doc.DocID))
583
                    {
584
                        StringBuilder sbSet = new StringBuilder();
585
                        var parameters = new Dictionary<string, object>();
586
587
                        #region Update 할 목록
588
                        if (doc.ID2StartDate != null)
589
                        {
590 4b8d9ad9 yoush97
                            sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) ");
591 978488b0 yoush97
                            parameters.Add("ID2StartDate", doc.ID2StartDate);
592
                        }
593 4b8d9ad9 yoush97
594
                        if (doc.Worker != null)
595
                        {
596
                            sbSet.Append(" ,Worker=@Worker ");
597
                            parameters.Add("Worker", doc.Worker);
598
                        }
599 978488b0 yoush97
                        #endregion
600
601
                        if (parameters.Count > 0)
602
                        {
603
                            sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
604
                            parameters.Add("ModifiedUser", userId);
605
606 54977253 yoush97
                            parameters.Add("DocID", doc.DocID);
607
608 978488b0 yoush97
                            query = $@"
609
declare @DateTimeNow datetime
610
set @DateTimeNow = getdate()
611
612
update dbo.Documents
613
set    ModifiedDate=@DateTimeNow {sbSet}
614
where  [DocID]=@DocID
615
616
if @@rowcount > 0
617
begin
618 c0420a29 yoush97
    select *, datediff(SECOND, ID2StartDate, ID2EndDate) as ID2JobTime from dbo.Documents where DocID=@DocID
619 978488b0 yoush97
end
620
else
621
begin
622 c0420a29 yoush97
    select *, 0 as ID2JobTime from dbo.Documents where 1=2
623 978488b0 yoush97
end;";
624
                            resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction);
625
                        }
626
                    }
627
628
                    transaction.Commit();
629
                }
630
            }
631
            catch (Exception ex)
632
            {
633
                throw ex;
634
            }
635
636
            return resultData;
637
        }
638 fe57f64a yoush97
639 54977253 yoush97
        public bool SetDocumentDatasField(List<Documents> docs, string userId)
640
        {
641
            bool isSuccess = false;
642
643
            try
644
            {
645
                using (var transaction = base.BeginTransaction())
646
                {
647
                    foreach (Documents doc in docs)
648
                    {
649
                        string query = string.Empty;
650
651
                        if (!string.IsNullOrEmpty(doc.DocID))
652
                        {
653
                            StringBuilder sbSet = new StringBuilder();
654
                            var parameters = new Dictionary<string, object>();
655
656
                            #region Update 할 목록
657
                            if (doc.ID2EndDate != null)
658
                            {
659
                                sbSet.Append(" ,ID2EndDate=@ID2EndDate ");
660
                                parameters.Add("ID2EndDate", doc.ID2EndDate);
661
                            }
662
                            #endregion
663
664
                            if (parameters.Count > 0)
665
                            {
666
                                sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
667
                                parameters.Add("ModifiedUser", userId);
668
669
                                parameters.Add("DocID", doc.DocID);
670
671
                                query = $@"
672
update dbo.Documents
673
set    ModifiedDate=getdate() {sbSet}
674
where  [DocID]=@DocID;";
675 e458a996 taeseongkim
                                base.Execute(query, parameters, transaction);
676 54977253 yoush97
                            }
677
                        }
678
                    }
679
                    transaction.Commit();
680
                    isSuccess = true;
681
                }
682
            }
683
            catch (Exception ex)
684
            {
685
                throw ex;
686
            }
687
688
            return isSuccess;
689
        }
690
691 fe57f64a yoush97
692
        //ID2
693
        public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info)
694
        {
695 82705273 yoush97
            try
696
            {
697
                string query = $@"
698 fe57f64a yoush97
select @Name PROJECTNAME
699
      ,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME
700
      ,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME]
701
      ,dw.OCCUPIED, dw.[Image]
702
from
703
(
704
    select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx
705
    from   dbo.Drawings
706
) dw;";
707 82705273 yoush97
                return Query<ID2Drawings>(query, id2Info);
708
            }
709
            catch (Exception ex)
710
            {
711
                throw ex;
712
            }
713 fe57f64a yoush97
        }
714 5898479a yoush97
    }
715 d2d4f84b yoush97
}
클립보드 이미지 추가 (최대 크기: 500 MB)