프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (24.5 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 avevaStatus, 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
            if (!string.IsNullOrEmpty(avevaStatus))
156
            {
157
                sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus ");
158
                parameters.Add("AVEVAStatus", avevaStatus);
159
            }
160

    
161
            if (!string.IsNullOrEmpty(prodIsResult))
162
            {
163
                sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult ");
164
                parameters.Add("ProdIsResult", prodIsResult);
165
            }
166
            if (!string.IsNullOrEmpty(clientIsResult))
167
            {
168
                sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult ");
169
                parameters.Add("ClientIsResult", clientIsResult);
170
            }
171
            if (!string.IsNullOrEmpty(isGateWay))
172
            {
173
                sbWhere.Append(" and doc.DTIsGateWay=@DTIsGateWay ");
174
                parameters.Add("DTIsGateWay", isGateWay);
175
            }
176
            if (!string.IsNullOrEmpty(isRegSystem))
177
            {
178
                sbWhere.Append(" and doc.DTIsRegSystem=@DTIsRegSystem ");
179
                parameters.Add("DTIsRegSystem", isRegSystem);
180
            }
181

    
182
            try
183
            {
184

    
185
                //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,
186
                    string query = $@"
187
                            select  doc.*, datediff(SECOND, doc.ID2StartDate, doc.ID2EndDate) as ID2JobTime,
188
                            files.[FileID] as FileID, files.*,
189
                            markus.MARKUP_DATA_ID as MARKUP_DATA_ID, markus.*, 
190
                            datediff(SECOND, doc.ID2StartDate, doc.ID2EndDate) as ID2JobTime
191
                            from     dbo.Documents doc
192
	                        LEFT OUTER JOIN AttachFIles files ON doc.DocID = fIles.RefID 
193
                            LEFT OUTER JOIN 
194
                                    (SELECT [MARKUP_DATA_ID]
195
                                           ,[PROJECT_NO] as PROJECT_NO
196
                                          ,[DOCUMENT_ID] as DocumentNo
197
                                          
198
                                          ,[PAGENUMBER]
199
                                          ,[Text] as TEXT
200
                                          ,[CREATE_DATE] as CREATE_DATE
201
                                          ,[NAME] as CREATE_USER
202
                                      FROM ViewMarkupData) markus 
203
                            ON doc.DocumentNo = markus.DocumentNo
204
                            where    doc.IsDeleted=0 {sbWhere}
205
                            order by doc.Seq
206

    
207
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere}
208
select @Total;";
209

    
210
                if (parameters.Count > 0)
211
                {
212
                    dynamicParameters.AddDynamicParams(parameters);
213
                }
214

    
215
                var docDictionary = new Dictionary<string, Documents>();
216

    
217
                var ret = MultiQuery<Documents, AttFileInfo, MarkupText, Documents>(query,
218
                                (document, attfile, markusText) =>
219
                                {
220
                                    Documents doc;
221

    
222
                                    if (!docDictionary.TryGetValue(document.DocID, out doc))
223
                                    {
224
                                        doc = document;
225
                                        docDictionary.Add(doc.DocID, doc);
226
                                    }
227

    
228
                                    if (markusText != null)
229
                                    {
230
                                        doc.Markups = doc.Markups ?? new List<MarkupText>();
231

    
232
                                        if (!doc.Markups.Any(x => x.MARKUP_DATA_ID == markusText.MARKUP_DATA_ID))
233
                                        {
234
                                            doc.Markups.Add(markusText);
235
                                        }
236
                                    }
237

    
238
                                    if (attfile != null)
239
                                    {
240
                                        doc.AttFiles = doc.AttFiles ?? new List<AttFileInfo>();
241
                                        System.Diagnostics.Debug.WriteLine(attfile.FileName);
242
                                        if (!doc.AttFiles.Any(x => x.FileID == attfile.FileID))
243
                                        {
244
                                            switch (attfile.Category)
245
                                            {
246
                                                case "toreview":
247
                                                    doc.ToCapture++;
248
                                                    break;
249
                                                case "frreview":
250
                                                    doc.FrCapture++;
251
                                                    break;
252
                                                case "prodvalidation":
253
                                                    doc.ProdCapture++;
254
                                                    break;
255
                                                case "clientvalidation":
256
                                                    doc.ClientCapture++;
257
                                                    break;
258
                                            }
259

    
260
                                            doc.AttFiles.Add(attfile);
261
                                        }
262
                                    }
263

    
264
                                    return doc;
265

    
266
                                }, dynamicParameters, splitOn: "DocID,FileID,MARKUP_DATA_ID").Distinct();
267

    
268
                int totalCount = dynamicParameters.Get<int>("Total");
269

    
270
                return (ret, totalCount);
271
            }
272
            catch (Exception ex)
273
            {
274
                throw ex;
275
            }
276
        }
277

    
278
        public int ExistsDocument(string projectGroupID, List<string> newDwgNos)
279
        {
280
            var dynamicParameters = new DynamicParameters();
281
            StringBuilder sbWhere = new StringBuilder();
282
            var parameters = new Dictionary<string, object>();
283
            if (!string.IsNullOrEmpty(projectGroupID))
284
            {
285
                sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) ");
286
                parameters.Add("RefGroupID", projectGroupID);
287
            }
288

    
289
            if (newDwgNos.Count > 0)
290
            {
291
                string dwgNoList = string.Join("','", newDwgNos.Where(x => !string.IsNullOrEmpty(x)).Select(x => x).ToList());
292

    
293
                if (dwgNoList.Length > 0)
294
                {
295
                    if (!string.IsNullOrEmpty(projectGroupID))
296
                    {
297
                        sbWhere.Append($@" and doc.DocumentNo in ('{dwgNoList}') ");
298
                    }
299
                }
300
            }
301

    
302
            try
303
            {
304
                string query = $@"
305
select   count(*) cnt
306
from     dbo.Documents doc
307
where    doc.IsDeleted=0 {sbWhere}";
308

    
309
                if (parameters.Count > 0)
310
                {
311
                    dynamicParameters.AddDynamicParams(parameters);
312
                }
313

    
314
                return ExecuteScalar<int>(query, dynamicParameters);
315
            }
316
            catch (Exception ex)
317
            {
318
                throw ex;
319
            }
320
        }
321

    
322
        public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId)
323
        {
324
            bool isSuccess = false;
325

    
326
            try
327
            {
328
                using (var transaction = base.BeginTransaction())
329
                {
330
                    string query = string.Empty;
331

    
332
                    if (delDocList.Count > 0)
333
                    {
334
                        string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList());
335

    
336
                        if (docIDList.Length > 0)
337
                        {
338
                            query = $@"
339
update dbo.Documents
340
set    IsDeleted=1
341
      ,DeletedDate=getdate(),
342
      ,DeletedUser=@DeletedUser
343
where  DocID in ('{docIDList}');";
344
                            base.Execute(query, new { DeletedUser = userId }, transaction);
345
                        }
346
                    }
347

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

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

    
510
if @@rowcount > 0
511
begin
512
    select @DocID
513
end
514
else
515
begin
516
    select ''
517
end;";
518
                        }
519
                        string refID = base.QueryFirstOrDefault<string>(query, doc, transaction);
520

    
521
                        if (doc.AttFiles != null && doc.AttFiles.Count > 0)
522
                        {
523
                            string attDelIDList = string.Join("','", doc.AttFiles.Where(x => !string.IsNullOrEmpty(x.FileID)).Select(x => x.FileID).ToList());
524

    
525
                            if (!string.IsNullOrEmpty(refID) && attDelIDList.Length > 0)
526
                            {
527
                                query = $@"
528
delete from dbo.AttachFIles
529
where  RefID=@RefID and FileID in ('{attDelIDList}');";
530
                                base.Execute(query, new { RefID = refID }, transaction);
531
                            }
532

    
533
                            foreach (AttFileInfo attFile in doc.AttFiles)
534
                            {
535
                                if (string.IsNullOrEmpty(attFile.RefID))
536
                                {
537
                                    attFile.RefID = refID;
538
                                    attFile.Creator = userId;
539

    
540
                                    query = $@"
541
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator)
542
values
543
(
544
    lower(newid())
545
   ,@RefID
546
   ,@Category
547
   ,@FileType
548
   ,@FileName
549
   ,@FilePath
550
   ,@FileExtension
551
   ,@FileData
552
   ,@Creator
553
)";
554

    
555
                                    base.Execute(query, attFile, transaction);
556
                                }
557
                            }
558
                        }
559
                    }
560

    
561
                    transaction.Commit();
562
                    isSuccess = true;
563
                }
564
            }
565
            catch (Exception ex)
566
            {
567
                throw ex;
568
            }
569

    
570
            return isSuccess;
571
        }
572

    
573
        public Documents SetDocumentDataField(Documents doc, string userId)
574
        {
575
            Documents resultData = null;
576

    
577
            try
578
            {
579
                using (var transaction = base.BeginTransaction())
580
                {
581
                    string query = string.Empty;
582

    
583
                    if (!string.IsNullOrEmpty(doc.DocID))
584
                    {
585
                        StringBuilder sbSet = new StringBuilder();
586
                        var parameters = new Dictionary<string, object>();
587

    
588
                        #region Update 할 목록
589
                        if (doc.ID2StartDate != null)
590
                        {
591
                            sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) ");
592
                            parameters.Add("ID2StartDate", doc.ID2StartDate);
593
                        }
594

    
595
                        if (doc.Worker != null)
596
                        {
597
                            sbSet.Append(" ,Worker=@Worker ");
598
                            parameters.Add("Worker", doc.Worker);
599
                        }
600
                        #endregion
601

    
602
                        if (parameters.Count > 0)
603
                        {
604
                            sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
605
                            parameters.Add("ModifiedUser", userId);
606

    
607
                            parameters.Add("DocID", doc.DocID);
608

    
609
                            query = $@"
610
declare @DateTimeNow datetime
611
set @DateTimeNow = getdate()
612

    
613
update dbo.Documents
614
set    ModifiedDate=@DateTimeNow {sbSet}
615
where  [DocID]=@DocID
616

    
617
if @@rowcount > 0
618
begin
619
    select *, datediff(SECOND, ID2StartDate, ID2EndDate) as ID2JobTime from dbo.Documents where DocID=@DocID
620
end
621
else
622
begin
623
    select *, 0 as ID2JobTime from dbo.Documents where 1=2
624
end;";
625
                            resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction);
626
                        }
627
                    }
628

    
629
                    transaction.Commit();
630
                }
631
            }
632
            catch (Exception ex)
633
            {
634
                throw ex;
635
            }
636

    
637
            return resultData;
638
        }
639

    
640
        public bool SetDocumentDatasField(List<Documents> docs, string userId)
641
        {
642
            bool isSuccess = false;
643

    
644
            try
645
            {
646
                using (var transaction = base.BeginTransaction())
647
                {
648
                    foreach (Documents doc in docs)
649
                    {
650
                        string query = string.Empty;
651

    
652
                        if (!string.IsNullOrEmpty(doc.DocID))
653
                        {
654
                            StringBuilder sbSet = new StringBuilder();
655
                            var parameters = new Dictionary<string, object>();
656

    
657
                            #region Update 할 목록
658
                            if (doc.ID2EndDate != null)
659
                            {
660
                                sbSet.Append(" ,ID2EndDate=@ID2EndDate ");
661
                                parameters.Add("ID2EndDate", doc.ID2EndDate);
662
                            }
663
                            #endregion
664

    
665
                            if (parameters.Count > 0)
666
                            {
667
                                sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
668
                                parameters.Add("ModifiedUser", userId);
669

    
670
                                parameters.Add("DocID", doc.DocID);
671

    
672
                                query = $@"
673
update dbo.Documents
674
set    ModifiedDate=getdate() {sbSet}
675
where  [DocID]=@DocID;";
676
                                base.Execute(query, parameters, transaction);
677
                            }
678
                        }
679
                    }
680
                    transaction.Commit();
681
                    isSuccess = true;
682
                }
683
            }
684
            catch (Exception ex)
685
            {
686
                throw ex;
687
            }
688

    
689
            return isSuccess;
690
        }
691

    
692

    
693
        //ID2
694
        public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info)
695
        {
696
            try
697
            {
698
                string query = $@"
699
select @Name PROJECTNAME
700
      ,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME
701
      ,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME]
702
      ,dw.OCCUPIED, dw.[Image]
703
from
704
(
705
    select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx
706
    from   dbo.Drawings
707
) dw;";
708
                return Query<ID2Drawings>(query, id2Info);
709
            }
710
            catch (Exception ex)
711
            {
712
                throw ex;
713
            }
714
        }
715
    }
716
}
클립보드 이미지 추가 (최대 크기: 500 MB)