프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (25 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 3cc84cb6 yoush97
                            markus.MARKUP_DATA_ID as MARKUP_DATA_ID, 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 08499f5f taeseongkim
                                    (SELECT [MARKUP_DATA_ID]
207
                                           ,[PROJECT_NO] as PROJECT_NO
208 e458a996 taeseongkim
                                          ,[DOCUMENT_ID] as DocumentNo
209 08499f5f taeseongkim
                                          
210 e458a996 taeseongkim
                                          ,[PAGENUMBER]
211
                                          ,[Text] as TEXT
212
                                          ,[CREATE_DATE] as CREATE_DATE
213
                                          ,[NAME] as CREATE_USER
214 08499f5f taeseongkim
                                      FROM ViewMarkupData) markus 
215 e458a996 taeseongkim
                            ON doc.DocumentNo = markus.DocumentNo
216
                            where    doc.IsDeleted=0 {sbWhere}
217
                            order by doc.Seq
218 7066b8a9 yoush97
219 3ccb1a8d yoush97
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere}
220 7066b8a9 yoush97
select @Total;";
221 8e373ccf yoush97
222 82705273 yoush97
                if (parameters.Count > 0)
223
                {
224
                    dynamicParameters.AddDynamicParams(parameters);
225
                }
226 5898479a yoush97
227 e458a996 taeseongkim
                var docDictionary = new Dictionary<string, Documents>();
228
229 08499f5f taeseongkim
                var ret = MultiQuery<Documents, AttFileInfo, MarkupText, Documents>(query,
230
                                (document, attfile, markusText) =>
231 e458a996 taeseongkim
                                {
232
                                    Documents doc;
233
234 08499f5f taeseongkim
                                    if (!docDictionary.TryGetValue(document.DocID, out doc))
235 e458a996 taeseongkim
                                    {
236
                                        doc = document;
237 08499f5f taeseongkim
                                        docDictionary.Add(doc.DocID, doc);
238
                                    }
239
240
                                    if (markusText != null)
241
                                    {
242 e458a996 taeseongkim
                                        doc.Markups = doc.Markups ?? new List<MarkupText>();
243 08499f5f taeseongkim
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 e8a86b9b yoush97
                                            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 08499f5f taeseongkim
                                            doc.AttFiles.Add(attfile);
273
                                        }
274 e458a996 taeseongkim
                                    }
275
276
                                    return doc;
277
278 08499f5f taeseongkim
                                }, dynamicParameters, splitOn: "DocID,FileID,MARKUP_DATA_ID").Distinct();
279 7066b8a9 yoush97
280 82705273 yoush97
                int totalCount = dynamicParameters.Get<int>("Total");
281 7066b8a9 yoush97
282 82705273 yoush97
                return (ret, totalCount);
283
            }
284
            catch (Exception ex)
285
            {
286
                throw ex;
287
            }
288 5898479a yoush97
        }
289 482f6326 yoush97
290 ff990784 yoush97
        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 54977253 yoush97
        public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId)
335 482f6326 yoush97
        {
336
            bool isSuccess = false;
337
338
            try
339
            {
340 d2d4f84b yoush97
                using (var transaction = base.BeginTransaction())
341 482f6326 yoush97
                {
342 709c1971 yoush97
                    string query = string.Empty;
343
344
                    if (delDocList.Count > 0)
345 482f6326 yoush97
                    {
346 709c1971 yoush97
                        string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList());
347
348
                        if (docIDList.Length > 0)
349
                        {
350 53fde692 yoush97
                            query = $@"
351 74aa670a yoush97
update dbo.Documents
352
set    IsDeleted=1
353 54977253 yoush97
      ,DeletedDate=getdate(),
354
      ,DeletedUser=@DeletedUser
355
where  DocID in ('{docIDList}');";
356
                            base.Execute(query, new { DeletedUser = userId }, transaction);
357 709c1971 yoush97
                        }
358
                    }
359 482f6326 yoush97
360
                    foreach (Documents doc in docList)
361
                    {
362
                        if (string.IsNullOrEmpty(doc.DocID))
363
                        {
364 54977253 yoush97
                            doc.RegisteredUser = userId;
365 482f6326 yoush97
                            query = $@"
366 b1591ae6 yoush97
declare @tbdoc table(docid varchar(36))
367 482f6326 yoush97
insert into dbo.Documents
368
(
369 54977253 yoush97
     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 482f6326 yoush97
)
414 b1591ae6 yoush97
output inserted.DocID into @tbdoc
415 482f6326 yoush97
values 
416
(
417
     lower(newid())
418
    ,@DocumentNo
419
    ,@RevisonNo
420 36a31d25 yoush97
    ,@RefProjectCode
421 482f6326 yoush97
    ,@DocFilePath
422
    ,@DocFileName
423
    ,@JobLevel
424
    ,@IsTypical
425
    ,@PersonInCharge
426 54977253 yoush97
    ,getdate()
427
    ,@RegisteredUser
428 482f6326 yoush97
    ,@ToIsDiscussion
429
    ,@ToRemarks
430
    ,@ToCreator
431 00d11333 yoush97
    ,@ToCapture
432 482f6326 yoush97
    ,@ToIsMarkup
433
    ,@FrReviewStatus
434
    ,@FrRemarks
435
    ,@FrCreator
436 00d11333 yoush97
    ,@FrCapture
437 482f6326 yoush97
    ,@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 b1591ae6 yoush97
)
462
463
if @@rowcount > 0
464
begin
465
    select docid from @tbdoc
466
end
467
else
468
begin
469
    select ''
470
end;";
471 482f6326 yoush97
                        }
472
                        else
473
                        {
474 54977253 yoush97
                            doc.ModifiedUser = userId;
475 482f6326 yoush97
                            query = $@"
476
update dbo.Documents
477 54977253 yoush97
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 b1591ae6 yoush97
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 e5ade387 yoush97
                                if (string.IsNullOrEmpty(attFile.RefID))
548
                                {
549
                                    attFile.RefID = refID;
550
                                    attFile.Creator = userId;
551 b1591ae6 yoush97
552 e5ade387 yoush97
                                    query = $@"
553 b1591ae6 yoush97
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 e5ade387 yoush97
                                    base.Execute(query, attFile, transaction);
568
                                }
569 b1591ae6 yoush97
                            }
570 482f6326 yoush97
                        }
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 978488b0 yoush97
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 4b8d9ad9 yoush97
                            sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) ");
604 978488b0 yoush97
                            parameters.Add("ID2StartDate", doc.ID2StartDate);
605
                        }
606 4b8d9ad9 yoush97
607
                        if (doc.Worker != null)
608
                        {
609
                            sbSet.Append(" ,Worker=@Worker ");
610
                            parameters.Add("Worker", doc.Worker);
611
                        }
612 978488b0 yoush97
                        #endregion
613
614
                        if (parameters.Count > 0)
615
                        {
616
                            sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
617
                            parameters.Add("ModifiedUser", userId);
618
619 54977253 yoush97
                            parameters.Add("DocID", doc.DocID);
620
621 978488b0 yoush97
                            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 c0420a29 yoush97
    select *, datediff(SECOND, ID2StartDate, ID2EndDate) as ID2JobTime from dbo.Documents where DocID=@DocID
632 978488b0 yoush97
end
633
else
634
begin
635 c0420a29 yoush97
    select *, 0 as ID2JobTime from dbo.Documents where 1=2
636 978488b0 yoush97
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 fe57f64a yoush97
652 54977253 yoush97
        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 e458a996 taeseongkim
                                base.Execute(query, parameters, transaction);
689 54977253 yoush97
                            }
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 fe57f64a yoush97
705
        //ID2
706
        public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info)
707
        {
708 82705273 yoush97
            try
709
            {
710
                string query = $@"
711 fe57f64a yoush97
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 82705273 yoush97
                return Query<ID2Drawings>(query, id2Info);
721
            }
722
            catch (Exception ex)
723
            {
724
                throw ex;
725
            }
726 fe57f64a yoush97
        }
727 5898479a yoush97
    }
728 d2d4f84b yoush97
}
클립보드 이미지 추가 (최대 크기: 500 MB)