프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 8e373ccf

이력 | 보기 | 이력해설 | 다운로드 (6.42 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 projectID, string personIncharge, string documentNo)
18
        {
19
            StringBuilder sbWhere = new StringBuilder();
20
            var parameters = new Dictionary<string, object>();
21
            if (!string.IsNullOrEmpty(projectID))
22
            {
23
                sbWhere.Append(" and doc.RefProjectID=@RefProjectID ");
24
                parameters.Add("RefProjectID", projectID);
25
            }
26
            if (!string.IsNullOrEmpty(personIncharge))
27
            {
28
                sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge ");
29
                parameters.Add("PersonInCharge", personIncharge);
30
            }
31
            if (!string.IsNullOrEmpty(documentNo))
32
            {
33
                sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' ");
34
                parameters.Add("DocumentNo", documentNo);
35
            }
36

    
37
            string query = $@"
38
select   doc.*
39
from     dbo.Documents doc
40
where    doc.IsDeleted=0 {sbWhere}
41
order by doc.Seq;";
42

    
43
            if (parameters.Count > 0)
44
            {
45
                var dynamicParameters = new DynamicParameters(parameters);
46
                return Query<Documents>(query, dynamicParameters);
47
            }
48

    
49
            return Query<Documents>(query);
50
        }
51

    
52
        public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList)
53
        {
54
            bool isSuccess = false;
55

    
56
            try
57
            {
58
                using (var transaction = base.BeginTransaction())
59
                {
60
                    string query = string.Empty;
61

    
62
                    if (delDocList.Count > 0)
63
                    {
64
                        string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList());
65

    
66
                        if (docIDList.Length > 0)
67
                        {
68
                            query = $@"
69
update dbo.Documents
70
set    IsDeleted=1
71
      ,DeletedDate=getdate()
72
where  [DocID] in ('{docIDList}');";
73
                            base.Execute(query, transaction);
74
                        }
75
                    }
76

    
77
                    foreach (Documents doc in docList)
78
                    {
79
                        if (string.IsNullOrEmpty(doc.DocID))
80
                        {
81
                            query = $@"
82
insert into dbo.Documents
83
(
84
     [DocID]
85
    ,[DocumentNo]
86
    ,[RevisonNo]
87
    ,[RefProjectID]
88
    ,[DocFilePath]
89
    ,[DocFileName]
90
    ,[Place]
91
    ,[JobLevel]
92
    ,[IsTypical]
93
    ,[PersonInCharge]
94
    ,[ToIsDiscussion]
95
    ,[ToRemarks]
96
    ,[ToCreator]
97
    ,[ToModifier]
98
    ,[ToCapturePath]
99
    ,[ToIsMarkup]
100
    ,[FrReviewStatus]
101
    ,[FrRemarks]
102
    ,[FrCreator]
103
    ,[FrModifier]
104
    ,[FrCapturePath]
105
    ,[FrIsMarkup]
106
    ,[IsID2Work]
107
    ,[ID2Connection]
108
    ,[ID2StartDate]
109
    ,[ID2EndDate]
110
    ,[ID2JobTime]
111
    ,[ID2Status]
112
    ,[ID2Issues]
113
    ,[AVEVAConnection]
114
    ,[AVEVAConvertDate]
115
    ,[AVEVAReviewDate]
116
    ,[AVEVAStatus]
117
    ,[AVEVAIssues]
118
    ,[ReviewFilePath]
119
    ,[ReviewFileName]
120
    ,[ProdReviewer]
121
    ,[ProdIsResult]
122
    ,[ProdRemarks]
123
    ,[ClientReviewer]
124
    ,[ClientIsResult]
125
    ,[ClientRemarks]
126
    ,[DTIsGateWay]
127
    ,[DTIsImport]
128
    ,[DTIsRegSystem]
129
    ,[DTRemarks]
130
)
131
values 
132
(
133
     lower(newid())
134
    ,@DocumentNo
135
    ,@RevisonNo
136
    ,@RefProjectID
137
    ,@DocFilePath
138
    ,@DocFileName
139
    ,@Place
140
    ,@JobLevel
141
    ,@IsTypical
142
    ,@PersonInCharge
143
    ,@ToIsDiscussion
144
    ,@ToRemarks
145
    ,@ToCreator
146
    ,@ToModifier
147
    ,@ToCapturePath
148
    ,@ToIsMarkup
149
    ,@FrReviewStatus
150
    ,@FrRemarks
151
    ,@FrCreator
152
    ,@FrModifier
153
    ,@FrCapturePath
154
    ,@FrIsMarkup
155
    ,@IsID2Work
156
    ,@ID2Connection
157
    ,@ID2StartDate
158
    ,@ID2EndDate
159
    ,@ID2JobTime
160
    ,@ID2Status
161
    ,@ID2Issues
162
    ,@AVEVAConnection
163
    ,@AVEVAConvertDate
164
    ,@AVEVAReviewDate
165
    ,@AVEVAStatus
166
    ,@AVEVAIssues
167
    ,@ReviewFilePath
168
    ,@ReviewFileName
169
    ,@ProdReviewer
170
    ,@ProdIsResult
171
    ,@ProdRemarks
172
    ,@ClientReviewer
173
    ,@ClientIsResult
174
    ,@ClientRemarks
175
    ,@DTIsGateWay
176
    ,@DTIsImport
177
    ,@DTIsRegSystem
178
    ,@DTRemarks
179
);";
180
                        }
181
                        else
182
                        {
183
                            query = $@"
184
update dbo.Documents
185
set    [DocumentNo]=@DocumentNo
186
      ,[RevisonNo]=@RevisonNo
187
      ,[RefProjectID]=@RefProjectID
188
      ,[DocFilePath]=@DocFilePath
189
      ,[DocFileName]=@DocFileName
190
      ,[Place]=@Place
191
      ,[JobLevel]=@JobLevel
192
      ,[IsTypical]=@IsTypical
193
      ,[PersonInCharge]=@PersonInCharge
194
      ,[ModifiedDate]=getdate()
195
      ,[ToIsDiscussion]=@ToIsDiscussion
196
      ,[ToRemarks]=@ToRemarks
197
      ,[ToCreator]=@ToCreator
198
      ,[ToModifier]=@ToModifier
199
      ,[ToCapturePath]=@ToCapturePath
200
      ,[ToIsMarkup]=@ToIsMarkup
201
      ,[FrReviewStatus]=@FrReviewStatus
202
      ,[FrRemarks]=@FrRemarks
203
      ,[FrCreator]=@FrCreator
204
      ,[FrModifier]=@FrModifier
205
      ,[FrCapturePath]=@FrCapturePath
206
      ,[FrIsMarkup]=@FrIsMarkup
207
      ,[IsID2Work]=@IsID2Work
208
      ,[ID2Connection]=@ID2Connection
209
      ,[ID2StartDate]=@ID2StartDate
210
      ,[ID2EndDate]=@ID2EndDate
211
      ,[ID2JobTime]=@ID2JobTime
212
      ,[ID2Status]=@ID2Status
213
      ,[ID2Issues]=@ID2Issues
214
      ,[AVEVAConnection]=@AVEVAConnection
215
      ,[AVEVAConvertDate]=@AVEVAConvertDate
216
      ,[AVEVAReviewDate]=@AVEVAReviewDate
217
      ,[AVEVAStatus]=@AVEVAStatus
218
      ,[AVEVAIssues]=@AVEVAIssues
219
      ,[ReviewFilePath]=@ReviewFilePath
220
      ,[ReviewFileName]=@ReviewFileName
221
      ,[ProdReviewer]=@ProdReviewer
222
      ,[ProdIsResult]=@ProdIsResult
223
      ,[ProdRemarks]=@ProdRemarks
224
      ,[ClientReviewer]=@ClientReviewer
225
      ,[ClientIsResult]=@ClientIsResult
226
      ,[ClientRemarks]=@ClientRemarks
227
      ,[DTIsGateWay]=@DTIsGateWay
228
      ,[DTIsImport]=@DTIsImport
229
      ,[DTIsRegSystem]=@DTIsRegSystem
230
      ,[DTRemarks]=@DTRemarks
231
where  [DocID]=@DocID;";
232
                        }
233
                        base.Execute(query, doc, transaction);
234
                    }
235

    
236
                    transaction.Commit();
237
                    isSuccess = true;
238
                }
239
            }
240
            catch (Exception ex)
241
            {
242
                throw ex;
243
            }
244

    
245
            return isSuccess;
246
        }
247
    }
248
}
클립보드 이미지 추가 (최대 크기: 500 MB)