hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ d0f44dbd
이력 | 보기 | 이력해설 | 다운로드 (7.64 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 |
from dbo.Documents doc |
73 |
where doc.IsDeleted=0 {sbWhere} |
74 |
order by doc.Seq;"; |
75 |
|
76 |
if (parameters.Count > 0) |
77 |
{ |
78 |
var dynamicParameters = new DynamicParameters(parameters); |
79 |
return Query<Documents>(query, dynamicParameters); |
80 |
} |
81 |
|
82 |
return Query<Documents>(query); |
83 |
} |
84 |
|
85 |
public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList) |
86 |
{ |
87 |
bool isSuccess = false; |
88 |
|
89 |
try |
90 |
{ |
91 |
using (var transaction = base.BeginTransaction()) |
92 |
{ |
93 |
string query = string.Empty; |
94 |
|
95 |
if (delDocList.Count > 0) |
96 |
{ |
97 |
string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList()); |
98 |
|
99 |
if (docIDList.Length > 0) |
100 |
{ |
101 |
query = $@" |
102 |
update dbo.Documents |
103 |
set IsDeleted=1 |
104 |
,DeletedDate=getdate() |
105 |
where [DocID] in ('{docIDList}');"; |
106 |
base.Execute(query, transaction); |
107 |
} |
108 |
} |
109 |
|
110 |
foreach (Documents doc in docList) |
111 |
{ |
112 |
if (string.IsNullOrEmpty(doc.DocID)) |
113 |
{ |
114 |
query = $@" |
115 |
insert into dbo.Documents |
116 |
( |
117 |
[DocID] |
118 |
,[DocumentNo] |
119 |
,[RevisonNo] |
120 |
,[RefProjectCode] |
121 |
,[DocFilePath] |
122 |
,[DocFileName] |
123 |
,[Place] |
124 |
,[JobLevel] |
125 |
,[IsTypical] |
126 |
,[PersonInCharge] |
127 |
,[ToIsDiscussion] |
128 |
,[ToRemarks] |
129 |
,[ToCreator] |
130 |
,[ToCapturePath] |
131 |
,[ToIsMarkup] |
132 |
,[FrReviewStatus] |
133 |
,[FrRemarks] |
134 |
,[FrCreator] |
135 |
,[FrCapturePath] |
136 |
,[FrIsMarkup] |
137 |
,[IsID2Work] |
138 |
,[ID2Connection] |
139 |
,[ID2StartDate] |
140 |
,[ID2EndDate] |
141 |
,[ID2JobTime] |
142 |
,[ID2Status] |
143 |
,[ID2Issues] |
144 |
,[AVEVAConnection] |
145 |
,[AVEVAConvertDate] |
146 |
,[AVEVAReviewDate] |
147 |
,[AVEVAStatus] |
148 |
,[AVEVAIssues] |
149 |
,[ReviewFilePath] |
150 |
,[ReviewFileName] |
151 |
,[ProdReviewer] |
152 |
,[ProdIsResult] |
153 |
,[ProdRemarks] |
154 |
,[ClientReviewer] |
155 |
,[ClientIsResult] |
156 |
,[ClientRemarks] |
157 |
,[DTIsGateWay] |
158 |
,[DTIsImport] |
159 |
,[DTIsRegSystem] |
160 |
,[DTRemarks] |
161 |
) |
162 |
values |
163 |
( |
164 |
lower(newid()) |
165 |
,@DocumentNo |
166 |
,@RevisonNo |
167 |
,@RefProjectCode |
168 |
,@DocFilePath |
169 |
,@DocFileName |
170 |
,@Place |
171 |
,@JobLevel |
172 |
,@IsTypical |
173 |
,@PersonInCharge |
174 |
,@ToIsDiscussion |
175 |
,@ToRemarks |
176 |
,@ToCreator |
177 |
,@ToCapturePath |
178 |
,@ToIsMarkup |
179 |
,@FrReviewStatus |
180 |
,@FrRemarks |
181 |
,@FrCreator |
182 |
,@FrCapturePath |
183 |
,@FrIsMarkup |
184 |
,@IsID2Work |
185 |
,@ID2Connection |
186 |
,@ID2StartDate |
187 |
,@ID2EndDate |
188 |
,@ID2JobTime |
189 |
,@ID2Status |
190 |
,@ID2Issues |
191 |
,@AVEVAConnection |
192 |
,@AVEVAConvertDate |
193 |
,@AVEVAReviewDate |
194 |
,@AVEVAStatus |
195 |
,@AVEVAIssues |
196 |
,@ReviewFilePath |
197 |
,@ReviewFileName |
198 |
,@ProdReviewer |
199 |
,@ProdIsResult |
200 |
,@ProdRemarks |
201 |
,@ClientReviewer |
202 |
,@ClientIsResult |
203 |
,@ClientRemarks |
204 |
,@DTIsGateWay |
205 |
,@DTIsImport |
206 |
,@DTIsRegSystem |
207 |
,@DTRemarks |
208 |
);"; |
209 |
} |
210 |
else |
211 |
{ |
212 |
query = $@" |
213 |
update dbo.Documents |
214 |
set [DocumentNo]=@DocumentNo |
215 |
,[RevisonNo]=@RevisonNo |
216 |
,[RefProjectCode]=@RefProjectCode |
217 |
,[DocFilePath]=@DocFilePath |
218 |
,[DocFileName]=@DocFileName |
219 |
,[Place]=@Place |
220 |
,[JobLevel]=@JobLevel |
221 |
,[IsTypical]=@IsTypical |
222 |
,[PersonInCharge]=@PersonInCharge |
223 |
,[ModifiedDate]=getdate() |
224 |
,[ToIsDiscussion]=@ToIsDiscussion |
225 |
,[ToRemarks]=@ToRemarks |
226 |
,[ToCreator]=@ToCreator |
227 |
,[ToCapturePath]=@ToCapturePath |
228 |
,[ToIsMarkup]=@ToIsMarkup |
229 |
,[FrReviewStatus]=@FrReviewStatus |
230 |
,[FrRemarks]=@FrRemarks |
231 |
,[FrCreator]=@FrCreator |
232 |
,[FrCapturePath]=@FrCapturePath |
233 |
,[FrIsMarkup]=@FrIsMarkup |
234 |
,[IsID2Work]=@IsID2Work |
235 |
,[ID2Connection]=@ID2Connection |
236 |
,[ID2StartDate]=@ID2StartDate |
237 |
,[ID2EndDate]=@ID2EndDate |
238 |
,[ID2JobTime]=@ID2JobTime |
239 |
,[ID2Status]=@ID2Status |
240 |
,[ID2Issues]=@ID2Issues |
241 |
,[AVEVAConnection]=@AVEVAConnection |
242 |
,[AVEVAConvertDate]=@AVEVAConvertDate |
243 |
,[AVEVAReviewDate]=@AVEVAReviewDate |
244 |
,[AVEVAStatus]=@AVEVAStatus |
245 |
,[AVEVAIssues]=@AVEVAIssues |
246 |
,[ReviewFilePath]=@ReviewFilePath |
247 |
,[ReviewFileName]=@ReviewFileName |
248 |
,[ProdReviewer]=@ProdReviewer |
249 |
,[ProdIsResult]=@ProdIsResult |
250 |
,[ProdRemarks]=@ProdRemarks |
251 |
,[ClientReviewer]=@ClientReviewer |
252 |
,[ClientIsResult]=@ClientIsResult |
253 |
,[ClientRemarks]=@ClientRemarks |
254 |
,[DTIsGateWay]=@DTIsGateWay |
255 |
,[DTIsImport]=@DTIsImport |
256 |
,[DTIsRegSystem]=@DTIsRegSystem |
257 |
,[DTRemarks]=@DTRemarks |
258 |
where [DocID]=@DocID;"; |
259 |
} |
260 |
base.Execute(query, doc, transaction); |
261 |
} |
262 |
|
263 |
transaction.Commit(); |
264 |
isSuccess = true; |
265 |
} |
266 |
} |
267 |
catch (Exception ex) |
268 |
{ |
269 |
throw ex; |
270 |
} |
271 |
|
272 |
return isSuccess; |
273 |
} |
274 |
} |
275 |
} |