프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 3cc84cb6

이력 | 보기 | 이력해설 | 다운로드 (25 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

    
7
using System.Data;
8

    
9
using ID2.Manager.Data.Models;
10

    
11
using Dapper;
12
using System.ComponentModel;
13
using System.Reflection;
14

    
15
namespace ID2.Manager.Dapper.Repository
16
{
17
    public class DocumentRepository : BaseRepository
18
    {
19
        public DocumentRepository(string connectionStr) : base(connectionStr) { }
20

    
21
        public IEnumerable<Documents> GetAllDocuments(string projectGroupID)
22
        {
23
            var dynamicParameters = new DynamicParameters();
24
            StringBuilder sbWhere = new StringBuilder();
25
            var parameters = new Dictionary<string, object>();
26
            if (!string.IsNullOrEmpty(projectGroupID))
27
            {
28
                sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) ");
29
                parameters.Add("RefGroupID", projectGroupID);
30
            }
31

    
32
            try
33
            {
34
                string query = $@"
35
select   doc.*
36
from     dbo.Documents doc
37
where    doc.IsDeleted=0 {sbWhere}
38
order by doc.Seq;";
39

    
40
                if (parameters.Count > 0)
41
                {
42
                    dynamicParameters.AddDynamicParams(parameters);
43
                }
44

    
45
                return Query<Documents>(query, dynamicParameters);
46
            }
47
            catch (Exception ex)
48
            {
49
                throw ex;
50
            }
51
        }
52
        static string GetDescriptionFromAttribute(MemberInfo member)
53
        {
54
            if (member == null) return null;
55

    
56
            var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false);
57
            return (attrib?.Description ?? member.Name).ToLower();
58
        }
59

    
60

    
61
        public (IEnumerable<Documents> dwgs, int totalCnt) GetDocuments(string projectGroupID, List<string> dateTypes, DateTime? frDate, DateTime? toDate, string projectCode, string personIncharge, string jobLevel, string documentNo, string isToIsDiscussion, string isFrReviewStatus, string isID2Work, string id2Status, string id2Issues, string avevaStatus, string avevaIssues, string prodIsResult, string clientIsResult, string isGateWay, string isRegSystem)
62
        {
63
            var map = new CustomPropertyTypeMap(typeof(AttFileInfo), (type, columnName)
64
     => type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName.ToLower()));
65
            SqlMapper.SetTypeMap(typeof(AttFileInfo), map);
66

    
67

    
68
            var dynamicParameters = new DynamicParameters();
69
            dynamicParameters.Add("Total", dbType: DbType.Int32, direction: ParameterDirection.Output);
70

    
71
            StringBuilder sbWhere = new StringBuilder();
72
            StringBuilder sbTotalWhere = new StringBuilder();
73
            var parameters = new Dictionary<string, object>();
74
            if (dateTypes.Count > 0 && (frDate != null || toDate != null))
75
            {
76
                List<string> subWheres = new List<string>();
77
                foreach (string dateType in dateTypes)
78
                {
79
                    StringBuilder sbSubWhere = new StringBuilder();
80
                    if (frDate != null)
81
                    {
82
                        sbSubWhere.Insert(0, $@"convert(datetime, '{Convert.ToDateTime(frDate).AddDays(-1):yyyy-MM-dd 23:59:59.997}') < doc.{dateType}");
83
                    }
84
                    if (toDate != null)
85
                    {
86
                        if (frDate != null)
87
                            sbSubWhere.Append($@" and ");
88
                        sbSubWhere.Append($@"doc.{dateType} < convert(datetime, '{Convert.ToDateTime(toDate).AddDays(1):yyyy-MM-dd 00:00:00.000}')");
89
                    }
90

    
91
                    if (sbSubWhere.Length > 0)
92
                    {
93
                        subWheres.Add("(" + sbSubWhere.ToString() + ")");
94
                    }
95
                }
96

    
97
                if (subWheres.Count > 0)
98
                {
99
                    sbWhere.Append(" and (" + string.Join(" or ", subWheres) + ") ");
100
                }
101
            }
102
            if (string.IsNullOrEmpty(projectCode))
103
            {
104
                sbWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') ");
105
                sbTotalWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') ");
106
                parameters.Add("RefGroupID", projectGroupID);
107
            }
108
            else
109
            {
110
                sbTotalWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') ");
111
                parameters.Add("RefGroupID", projectGroupID);
112

    
113
                sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode ");
114
                parameters.Add("RefProjectCode", projectCode);
115
            }
116
            if (!string.IsNullOrEmpty(personIncharge))
117
            {
118
                sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge ");
119
                parameters.Add("PersonInCharge", personIncharge);
120
            }
121
            if (!string.IsNullOrEmpty(jobLevel))
122
            {
123
                sbWhere.Append(" and doc.JobLevel=@JobLevel ");
124
                parameters.Add("JobLevel", jobLevel);
125
            }
126
            if (!string.IsNullOrEmpty(documentNo))
127
            {
128
                sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' ");
129
                parameters.Add("DocumentNo", documentNo);
130
            }
131

    
132
            if (!string.IsNullOrEmpty(isToIsDiscussion))
133
            {
134
                sbWhere.Append(" and doc.ToIsDiscussion=@ToIsDiscussion ");
135
                parameters.Add("ToIsDiscussion", isToIsDiscussion);
136
            }
137

    
138
            if (!string.IsNullOrEmpty(isFrReviewStatus))
139
            {
140
                sbWhere.Append(" and doc.FrReviewStatus=@FrReviewStatus ");
141
                parameters.Add("FrReviewStatus", isFrReviewStatus);
142
            }
143

    
144
            if (!string.IsNullOrEmpty(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

    
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
            if (!string.IsNullOrEmpty(avevaStatus))
163
            {
164
                sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus ");
165
                parameters.Add("AVEVAStatus", avevaStatus);
166
            }
167

    
168
            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
            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
            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

    
195
            try
196
            {
197

    
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
                            select  doc.*, datediff(SECOND, doc.ID2StartDate, doc.ID2EndDate) as ID2JobTime,
201
                            files.[FileID] as FileID, files.*,
202
                            markus.MARKUP_DATA_ID as MARKUP_DATA_ID, markus.*
203
                            from     dbo.Documents doc
204
	                        LEFT OUTER JOIN AttachFIles files ON doc.DocID = fIles.RefID 
205
                            LEFT OUTER JOIN 
206
                                    (SELECT [MARKUP_DATA_ID]
207
                                           ,[PROJECT_NO] as PROJECT_NO
208
                                          ,[DOCUMENT_ID] as DocumentNo
209
                                          
210
                                          ,[PAGENUMBER]
211
                                          ,[Text] as TEXT
212
                                          ,[CREATE_DATE] as CREATE_DATE
213
                                          ,[NAME] as CREATE_USER
214
                                      FROM ViewMarkupData) markus 
215
                            ON doc.DocumentNo = markus.DocumentNo
216
                            where    doc.IsDeleted=0 {sbWhere}
217
                            order by doc.Seq
218

    
219
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere}
220
select @Total;";
221

    
222
                if (parameters.Count > 0)
223
                {
224
                    dynamicParameters.AddDynamicParams(parameters);
225
                }
226

    
227
                var docDictionary = new Dictionary<string, Documents>();
228

    
229
                var ret = MultiQuery<Documents, AttFileInfo, MarkupText, Documents>(query,
230
                                (document, attfile, markusText) =>
231
                                {
232
                                    Documents doc;
233

    
234
                                    if (!docDictionary.TryGetValue(document.DocID, out doc))
235
                                    {
236
                                        doc = document;
237
                                        docDictionary.Add(doc.DocID, doc);
238
                                    }
239

    
240
                                    if (markusText != null)
241
                                    {
242
                                        doc.Markups = doc.Markups ?? new List<MarkupText>();
243

    
244
                                        if (!doc.Markups.Any(x => x.MARKUP_DATA_ID == markusText.MARKUP_DATA_ID))
245
                                        {
246
                                            doc.Markups.Add(markusText);
247
                                        }
248
                                    }
249

    
250
                                    if (attfile != null)
251
                                    {
252
                                        doc.AttFiles = doc.AttFiles ?? new List<AttFileInfo>();
253
                                        System.Diagnostics.Debug.WriteLine(attfile.FileName);
254
                                        if (!doc.AttFiles.Any(x => x.FileID == attfile.FileID))
255
                                        {
256
                                            switch (attfile.Category)
257
                                            {
258
                                                case "toreview":
259
                                                    doc.ToCapture++;
260
                                                    break;
261
                                                case "frreview":
262
                                                    doc.FrCapture++;
263
                                                    break;
264
                                                case "prodvalidation":
265
                                                    doc.ProdCapture++;
266
                                                    break;
267
                                                case "clientvalidation":
268
                                                    doc.ClientCapture++;
269
                                                    break;
270
                                            }
271

    
272
                                            doc.AttFiles.Add(attfile);
273
                                        }
274
                                    }
275

    
276
                                    return doc;
277

    
278
                                }, dynamicParameters, splitOn: "DocID,FileID,MARKUP_DATA_ID").Distinct();
279

    
280
                int totalCount = dynamicParameters.Get<int>("Total");
281

    
282
                return (ret, totalCount);
283
            }
284
            catch (Exception ex)
285
            {
286
                throw ex;
287
            }
288
        }
289

    
290
        public int ExistsDocument(string projectGroupID, List<string> newDwgNos)
291
        {
292
            var dynamicParameters = new DynamicParameters();
293
            StringBuilder sbWhere = new StringBuilder();
294
            var parameters = new Dictionary<string, object>();
295
            if (!string.IsNullOrEmpty(projectGroupID))
296
            {
297
                sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) ");
298
                parameters.Add("RefGroupID", projectGroupID);
299
            }
300

    
301
            if (newDwgNos.Count > 0)
302
            {
303
                string dwgNoList = string.Join("','", newDwgNos.Where(x => !string.IsNullOrEmpty(x)).Select(x => x).ToList());
304

    
305
                if (dwgNoList.Length > 0)
306
                {
307
                    if (!string.IsNullOrEmpty(projectGroupID))
308
                    {
309
                        sbWhere.Append($@" and doc.DocumentNo in ('{dwgNoList}') ");
310
                    }
311
                }
312
            }
313

    
314
            try
315
            {
316
                string query = $@"
317
select   count(*) cnt
318
from     dbo.Documents doc
319
where    doc.IsDeleted=0 {sbWhere}";
320

    
321
                if (parameters.Count > 0)
322
                {
323
                    dynamicParameters.AddDynamicParams(parameters);
324
                }
325

    
326
                return ExecuteScalar<int>(query, dynamicParameters);
327
            }
328
            catch (Exception ex)
329
            {
330
                throw ex;
331
            }
332
        }
333

    
334
        public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId)
335
        {
336
            bool isSuccess = false;
337

    
338
            try
339
            {
340
                using (var transaction = base.BeginTransaction())
341
                {
342
                    string query = string.Empty;
343

    
344
                    if (delDocList.Count > 0)
345
                    {
346
                        string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList());
347

    
348
                        if (docIDList.Length > 0)
349
                        {
350
                            query = $@"
351
update dbo.Documents
352
set    IsDeleted=1
353
      ,DeletedDate=getdate(),
354
      ,DeletedUser=@DeletedUser
355
where  DocID in ('{docIDList}');";
356
                            base.Execute(query, new { DeletedUser = userId }, transaction);
357
                        }
358
                    }
359

    
360
                    foreach (Documents doc in docList)
361
                    {
362
                        if (string.IsNullOrEmpty(doc.DocID))
363
                        {
364
                            doc.RegisteredUser = userId;
365
                            query = $@"
366
declare @tbdoc table(docid varchar(36))
367
insert into dbo.Documents
368
(
369
     DocID
370
    ,DocumentNo
371
    ,RevisonNo
372
    ,RefProjectCode
373
    ,DocFilePath
374
    ,DocFileName
375
    ,JobLevel
376
    ,IsTypical
377
    ,PersonInCharge
378
    ,RegisteredDate
379
    ,RegisteredUser
380
    ,ToIsDiscussion
381
    ,ToRemarks
382
    ,ToCreator
383
    ,ToCapture
384
    ,ToIsMarkup
385
    ,FrReviewStatus
386
    ,FrRemarks
387
    ,FrCreator
388
    ,FrCapture
389
    ,FrIsMarkup
390
    ,IsID2Work
391
    ,ID2Connection
392
    ,ID2StartDate
393
    ,ID2EndDate
394
    ,ID2Status
395
    ,ID2Issues
396
    ,AVEVAConnection
397
    ,AVEVAConvertDate
398
    ,AVEVAReviewDate
399
    ,AVEVAStatus
400
    ,AVEVAIssues
401
    ,ReviewFilePath
402
    ,ReviewFileName
403
    ,ProdReviewer
404
    ,ProdIsResult
405
    ,ProdRemarks
406
    ,ClientReviewer
407
    ,ClientIsResult
408
    ,ClientRemarks
409
    ,DTIsGateWay
410
    ,DTIsImport
411
    ,DTIsRegSystem
412
    ,DTRemarks
413
)
414
output inserted.DocID into @tbdoc
415
values 
416
(
417
     lower(newid())
418
    ,@DocumentNo
419
    ,@RevisonNo
420
    ,@RefProjectCode
421
    ,@DocFilePath
422
    ,@DocFileName
423
    ,@JobLevel
424
    ,@IsTypical
425
    ,@PersonInCharge
426
    ,getdate()
427
    ,@RegisteredUser
428
    ,@ToIsDiscussion
429
    ,@ToRemarks
430
    ,@ToCreator
431
    ,@ToCapture
432
    ,@ToIsMarkup
433
    ,@FrReviewStatus
434
    ,@FrRemarks
435
    ,@FrCreator
436
    ,@FrCapture
437
    ,@FrIsMarkup
438
    ,@IsID2Work
439
    ,@ID2Connection
440
    ,@ID2StartDate
441
    ,@ID2EndDate
442
    ,@ID2Status
443
    ,@ID2Issues
444
    ,@AVEVAConnection
445
    ,@AVEVAConvertDate
446
    ,@AVEVAReviewDate
447
    ,@AVEVAStatus
448
    ,@AVEVAIssues
449
    ,@ReviewFilePath
450
    ,@ReviewFileName
451
    ,@ProdReviewer
452
    ,@ProdIsResult
453
    ,@ProdRemarks
454
    ,@ClientReviewer
455
    ,@ClientIsResult
456
    ,@ClientRemarks
457
    ,@DTIsGateWay
458
    ,@DTIsImport
459
    ,@DTIsRegSystem
460
    ,@DTRemarks
461
)
462

    
463
if @@rowcount > 0
464
begin
465
    select docid from @tbdoc
466
end
467
else
468
begin
469
    select ''
470
end;";
471
                        }
472
                        else
473
                        {
474
                            doc.ModifiedUser = userId;
475
                            query = $@"
476
update dbo.Documents
477
set    DocumentNo=@DocumentNo
478
      ,RevisonNo=@RevisonNo
479
      ,RefProjectCode=@RefProjectCode
480
      ,DocFilePath=@DocFilePath
481
      ,DocFileName=@DocFileName
482
      ,JobLevel=@JobLevel
483
      ,IsTypical=@IsTypical
484
      ,PersonInCharge=@PersonInCharge
485
      ,ModifiedDate=getdate()
486
      ,ModifiedUser=@ModifiedUser
487
      ,ToIsDiscussion=@ToIsDiscussion
488
      ,ToRemarks=@ToRemarks
489
      ,ToCreator=@ToCreator
490
      ,ToCapture=@ToCapture
491
      ,ToIsMarkup=@ToIsMarkup
492
      ,FrReviewStatus=@FrReviewStatus
493
      ,FrRemarks=@FrRemarks
494
      ,FrCreator=@FrCreator
495
      ,FrCapture=@FrCapture
496
      ,FrIsMarkup=@FrIsMarkup
497
      ,IsID2Work=@IsID2Work
498
      ,ID2Connection=@ID2Connection
499
      ,ID2StartDate=@ID2StartDate
500
      ,ID2EndDate=@ID2EndDate
501
      ,ID2Status=@ID2Status
502
      ,ID2Issues=@ID2Issues
503
      ,AVEVAConnection=@AVEVAConnection
504
      ,AVEVAConvertDate=@AVEVAConvertDate
505
      ,AVEVAReviewDate=@AVEVAReviewDate
506
      ,AVEVAStatus=@AVEVAStatus
507
      ,AVEVAIssues=@AVEVAIssues
508
      ,ReviewFilePath=@ReviewFilePath
509
      ,ReviewFileName=@ReviewFileName
510
      ,ProdReviewer=@ProdReviewer
511
      ,ProdIsResult=@ProdIsResult
512
      ,ProdRemarks=@ProdRemarks
513
      ,ClientReviewer=@ClientReviewer
514
      ,ClientIsResult=@ClientIsResult
515
      ,ClientRemarks=@ClientRemarks
516
      ,DTIsGateWay=@DTIsGateWay
517
      ,DTIsImport=@DTIsImport
518
      ,DTIsRegSystem=@DTIsRegSystem
519
      ,DTRemarks=@DTRemarks
520
where  DocID=@DocID
521

    
522
if @@rowcount > 0
523
begin
524
    select @DocID
525
end
526
else
527
begin
528
    select ''
529
end;";
530
                        }
531
                        string refID = base.QueryFirstOrDefault<string>(query, doc, transaction);
532

    
533
                        if (doc.AttFiles != null && doc.AttFiles.Count > 0)
534
                        {
535
                            string attDelIDList = string.Join("','", doc.AttFiles.Where(x => !string.IsNullOrEmpty(x.FileID)).Select(x => x.FileID).ToList());
536

    
537
                            if (!string.IsNullOrEmpty(refID) && attDelIDList.Length > 0)
538
                            {
539
                                query = $@"
540
delete from dbo.AttachFIles
541
where  RefID=@RefID and FileID in ('{attDelIDList}');";
542
                                base.Execute(query, new { RefID = refID }, transaction);
543
                            }
544

    
545
                            foreach (AttFileInfo attFile in doc.AttFiles)
546
                            {
547
                                if (string.IsNullOrEmpty(attFile.RefID))
548
                                {
549
                                    attFile.RefID = refID;
550
                                    attFile.Creator = userId;
551

    
552
                                    query = $@"
553
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator)
554
values
555
(
556
    lower(newid())
557
   ,@RefID
558
   ,@Category
559
   ,@FileType
560
   ,@FileName
561
   ,@FilePath
562
   ,@FileExtension
563
   ,@FileData
564
   ,@Creator
565
)";
566

    
567
                                    base.Execute(query, attFile, transaction);
568
                                }
569
                            }
570
                        }
571
                    }
572

    
573
                    transaction.Commit();
574
                    isSuccess = true;
575
                }
576
            }
577
            catch (Exception ex)
578
            {
579
                throw ex;
580
            }
581

    
582
            return isSuccess;
583
        }
584

    
585
        public Documents SetDocumentDataField(Documents doc, string userId)
586
        {
587
            Documents resultData = null;
588

    
589
            try
590
            {
591
                using (var transaction = base.BeginTransaction())
592
                {
593
                    string query = string.Empty;
594

    
595
                    if (!string.IsNullOrEmpty(doc.DocID))
596
                    {
597
                        StringBuilder sbSet = new StringBuilder();
598
                        var parameters = new Dictionary<string, object>();
599

    
600
                        #region Update 할 목록
601
                        if (doc.ID2StartDate != null)
602
                        {
603
                            sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) ");
604
                            parameters.Add("ID2StartDate", doc.ID2StartDate);
605
                        }
606

    
607
                        if (doc.Worker != null)
608
                        {
609
                            sbSet.Append(" ,Worker=@Worker ");
610
                            parameters.Add("Worker", doc.Worker);
611
                        }
612
                        #endregion
613

    
614
                        if (parameters.Count > 0)
615
                        {
616
                            sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
617
                            parameters.Add("ModifiedUser", userId);
618

    
619
                            parameters.Add("DocID", doc.DocID);
620

    
621
                            query = $@"
622
declare @DateTimeNow datetime
623
set @DateTimeNow = getdate()
624

    
625
update dbo.Documents
626
set    ModifiedDate=@DateTimeNow {sbSet}
627
where  [DocID]=@DocID
628

    
629
if @@rowcount > 0
630
begin
631
    select *, datediff(SECOND, ID2StartDate, ID2EndDate) as ID2JobTime from dbo.Documents where DocID=@DocID
632
end
633
else
634
begin
635
    select *, 0 as ID2JobTime from dbo.Documents where 1=2
636
end;";
637
                            resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction);
638
                        }
639
                    }
640

    
641
                    transaction.Commit();
642
                }
643
            }
644
            catch (Exception ex)
645
            {
646
                throw ex;
647
            }
648

    
649
            return resultData;
650
        }
651

    
652
        public bool SetDocumentDatasField(List<Documents> docs, string userId)
653
        {
654
            bool isSuccess = false;
655

    
656
            try
657
            {
658
                using (var transaction = base.BeginTransaction())
659
                {
660
                    foreach (Documents doc in docs)
661
                    {
662
                        string query = string.Empty;
663

    
664
                        if (!string.IsNullOrEmpty(doc.DocID))
665
                        {
666
                            StringBuilder sbSet = new StringBuilder();
667
                            var parameters = new Dictionary<string, object>();
668

    
669
                            #region Update 할 목록
670
                            if (doc.ID2EndDate != null)
671
                            {
672
                                sbSet.Append(" ,ID2EndDate=@ID2EndDate ");
673
                                parameters.Add("ID2EndDate", doc.ID2EndDate);
674
                            }
675
                            #endregion
676

    
677
                            if (parameters.Count > 0)
678
                            {
679
                                sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
680
                                parameters.Add("ModifiedUser", userId);
681

    
682
                                parameters.Add("DocID", doc.DocID);
683

    
684
                                query = $@"
685
update dbo.Documents
686
set    ModifiedDate=getdate() {sbSet}
687
where  [DocID]=@DocID;";
688
                                base.Execute(query, parameters, transaction);
689
                            }
690
                        }
691
                    }
692
                    transaction.Commit();
693
                    isSuccess = true;
694
                }
695
            }
696
            catch (Exception ex)
697
            {
698
                throw ex;
699
            }
700

    
701
            return isSuccess;
702
        }
703

    
704

    
705
        //ID2
706
        public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info)
707
        {
708
            try
709
            {
710
                string query = $@"
711
select @Name PROJECTNAME
712
      ,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME
713
      ,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME]
714
      ,dw.OCCUPIED, dw.[Image]
715
from
716
(
717
    select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx
718
    from   dbo.Drawings
719
) dw;";
720
                return Query<ID2Drawings>(query, id2Info);
721
            }
722
            catch (Exception ex)
723
            {
724
                throw ex;
725
            }
726
        }
727
    }
728
}
클립보드 이미지 추가 (최대 크기: 500 MB)