프로젝트

일반

사용자정보

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

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / MarkusRepository.cs @ 7a9c6a5b

이력 | 보기 | 이력해설 | 다운로드 (13.1 KB)

1 1a88080d taeseongkim
using Dapper;
2
using DapperParameters;
3
using ID2.Manager.Dapper.Entities;
4 0b008ea6 taeseongkim
using ID2.Manager.Data.Models;
5 1a88080d taeseongkim
using System;
6
using System.Collections.Generic;
7
using System.Data;
8
using System.Linq;
9
using System.Text;
10
using System.Threading.Tasks;
11
12
namespace ID2.Manager.Dapper.Repository
13
{
14
    public class MarkusRepository : BaseRepository
15
    {
16
        public MarkusRepository(string connectionStr) : base(connectionStr) { }
17
18 c112c3c3 taeseongkim
        public bool Insert(string ProjectNo,string Name)
19 1a88080d taeseongkim
        {
20
            bool result = false;
21
22 d1d8c5ea taeseongkim
            var convertDocID = CreateConvertDoc(ProjectNo, Name + ".pdf", Name);
23 1a88080d taeseongkim
24
            if (convertDocID != null)
25
            {
26 c112c3c3 taeseongkim
                var documentItemID = CreateOrUPdateDocItem(
27 1a88080d taeseongkim
                    new DOCUMENTITEM
28
                    {
29
                        REVISION = "0",
30
                        PROJECT_NO = ProjectNo,
31
                        DOCUMENT_NO = Name,
32
                        GROUP_NO = Name,
33
                        DOCUMENT_NAME = Name,
34
                        ORIGINAL_FILE = Name,
35
                        DOCUMENT_ID = Name
36
                    });
37
38 d1d8c5ea taeseongkim
                if (documentItemID != null)
39 1a88080d taeseongkim
                {
40
                    result = true;
41
                }
42
            }
43
44
            return result;
45
        }
46
47 5b086e44 taeseongkim
        public bool InsertOrUpdateUsers(MEMBER member)
48 7298c115 taeseongkim
        {
49
            bool result = false;
50
51
            try
52
            {
53 5b086e44 taeseongkim
                var oMember = GetMEMBER(member.ID);
54 7298c115 taeseongkim
55 5b086e44 taeseongkim
                if(oMember?.Count() > 0)
56
                {
57
                    var tran = BeginTransaction();
58
59
                    string SQL = "UPDATE MEMBER" +
60
                        " SET " +
61
                        "DEPARTMENT = @DEPARTMENT" +
62
                        ",NAME = @NAME" +
63
                        ",POSITION = @POSITION" +
64
                        ",EMAIL_ADDRESS = @EMAIL_ADDRESS" +
65
                        ",PASSWORD = @PASSWORD" +
66
                        ",COMPANY = @COMPANY" +
67
                        ",CREATE_DATETIME = @CREATE_DATETIME" +
68
                        ",MODIFIED_DATETIME = @MODIFIED_DATETIME" +
69
                        ",ISLICENSE = @ISLICENSE" +
70 99c0623d yoush97
                        " WHERE ID = @ID";
71 5b086e44 taeseongkim
72
73
                    var parameters = new DynamicParameters();
74
                    parameters.Add("@ID", member.ID);
75
                    parameters.Add("@DEPARTMENT", member.DEPARTMENT);
76
                    parameters.Add("@NAME", member.NAME);
77
                    parameters.Add("@POSITION", member.POSITION);
78
                    parameters.Add("@EMAIL_ADDRESS", member.EMAIL_ADDRESS);
79
                    parameters.Add("@PASSWORD", member.PASSWORD);
80
                    parameters.Add("@COMPANY", member.COMPANY);
81
                    parameters.Add("@CREATE_DATETIME", member.CREATE_DATETIME);
82
                    parameters.Add("@MODIFIED_DATETIME", member.MODIFIED_DATETIME);
83
                    parameters.Add("@ISLICENSE", member.ISLICENSE);
84
85
                    var rowsAffected = base.Execute(SQL, parameters, tran);
86
87
88
                    if (rowsAffected < 0)
89
                    {
90
                        result = false;
91
                    }
92
                    else
93
                    {
94
                        tran.Commit();
95
                    }
96
                }
97
                else
98
                {
99
                    var tran = BeginTransaction();
100
101
                    string SQL = "INSERT INTO MEMBER (ID,DEPARTMENT,NAME,POSITION,EMAIL_ADDRESS,PASSWORD,COMPANY,CREATE_DATETIME,MODIFIED_DATETIME,ISLICENSE) " +
102
                        "VALUES (@ID,@DEPARTMENT,@NAME,@POSITION,@EMAIL_ADDRESS,@PASSWORD,@COMPANY,@CREATE_DATETIME,@MODIFIED_DATETIME,@ISLICENSE)";
103
104
105
                    var parameters = new DynamicParameters();
106
                    parameters.Add("@ID", member.ID);
107
                    parameters.Add("@DEPARTMENT", member.DEPARTMENT);
108
                    parameters.Add("@NAME", member.NAME);
109
                    parameters.Add("@POSITION", member.POSITION);
110
                    parameters.Add("@EMAIL_ADDRESS", member.EMAIL_ADDRESS);
111
                    parameters.Add("@PASSWORD", member.PASSWORD);
112
                    parameters.Add("@COMPANY", member.COMPANY);
113
                    parameters.Add("@CREATE_DATETIME", member.CREATE_DATETIME);
114
                    parameters.Add("@MODIFIED_DATETIME", member.MODIFIED_DATETIME);
115
                    parameters.Add("@ISLICENSE", member.ISLICENSE);
116
117
                    var rowsAffected = base.Execute(SQL, parameters, tran);
118
119
120
                    if(rowsAffected < 0)
121
                    {
122
                        result = false;
123
                    }
124
                    else
125
                    {
126
                        tran.Commit();
127
                    }
128
                }
129 7298c115 taeseongkim
            }
130
            catch (Exception ex)
131
            {
132 5b086e44 taeseongkim
                throw new Exception($"userId : {member.ID}",ex);
133 7298c115 taeseongkim
            }
134 753a1c26 taeseongkim
135
            return result;
136
        }
137
138
        public bool InsertProperties(string ProjectNo)
139
        {
140
            bool result = false;
141
142
            try
143
            {
144
                var properties = new[] { "TileSorceStorage", "TileSorcePath" };
145
146
                foreach (var property in properties)
147
                {
148
                    var tran = BeginTransaction();
149
150
                    string SQL = "INSERT INTO [dbo].[PROPERTIES] ([TYPE], [PROPERTY], [VALUE])" +
151
                                " SELECT @TYPE,@ProjectNo, [VALUE]" +
152
                                " FROM [dbo].[PROPERTIES]" +
153
                                " WHERE [TYPE] = @TYPE AND [PROPERTY] = 'APAO'" +
154
                                " AND NOT EXISTS (" +
155
                                " SELECT 1" +
156
                                " FROM [dbo].[PROPERTIES]" +
157
                                "  WHERE [TYPE] =  @TYPE AND [PROPERTY] = @ProjectNo)";
158
159
                    var parameters = new DynamicParameters();
160
                    parameters.Add("@TYPE", property);
161
                    parameters.Add("@ProjectNo", ProjectNo);
162
163
                    var rowsAffected = base.Execute(SQL, parameters, tran);
164
165
                    tran.Commit();
166
                }
167
            }
168
            catch (Exception ex)
169
            {
170
                throw new Exception($"InsertProperties : {ProjectNo}", ex);
171
            }
172 7298c115 taeseongkim
173
            return result;
174
        }
175
176 5b086e44 taeseongkim
        public IEnumerable<MEMBER> GetMEMBER(string id)
177
        {
178
            string SQL = "SELECT * FROM MEMBER WHERE ID = @ID";
179
180
            var parameters = new DynamicParameters();
181
            parameters.Add("@ID", id);
182
183
            return base.Query<MEMBER>(SQL, parameters);
184
        }
185
186 d1d8c5ea taeseongkim
        public IEnumerable<ConvertDoc> GetConvertDoc(int status,string ProjectNo)
187
        {
188
            string SQL = "SELECT * FROM CONVERTER_DOC WHERE STATUS = @STATUS and PROJECT_NO = @PROJECT_NO";
189
190
            var parameters = new DynamicParameters();
191
            parameters.Add("@STATUS", status);
192
            parameters.Add("@PROJECT_NO", ProjectNo);
193
194
            var convertItems = base.Query<ConvertDoc>(SQL, parameters);
195
196
            return convertItems;
197
        }
198
199 c7f3eb42 taeseongkim
        //public IEnumerable<MarkupText> GetMarkupText(IEnumerable<string> ProjectNoList, IEnumerable<string> DocumentNoList)
200
        //{
201
        //    string SQL = "GET_MARKUPDATA";
202 0b008ea6 taeseongkim
203 c7f3eb42 taeseongkim
        //    var parameters = new DynamicParameters();
204
        //    parameters.AddTable("@PROJECT_NOs", "VARCHAR_TABLE", ProjectNoList.Select(x=>new VARCHAR_TABLE { ITEM = x }));
205
        //    parameters.AddTable("@DOCUMENT_IDs", "VARCHAR_TABLE", DocumentNoList.Select(x => new VARCHAR_TABLE { ITEM = x }));
206 0b008ea6 taeseongkim
207 c7f3eb42 taeseongkim
        //    var Items = base.Query<MarkupText>(SQL, parameters,commandType:CommandType.StoredProcedure);
208 0b008ea6 taeseongkim
209 c7f3eb42 taeseongkim
        //    return Items;
210
        //}
211 0b008ea6 taeseongkim
212 1a88080d taeseongkim
        /// <summary>
213
        /// 완료
214
        /// </summary>
215
        /// <param name="PROJECT_NO"></param>
216
        /// <param name="DOCUMENT_URL"></param>
217
        /// <param name="DOCUMENT_ID"></param>
218
        /// <returns></returns>
219 c112c3c3 taeseongkim
        public string CreateConvertDoc(string PROJECT_NO, string DOCUMENT_URL, string DOCUMENT_ID)
220 1a88080d taeseongkim
        {
221
            string result = null;
222
            try
223
            {
224
                var tran = BeginTransaction();
225
226
                var parameters = new DynamicParameters();
227
                parameters.Add("@project_no", value: PROJECT_NO);
228
                parameters.Add("@document_url", value: DOCUMENT_URL);
229
                parameters.Add("@document_id", value: DOCUMENT_ID);
230 098748fa taeseongkim
                parameters.Add("@newid", direction: ParameterDirection.Output,size:int.MaxValue);
231 1a88080d taeseongkim
232 c112c3c3 taeseongkim
                base.Execute("convert_insert_convertdoc", parameters, transaction: tran, commandType: CommandType.StoredProcedure);
233 098748fa taeseongkim
                
234 1a88080d taeseongkim
                tran.Commit();
235
236
                result = parameters.Get<string>("newid");
237 098748fa taeseongkim
238
239 1a88080d taeseongkim
            }
240
            catch (Exception ex)
241
            {
242
243
                throw ex;
244
            }
245
            return result;
246
        }
247
248 098748fa taeseongkim
        public int UpdateStatusAsync(string ServiceID, string ConvertDocID, int status, int totalPage, int currentPage, string exception)
249
        {
250
            int result = 0;
251
            var tran = BeginTransaction();
252
            var parameters = new DynamicParameters();
253
            parameters.Add("@service_id", value: ServiceID);
254
            parameters.Add("@id", value: ConvertDocID);
255
            parameters.Add("@status", value: status);
256
            parameters.Add("@total_page", value: totalPage);
257
            parameters.Add("@current_page", value: currentPage);
258
            parameters.Add("@exception", value: exception);
259
            result = base.Execute("convert_update_status", parameters, transaction: tran, commandType: CommandType.StoredProcedure);
260
            tran.Commit();
261
262
            return result;
263
        }
264
265 1a88080d taeseongkim
        /// <summary>
266
        /// 
267
        /// </summary>
268
        /// <param name="documentItem"></param>
269
        /// <returns>Create or Update id</returns>
270 c112c3c3 taeseongkim
        public string CreateOrUPdateDocItem(DOCUMENTITEM documentItem)
271 1a88080d taeseongkim
        {
272
            string result = null;
273
274
            var tran = BeginTransaction();
275
            var parameter = new DynamicParameters();
276
277
            parameter.Add("@revision", documentItem.REVISION);
278
            parameter.Add("@document_no", documentItem.DOCUMENT_NO);
279
            parameter.Add("@document_name", documentItem.DOCUMENT_NAME);
280
            parameter.Add("@original_file", documentItem.ORIGINAL_FILE);
281
            parameter.Add("@document_id", documentItem.DOCUMENT_ID);
282
            parameter.Add("@project_no", documentItem.PROJECT_NO);
283
            parameter.Add("@link", documentItem.Link);
284
            parameter.Add("@result_file", documentItem.RESULT_FILE);
285
            parameter.Add("@result", documentItem.RESULT);
286
            parameter.Add("@group_no", documentItem.GROUP_NO);
287 098748fa taeseongkim
            parameter.Add("@newid", direction: ParameterDirection.Output, size: int.MaxValue);
288 1a88080d taeseongkim
289 c112c3c3 taeseongkim
            base.Execute("convert_insert_documentitem", parameter, tran, commandType: CommandType.StoredProcedure);
290 1a88080d taeseongkim
291
            tran.Commit();
292
293
            result = parameter.Get<string>("newid");
294
295
296
            return result;
297
        }
298
299
300
        /// <summary>
301
        /// test 필요 transaction Commit 이후 parameter.get을 해야 commit이 된다.
302
        /// </summary>
303
        /// <param name="convertDocID"></param>
304
        /// <param name="PageCount"></param>
305
        /// <returns></returns>
306 c112c3c3 taeseongkim
        public string CreateDocInfo(string convertDocID, int PageCount)
307 1a88080d taeseongkim
        {
308
            string result = "";
309
            var tran = BeginTransaction();
310
311
            var parameters = new DynamicParameters();
312
            parameters.Add("@convert_id", convertDocID, dbType: DbType.String);
313
            parameters.Add("@page_count", PageCount, dbType: DbType.Int32);
314
            parameters.Add("@newid", dbType: DbType.String, direction: ParameterDirection.Output, size: 50);
315
            parameters.Add("@errorcode", dbType: DbType.Int32, direction: ParameterDirection.Output);
316
            parameters.Add("@error", dbType: DbType.String, direction: ParameterDirection.Output, size: 500);
317
318 c112c3c3 taeseongkim
            base.Execute("convert_insert_docinfo", parameters, tran, commandType: CommandType.StoredProcedure);
319 1a88080d taeseongkim
320
            var errorCode = parameters.Get<int>("errorcode");
321
            var error = parameters.Get<string>("error");
322
323
            if (errorCode > 0)
324
            {
325
                tran.Rollback();
326
                throw new Exception(error);
327
            }
328
            else
329
            {
330
                tran.Commit();
331
332
                result = parameters.Get<string>("newid");
333
            }
334
335
            return result;
336
        }
337
338
339 c112c3c3 taeseongkim
        public bool CreateDocPage(IEnumerable<DocPage> docPages)
340 1a88080d taeseongkim
        {
341
            bool result = false;
342
343
            try
344
            {
345
                var tran = BeginTransaction();
346
347
                var parameter = new DynamicParameters();
348
349 c7f3eb42 taeseongkim
                parameter.AddTable< DocPage>("DOCPAGES", "TYPE_INSERT_DOCPAGE", docPages.ToList());
350 1a88080d taeseongkim
351 c112c3c3 taeseongkim
                var id = base.Execute("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure);
352 1a88080d taeseongkim
353
                tran.Commit();
354
355
                result = true;
356
            }
357
            catch (Exception ex)
358
            {
359
                throw new Exception("DOCPAGERepository CreateAsync error.", ex);
360
            }
361
362
            return result;
363
        }
364
    }
365 0b008ea6 taeseongkim
366
    internal class VARCHAR_TABLE
367
    {
368
        public string ITEM { get; set; }
369
    }
370 1a88080d taeseongkim
}
클립보드 이미지 추가 (최대 크기: 500 MB)