프로젝트

일반

사용자정보

개정판 bca86986

IDbca869866ff5e064be5c9036fd598e22fc65f2f6
상위 0d8062b2
하위 60a617ec

gaqhf 이(가) 5년 이상 전에 추가함

dev issue #000 : mapping logic

Change-Id: I9cb888f07e99b902f23fc46081be2ffa69449229

차이점 보기:

DTI_PID/BaseModel/Project_DB.cs
11 11
{
12 12
    public class Project_DB
13 13
    {
14
        const string SPPID_DB_INFO_TABLE = "SPPID_CONNECTION_INFO";
14
        const string SPPID_DB_INFO_TABLE = "T_SPPID_CONNECTION_INFO";
15
        const string SPPID_SYMBOL_MAPPING_TABLE = "T_SPPID_SYMBOL_MAPPING";
16
        const string SPPID_ATTRIBUTE_MAPPING_TABLE = "T_SPPID_ATTRIBUTE_MAPPING";
15 17

  
16
        public static void Conn()
17
        {
18
            Project_Info projectInfo = Project_Info.GetInstance();
19
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
20
            {
21
                connection.Open();
22
            }
23
        }
18
        const string LineProperties_TABLE = "LineProperties";
19
        const string LineTypes_TABLE = "LineTypes";
20
        const string SymbolType_TABLE = "SymbolType";
21
        const string SymbolAttribute_TABLE = "SymbolAttribute";
22
        const string Symbol_TABLE = "Symbol";
24 23

  
25 24
        public static bool ConnTestAndCreateTable()
26 25
        {
......
128 127
                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT)", SPPID_DB_INFO_TABLE);
129 128
                        cmd.ExecuteNonQuery();
130 129
                    }
130
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
131
                    {
132
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, SPPID_SYMBOL_PATH TEXT)", SPPID_SYMBOL_MAPPING_TABLE);
133
                        cmd.ExecuteNonQuery();
134
                    }
135
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
136
                    {
137
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, SPPID_ATTRIBUTE TEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE);
138
                        cmd.ExecuteNonQuery();
139
                    }
131 140
                }
132 141
            }
133 142
        }
143

  
144
        public static DataTable SelectProjectSymbol()
145
        {
146
            DataTable dt = new DataTable();
147
            Project_Info projectInfo = Project_Info.GetInstance();
148
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
149
            {
150
                try
151
                {
152
                    connection.Open();
153
                    using (SQLiteCommand cmd = connection.CreateCommand())
154
                    {
155
                        cmd.CommandText = string.Format(@"
156
                            SELECT s.UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH FROM {1} as st, {0} as s 
157
                                LEFT OUTER JOIN {2} as sp 
158
                                    ON s.UID = SP.UID 
159
                            WHERE s.SymbolType_UID = st.UID 
160
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
161
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
162
                            dt.Load(dr);
163
                    }
164
                    connection.Close();
165
                }
166
                catch (Exception ex)
167
                {
168

  
169
                }
170
                finally
171
                {
172
                    connection.Dispose();
173
                }
174
            }
175

  
176
            return dt;
177
        }
178

  
179
        public static DataTable SelectProjectLine()
180
        {
181
            DataTable dt = new DataTable();
182
            Project_Info projectInfo = Project_Info.GetInstance();
183
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
184
            {
185
                try
186
                {
187
                    connection.Open();
188
                    using (SQLiteCommand cmd = connection.CreateCommand())
189
                    {
190
                        cmd.CommandText = string.Format(@"
191
                            SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l 
192
                                LEFT OUTER JOIN {1} as sp 
193
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
194
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
195
                            dt.Load(dr);
196
                    }
197
                    connection.Close();
198
                }
199
                catch (Exception ex)
200
                {
201

  
202
                }
203
                finally
204
                {
205
                    connection.Dispose();
206
                }
207
            }
208

  
209
            return dt;
210
        }
211

  
212
        public static DataTable SelectProjectLineProperties()
213
        {
214
            DataTable dt = new DataTable();
215
            Project_Info projectInfo = Project_Info.GetInstance();
216
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
217
            {
218
                try
219
                {
220
                    connection.Open();
221
                    using (SQLiteCommand cmd = connection.CreateCommand())
222
                    {
223
                        cmd.CommandText = string.Format(@"
224
                            SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE
225
                            FROM {0} as lp 
226
                                 LEFT OUTER JOIN {1} as sp 
227
                                      ON lp.UID = sp.UID
228
                                 LEFT OUTER JOIN {2} as spa 
229
                                      ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
230
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
231
                            dt.Load(dr);
232
                    }
233
                    connection.Close();
234
                }
235
                catch (Exception ex)
236
                {
237

  
238
                }
239
                finally
240
                {
241
                    connection.Dispose();
242
                }
243
            }
244

  
245
            return dt;
246
        }
247

  
248
        public static DataTable SelectProjectAssociation()
249
        {
250
            DataTable dt = new DataTable();
251
            Project_Info projectInfo = Project_Info.GetInstance();
252
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
253
            {
254
                try
255
                {
256
                    connection.Open();
257
                    using (SQLiteCommand cmd = connection.CreateCommand())
258
                    {
259
                        cmd.CommandText = string.Format(@"
260
                            SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH 
261
                            FROM {1} as sa, {0} as st 
262
                                 LEFT OUTER JOIN {2} as sp 
263
                                      ON sa.UID = SP.UID 
264
                                LEFT OUTER JOIN {3} as spa 
265
                                     ON sa.UID = spa.UID
266
                            WHERE sa.SymbolType_UID = st.UID;", SymbolType_TABLE, SymbolAttribute_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
267
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
268
                            dt.Load(dr);
269
                    }
270
                    connection.Close();
271
                }
272
                catch (Exception ex)
273
                {
274

  
275
                }
276
                finally
277
                {
278
                    connection.Dispose();
279
                }
280
            }
281

  
282
            return dt;
283
        }
284

  
285

  
286

  
287
        public static bool InsertSymbolMapping(List<Tuple<string, string, string>> datas)
288
        {
289
            Project_Info projectInfo = Project_Info.GetInstance();
290
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
291
            {
292
                try
293
                {
294
                    connection.Open();
295
                    using (SQLiteCommand cmd = connection.CreateCommand())
296
                    {
297
                        foreach (var item in datas)
298
                        {
299
                            cmd.Parameters.Clear();
300
                            cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, SPPID_SYMBOL_PATH) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH)", SPPID_SYMBOL_MAPPING_TABLE);
301
                            cmd.Parameters.AddWithValue("@UID", item.Item1);
302
                            cmd.Parameters.AddWithValue("@NAME", item.Item2);
303
                            cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
304
                            cmd.ExecuteNonQuery();
305
                        }
306
                    }
307
                    connection.Close();
308
                }
309
                catch (Exception ex)
310
                {
311
                    return false;
312
                }
313
                finally
314
                {
315
                    connection.Dispose();
316
                }
317
            }
318

  
319
            return true;
320
        }
321

  
322
        public static bool InsertAttributeMapping(List<Tuple<string, string>> datas)
323
        {
324
            Project_Info projectInfo = Project_Info.GetInstance();
325
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
326
            {
327
                try
328
                {
329
                    connection.Open();
330
                    using (SQLiteCommand cmd = connection.CreateCommand())
331
                    {
332
                        foreach (var item in datas)
333
                        {
334
                            cmd.Parameters.Clear();
335
                            cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE);
336
                            cmd.Parameters.AddWithValue("@UID", item.Item1);
337
                            cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2);
338
                            cmd.ExecuteNonQuery();
339
                        }
340
                    }
341
                    connection.Close();
342
                }
343
                catch (Exception ex)
344
                {
345
                    return false;
346
                }
347
                finally
348
                {
349
                    connection.Dispose();
350
                }
351
            }
352

  
353
            return true;
354
        }
134 355
    }
135 356
}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)