프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (24.5 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 b2ff5ff4 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 avevaStatus, 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
            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 ee82162b yoush97
            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 08ea0584 yoush97
182 82705273 yoush97
            try
183
            {
184 08499f5f taeseongkim
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 f044f53d taeseongkim
                            select  doc.*, datediff(SECOND, doc.ID2StartDate, doc.ID2EndDate) as ID2JobTime,
188 08499f5f taeseongkim
                            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 e458a996 taeseongkim
                            from     dbo.Documents doc
192 08499f5f taeseongkim
	                        LEFT OUTER JOIN AttachFIles files ON doc.DocID = fIles.RefID 
193 e458a996 taeseongkim
                            LEFT OUTER JOIN 
194 08499f5f taeseongkim
                                    (SELECT [MARKUP_DATA_ID]
195
                                           ,[PROJECT_NO] as PROJECT_NO
196 e458a996 taeseongkim
                                          ,[DOCUMENT_ID] as DocumentNo
197 08499f5f taeseongkim
                                          
198 e458a996 taeseongkim
                                          ,[PAGENUMBER]
199
                                          ,[Text] as TEXT
200
                                          ,[CREATE_DATE] as CREATE_DATE
201
                                          ,[NAME] as CREATE_USER
202 08499f5f taeseongkim
                                      FROM ViewMarkupData) markus 
203 e458a996 taeseongkim
                            ON doc.DocumentNo = markus.DocumentNo
204
                            where    doc.IsDeleted=0 {sbWhere}
205
                            order by doc.Seq
206 7066b8a9 yoush97
207 3ccb1a8d yoush97
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere}
208 7066b8a9 yoush97
select @Total;";
209 8e373ccf yoush97
210 82705273 yoush97
                if (parameters.Count > 0)
211
                {
212
                    dynamicParameters.AddDynamicParams(parameters);
213
                }
214 5898479a yoush97
215 e458a996 taeseongkim
                var docDictionary = new Dictionary<string, Documents>();
216
217 08499f5f taeseongkim
                var ret = MultiQuery<Documents, AttFileInfo, MarkupText, Documents>(query,
218
                                (document, attfile, markusText) =>
219 e458a996 taeseongkim
                                {
220
                                    Documents doc;
221
222 08499f5f taeseongkim
                                    if (!docDictionary.TryGetValue(document.DocID, out doc))
223 e458a996 taeseongkim
                                    {
224
                                        doc = document;
225 08499f5f taeseongkim
                                        docDictionary.Add(doc.DocID, doc);
226
                                    }
227
228
                                    if (markusText != null)
229
                                    {
230 e458a996 taeseongkim
                                        doc.Markups = doc.Markups ?? new List<MarkupText>();
231 08499f5f taeseongkim
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 e8a86b9b yoush97
                                            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 08499f5f taeseongkim
                                            doc.AttFiles.Add(attfile);
261
                                        }
262 e458a996 taeseongkim
                                    }
263
264
                                    return doc;
265
266 08499f5f taeseongkim
                                }, dynamicParameters, splitOn: "DocID,FileID,MARKUP_DATA_ID").Distinct();
267 7066b8a9 yoush97
268 82705273 yoush97
                int totalCount = dynamicParameters.Get<int>("Total");
269 7066b8a9 yoush97
270 82705273 yoush97
                return (ret, totalCount);
271
            }
272
            catch (Exception ex)
273
            {
274
                throw ex;
275
            }
276 5898479a yoush97
        }
277 482f6326 yoush97
278 ff990784 yoush97
        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 54977253 yoush97
        public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId)
323 482f6326 yoush97
        {
324
            bool isSuccess = false;
325
326
            try
327
            {
328 d2d4f84b yoush97
                using (var transaction = base.BeginTransaction())
329 482f6326 yoush97
                {
330 709c1971 yoush97
                    string query = string.Empty;
331
332
                    if (delDocList.Count > 0)
333 482f6326 yoush97
                    {
334 709c1971 yoush97
                        string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList());
335
336
                        if (docIDList.Length > 0)
337
                        {
338 53fde692 yoush97
                            query = $@"
339 74aa670a yoush97
update dbo.Documents
340
set    IsDeleted=1
341 54977253 yoush97
      ,DeletedDate=getdate(),
342
      ,DeletedUser=@DeletedUser
343
where  DocID in ('{docIDList}');";
344
                            base.Execute(query, new { DeletedUser = userId }, transaction);
345 709c1971 yoush97
                        }
346
                    }
347 482f6326 yoush97
348
                    foreach (Documents doc in docList)
349
                    {
350
                        if (string.IsNullOrEmpty(doc.DocID))
351
                        {
352 54977253 yoush97
                            doc.RegisteredUser = userId;
353 482f6326 yoush97
                            query = $@"
354 b1591ae6 yoush97
declare @tbdoc table(docid varchar(36))
355 482f6326 yoush97
insert into dbo.Documents
356
(
357 54977253 yoush97
     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 482f6326 yoush97
)
402 b1591ae6 yoush97
output inserted.DocID into @tbdoc
403 482f6326 yoush97
values 
404
(
405
     lower(newid())
406
    ,@DocumentNo
407
    ,@RevisonNo
408 36a31d25 yoush97
    ,@RefProjectCode
409 482f6326 yoush97
    ,@DocFilePath
410
    ,@DocFileName
411
    ,@JobLevel
412
    ,@IsTypical
413
    ,@PersonInCharge
414 54977253 yoush97
    ,getdate()
415
    ,@RegisteredUser
416 482f6326 yoush97
    ,@ToIsDiscussion
417
    ,@ToRemarks
418
    ,@ToCreator
419 00d11333 yoush97
    ,@ToCapture
420 482f6326 yoush97
    ,@ToIsMarkup
421
    ,@FrReviewStatus
422
    ,@FrRemarks
423
    ,@FrCreator
424 00d11333 yoush97
    ,@FrCapture
425 482f6326 yoush97
    ,@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 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
      ,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 b1591ae6 yoush97
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 e5ade387 yoush97
                                if (string.IsNullOrEmpty(attFile.RefID))
536
                                {
537
                                    attFile.RefID = refID;
538
                                    attFile.Creator = userId;
539 b1591ae6 yoush97
540 e5ade387 yoush97
                                    query = $@"
541 b1591ae6 yoush97
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 e5ade387 yoush97
                                    base.Execute(query, attFile, transaction);
556
                                }
557 b1591ae6 yoush97
                            }
558 482f6326 yoush97
                        }
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 978488b0 yoush97
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 4b8d9ad9 yoush97
                            sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) ");
592 978488b0 yoush97
                            parameters.Add("ID2StartDate", doc.ID2StartDate);
593
                        }
594 4b8d9ad9 yoush97
595
                        if (doc.Worker != null)
596
                        {
597
                            sbSet.Append(" ,Worker=@Worker ");
598
                            parameters.Add("Worker", doc.Worker);
599
                        }
600 978488b0 yoush97
                        #endregion
601
602
                        if (parameters.Count > 0)
603
                        {
604
                            sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
605
                            parameters.Add("ModifiedUser", userId);
606
607 54977253 yoush97
                            parameters.Add("DocID", doc.DocID);
608
609 978488b0 yoush97
                            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 c0420a29 yoush97
    select *, datediff(SECOND, ID2StartDate, ID2EndDate) as ID2JobTime from dbo.Documents where DocID=@DocID
620 978488b0 yoush97
end
621
else
622
begin
623 c0420a29 yoush97
    select *, 0 as ID2JobTime from dbo.Documents where 1=2
624 978488b0 yoush97
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 fe57f64a yoush97
640 54977253 yoush97
        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 e458a996 taeseongkim
                                base.Execute(query, parameters, transaction);
677 54977253 yoush97
                            }
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 fe57f64a yoush97
693
        //ID2
694
        public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info)
695
        {
696 82705273 yoush97
            try
697
            {
698
                string query = $@"
699 fe57f64a yoush97
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 82705273 yoush97
                return Query<ID2Drawings>(query, id2Info);
709
            }
710
            catch (Exception ex)
711
            {
712
                throw ex;
713
            }
714 fe57f64a yoush97
        }
715 5898479a yoush97
    }
716 d2d4f84b yoush97
}
클립보드 이미지 추가 (최대 크기: 500 MB)