프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (10.2 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 ID2.Manager.Data.Models;
8

    
9
using Dapper;
10

    
11
namespace ID2.Manager.Dapper.Repository
12
{
13
    public class DocumentRepository : BaseRepository
14
    {
15
        public DocumentRepository(string connectionStr) : base(connectionStr) { }
16

    
17
        public IEnumerable<Documents> GetAllDocuments(string projectCode, string personIncharge, string jobLevel, string documentNo, string isID2Work, string id2Status, string avevaStatus, string prodIsResult, string clientIsResult)
18
        {
19
            StringBuilder sbWhere = new StringBuilder();
20
            var parameters = new Dictionary<string, object>();
21
            if (!string.IsNullOrEmpty(projectCode))
22
            {
23
                sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode ");
24
                parameters.Add("RefProjectCode", projectCode);
25
            }
26
            if (!string.IsNullOrEmpty(personIncharge))
27
            {
28
                sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge ");
29
                parameters.Add("PersonInCharge", personIncharge);
30
            }
31
            if (!string.IsNullOrEmpty(jobLevel))
32
            {
33
                sbWhere.Append(" and doc.JobLevel=@JobLevel ");
34
                parameters.Add("JobLevel", jobLevel);
35
            }
36
            if (!string.IsNullOrEmpty(documentNo))
37
            {
38
                sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' ");
39
                parameters.Add("DocumentNo", documentNo);
40
            }
41

    
42
            if (!string.IsNullOrEmpty(isID2Work))
43
            {
44
                sbWhere.Append(" and doc.IsID2Work=@IsID2Work ");
45
                parameters.Add("IsID2Work", isID2Work);
46
            }
47

    
48
            if (!string.IsNullOrEmpty(id2Status))
49
            {
50
                sbWhere.Append(" and doc.ID2Status=@ID2Status ");
51
                parameters.Add("ID2Status", id2Status);
52
            }
53
            if (!string.IsNullOrEmpty(avevaStatus))
54
            {
55
                sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus ");
56
                parameters.Add("AVEVAStatus", avevaStatus);
57
            }
58

    
59
            if (!string.IsNullOrEmpty(prodIsResult))
60
            {
61
                sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult ");
62
                parameters.Add("ProdIsResult", prodIsResult);
63
            }
64
            if (!string.IsNullOrEmpty(clientIsResult))
65
            {
66
                sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult ");
67
                parameters.Add("ClientIsResult", clientIsResult);
68
            }
69

    
70
            string query = $@"
71
select   doc.*,
72

    
73
  (
74
    select markus.*
75
	from [markus_SEC].[dbo].[ViewMarkupData] markus where doc.DocumentNo = markus.DOCUMENT_ID
76
	FOR JSON PATH
77
  ) as MarkupText
78
from     dbo.Documents doc
79
where    doc.IsDeleted=0 {sbWhere}
80
order by doc.Seq;";
81

    
82
            if (parameters.Count > 0)
83
            {
84
                var dynamicParameters = new DynamicParameters(parameters);
85
                return Query<Documents>(query, dynamicParameters);
86
            }
87

    
88
            return Query<Documents>(query);
89
        }
90

    
91
        public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList)
92
        {
93
            bool isSuccess = false;
94

    
95
            try
96
            {
97
                using (var transaction = base.BeginTransaction())
98
                {
99
                    string query = string.Empty;
100

    
101
                    if (delDocList.Count > 0)
102
                    {
103
                        string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList());
104

    
105
                        if (docIDList.Length > 0)
106
                        {
107
                            query = $@"
108
update dbo.Documents
109
set    IsDeleted=1
110
      ,DeletedDate=getdate()
111
where  [DocID] in ('{docIDList}');";
112
                            base.Execute(query, transaction);
113
                        }
114
                    }
115

    
116
                    foreach (Documents doc in docList)
117
                    {
118
                        if (string.IsNullOrEmpty(doc.DocID))
119
                        {
120
                            query = $@"
121
insert into dbo.Documents
122
(
123
     [DocID]
124
    ,[DocumentNo]
125
    ,[RevisonNo]
126
    ,[RefProjectCode]
127
    ,[DocFilePath]
128
    ,[DocFileName]
129
    ,[JobLevel]
130
    ,[IsTypical]
131
    ,[PersonInCharge]
132
    ,[ToIsDiscussion]
133
    ,[ToRemarks]
134
    ,[ToCreator]
135
    ,[ToCapturePath]
136
    ,[ToIsMarkup]
137
    ,[FrReviewStatus]
138
    ,[FrRemarks]
139
    ,[FrCreator]
140
    ,[FrCapturePath]
141
    ,[FrIsMarkup]
142
    ,[IsID2Work]
143
    ,[ID2Connection]
144
    ,[ID2StartDate]
145
    ,[ID2EndDate]
146
    ,[ID2JobTime]
147
    ,[ID2Status]
148
    ,[ID2Issues]
149
    ,[AVEVAConnection]
150
    ,[AVEVAConvertDate]
151
    ,[AVEVAReviewDate]
152
    ,[AVEVAStatus]
153
    ,[AVEVAIssues]
154
    ,[ReviewFilePath]
155
    ,[ReviewFileName]
156
    ,[ProdReviewer]
157
    ,[ProdIsResult]
158
    ,[ProdRemarks]
159
    ,[ClientReviewer]
160
    ,[ClientIsResult]
161
    ,[ClientRemarks]
162
    ,[DTIsGateWay]
163
    ,[DTIsImport]
164
    ,[DTIsRegSystem]
165
    ,[DTRemarks]
166
)
167
values 
168
(
169
     lower(newid())
170
    ,@DocumentNo
171
    ,@RevisonNo
172
    ,@RefProjectCode
173
    ,@DocFilePath
174
    ,@DocFileName
175
    ,@JobLevel
176
    ,@IsTypical
177
    ,@PersonInCharge
178
    ,@ToIsDiscussion
179
    ,@ToRemarks
180
    ,@ToCreator
181
    ,@ToCapturePath
182
    ,@ToIsMarkup
183
    ,@FrReviewStatus
184
    ,@FrRemarks
185
    ,@FrCreator
186
    ,@FrCapturePath
187
    ,@FrIsMarkup
188
    ,@IsID2Work
189
    ,@ID2Connection
190
    ,@ID2StartDate
191
    ,@ID2EndDate
192
    ,@ID2JobTime
193
    ,@ID2Status
194
    ,@ID2Issues
195
    ,@AVEVAConnection
196
    ,@AVEVAConvertDate
197
    ,@AVEVAReviewDate
198
    ,@AVEVAStatus
199
    ,@AVEVAIssues
200
    ,@ReviewFilePath
201
    ,@ReviewFileName
202
    ,@ProdReviewer
203
    ,@ProdIsResult
204
    ,@ProdRemarks
205
    ,@ClientReviewer
206
    ,@ClientIsResult
207
    ,@ClientRemarks
208
    ,@DTIsGateWay
209
    ,@DTIsImport
210
    ,@DTIsRegSystem
211
    ,@DTRemarks
212
);";
213
                        }
214
                        else
215
                        {
216
                            query = $@"
217
update dbo.Documents
218
set    [DocumentNo]=@DocumentNo
219
      ,[RevisonNo]=@RevisonNo
220
      ,[RefProjectCode]=@RefProjectCode
221
      ,[DocFilePath]=@DocFilePath
222
      ,[DocFileName]=@DocFileName
223
      ,[JobLevel]=@JobLevel
224
      ,[IsTypical]=@IsTypical
225
      ,[PersonInCharge]=@PersonInCharge
226
      ,[ModifiedDate]=getdate()
227
      ,[ToIsDiscussion]=@ToIsDiscussion
228
      ,[ToRemarks]=@ToRemarks
229
      ,[ToCreator]=@ToCreator
230
      ,[ToCapturePath]=@ToCapturePath
231
      ,[ToIsMarkup]=@ToIsMarkup
232
      ,[FrReviewStatus]=@FrReviewStatus
233
      ,[FrRemarks]=@FrRemarks
234
      ,[FrCreator]=@FrCreator
235
      ,[FrCapturePath]=@FrCapturePath
236
      ,[FrIsMarkup]=@FrIsMarkup
237
      ,[IsID2Work]=@IsID2Work
238
      ,[ID2Connection]=@ID2Connection
239
      ,[ID2StartDate]=@ID2StartDate
240
      ,[ID2EndDate]=@ID2EndDate
241
      ,[ID2JobTime]=@ID2JobTime
242
      ,[ID2Status]=@ID2Status
243
      ,[ID2Issues]=@ID2Issues
244
      ,[AVEVAConnection]=@AVEVAConnection
245
      ,[AVEVAConvertDate]=@AVEVAConvertDate
246
      ,[AVEVAReviewDate]=@AVEVAReviewDate
247
      ,[AVEVAStatus]=@AVEVAStatus
248
      ,[AVEVAIssues]=@AVEVAIssues
249
      ,[ReviewFilePath]=@ReviewFilePath
250
      ,[ReviewFileName]=@ReviewFileName
251
      ,[ProdReviewer]=@ProdReviewer
252
      ,[ProdIsResult]=@ProdIsResult
253
      ,[ProdRemarks]=@ProdRemarks
254
      ,[ClientReviewer]=@ClientReviewer
255
      ,[ClientIsResult]=@ClientIsResult
256
      ,[ClientRemarks]=@ClientRemarks
257
      ,[DTIsGateWay]=@DTIsGateWay
258
      ,[DTIsImport]=@DTIsImport
259
      ,[DTIsRegSystem]=@DTIsRegSystem
260
      ,[DTRemarks]=@DTRemarks
261
where  [DocID]=@DocID;";
262
                        }
263
                        base.Execute(query, doc, transaction);
264
                    }
265

    
266
                    transaction.Commit();
267
                    isSuccess = true;
268
                }
269
            }
270
            catch (Exception ex)
271
            {
272
                throw ex;
273
            }
274

    
275
            return isSuccess;
276
        }
277

    
278
        public Documents SetDocumentDataField(Documents doc, string userId)
279
        {
280
            Documents resultData = null;
281

    
282
            try
283
            {
284
                using (var transaction = base.BeginTransaction())
285
                {
286
                    string query = string.Empty;
287

    
288
                    if (!string.IsNullOrEmpty(doc.DocID))
289
                    {
290
                        StringBuilder sbSet = new StringBuilder();
291
                        var parameters = new Dictionary<string, object>();
292

    
293
                        #region Update 할 목록
294
                        if (doc.ID2StartDate != null)
295
                        {
296
                            sbSet.Append(" ,ID2StartDate=@DateTimeNow ");
297
                            parameters.Add("ID2StartDate", doc.ID2StartDate);
298
                        }
299
                        #endregion
300

    
301
                        if (parameters.Count > 0)
302
                        {
303
                            sbSet.Append(" ,DocID=@DocID ");
304
                            parameters.Add("DocID", doc.DocID);
305

    
306
                            sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
307
                            parameters.Add("ModifiedUser", userId);
308

    
309
                            query = $@"
310
declare @DateTimeNow datetime
311
set @DateTimeNow = getdate()
312

    
313
update dbo.Documents
314
set    ModifiedDate=@DateTimeNow {sbSet}
315
where  [DocID]=@DocID
316

    
317
if @@rowcount > 0
318
begin
319
    select * from dbo.Documents where DocID=@DocID
320
end
321
else
322
begin
323
    select * from dbo.Documents where 1=2
324
end;";
325
                            resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction);
326
                        }
327
                    }
328

    
329
                    transaction.Commit();
330
                }
331
            }
332
            catch (Exception ex)
333
            {
334
                throw ex;
335
            }
336

    
337
            return resultData;
338
        }
339

    
340

    
341
        //ID2
342
        public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info)
343
        {
344
            string query = $@"
345
select @Name PROJECTNAME
346
      ,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME
347
      ,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME]
348
      ,dw.OCCUPIED, dw.[Image]
349
from
350
(
351
    select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx
352
    from   dbo.Drawings
353
) dw;";
354
            return Query<ID2Drawings>(query, id2Info);
355
        }
356
    }
357
}
클립보드 이미지 추가 (최대 크기: 500 MB)