프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / DB / Project_DB.cs @ 8701de36

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Globalization;
7
using System.Data.SQLite;
8
using System.Data;
9
using Newtonsoft.Json;
10

    
11
namespace Converter.BaseModel
12
{
13
    public class Project_DB
14
    {
15
        const string SPPID_DB_INFO_TABLE = "T_SPPID_CONNECTION_INFO";
16
        const string SPPID_SYMBOL_MAPPING_TABLE = "T_SPPID_SYMBOL_MAPPING";
17
        const string SPPID_ATTRIBUTE_MAPPING_TABLE = "T_SPPID_ATTRIBUTE_MAPPING";
18
        const string SPPID_SETTING_TABLE = "T_SPPID_SETTING_TABLE";
19
        const string SPPID_LABEL_INFO_TABLE = "T_SPPID_LABEL_INFO";
20
        const string SPPID_DRAWING_INFO = "T_SPPID_DRAWING_INFO";
21

    
22
        const string LineProperties_TABLE = "LineProperties";
23
        const string LineTypes_TABLE = "LineTypes";
24
        const string SymbolType_TABLE = "SymbolType";
25
        const string SymbolAttribute_TABLE = "SymbolAttribute";
26
        const string Symbol_TABLE = "Symbol";
27

    
28
        public static bool ConnTestAndCreateTable()
29
        {
30
            bool result = false;
31
            Project_Info projectInfo = Project_Info.GetInstance();
32
            SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, @"Data Source = {0}", projectInfo.DBFilePath));
33
            try
34
            {
35
                connection.Open();
36
                if (connection.State == ConnectionState.Open)
37
                {
38
                    CreateTable(connection);
39
                    result = true;
40
                }
41
                connection.Close();
42
            }
43
            catch (Exception ex)
44
            {
45

    
46
            }
47
            finally
48
            {
49
                connection.Dispose();
50
            }
51

    
52
            return result;
53
        }
54

    
55
        public static bool SaveSPPID_DB_INFO(string jsonString)
56
        {
57
            Project_Info projectInfo = Project_Info.GetInstance();
58
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
59
            {
60

    
61
                try
62
                {
63
                    connection.Open();
64
                    using (SQLiteCommand cmd = connection.CreateCommand())
65
                    {
66
                        cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_DB_INFO_TABLE);
67
                        cmd.ExecuteNonQuery();
68

    
69
                        cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString)", SPPID_DB_INFO_TABLE);
70
                        cmd.Parameters.AddWithValue("@jsonString", jsonString);
71
                        cmd.ExecuteNonQuery();
72
                    }
73
                    connection.Close();
74
                }
75
                catch (Exception ex)
76
                {
77
                    return false;
78
                }
79
                finally
80
                {
81
                    connection.Dispose();
82
                }
83
            }
84

    
85
            return true;
86
        }
87

    
88
        public static DataTable SelectSPPID_DB_INFO()
89
        {
90
            DataTable dt = new DataTable();
91
            Project_Info projectInfo = Project_Info.GetInstance();
92
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
93
            {
94
                try
95
                {
96
                    connection.Open();
97
                    using (SQLiteCommand cmd = connection.CreateCommand())
98
                    {
99
                        cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DB_INFO_TABLE);
100
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
101
                            dt.Load(dr);
102
                    }
103
                    connection.Close();
104
                }
105
                catch (Exception ex)
106
                {
107

    
108
                }
109
                finally
110
                {
111
                    connection.Dispose();
112
                }
113
            }
114

    
115
            return dt;
116
        }
117

    
118
        public static bool SaveETCSetting(Dictionary<string,string> dicSetting)
119
        {
120
            Project_Info projectInfo = Project_Info.GetInstance();
121
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
122
            {
123

    
124
                try
125
                {
126
                    connection.Open();
127
                    using (SQLiteCommand cmd = connection.CreateCommand())
128
                    {
129
                        cmd.CommandText = string.Format("DELETE FROM {0}", SPPID_SETTING_TABLE);
130
                        cmd.ExecuteNonQuery();
131

    
132
                        foreach (var item in dicSetting)
133
                        {
134
                            cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@jsonString, @SettingType)", SPPID_SETTING_TABLE);
135
                            cmd.Parameters.AddWithValue("@jsonString", item.Value);
136
                            cmd.Parameters.AddWithValue("@SettingType", item.Key);
137
                            cmd.ExecuteNonQuery();
138
                        }
139
                    }
140
                    connection.Close();
141
                }
142
                catch (Exception ex)
143
                {
144
                    return false;
145
                }
146
                finally
147
                {
148
                    connection.Dispose();
149
                }
150
            }
151

    
152
            return true;
153
        }
154

    
155
        public static DataTable SelectSetting()
156
        {
157
            DataTable dt = new DataTable();
158
            Project_Info projectInfo = Project_Info.GetInstance();
159
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
160
            {
161
                try
162
                {
163
                    connection.Open();
164
                    using (SQLiteCommand cmd = connection.CreateCommand())
165
                    {
166
                        cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
167
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
168
                            dt.Load(dr);
169
                    }
170
                    connection.Close();
171
                }
172
                catch (Exception ex)
173
                {
174

    
175
                }
176
                finally
177
                {
178
                    connection.Dispose();
179
                }
180
            }
181

    
182
            return dt;
183
        }
184

    
185
        private static void CreateTable(SQLiteConnection connection)
186
        {
187
            using (SQLiteCommand cmd = connection.CreateCommand())
188
            {
189
                cmd.CommandText = "SELECT NAME FROM sqlite_master WHERE type='table'";
190
                using (SQLiteDataReader dr = cmd.ExecuteReader())
191
                using (DataTable dt = new DataTable())
192
                {
193
                    dt.Load(dr);
194

    
195
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DB_INFO_TABLE)).Length == 0)
196
                    {
197
                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT)", SPPID_DB_INFO_TABLE);
198
                        cmd.ExecuteNonQuery();
199
                    }
200
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SETTING_TABLE)).Length == 0)
201
                    {
202
                        cmd.CommandText = string.Format("CREATE TABLE {0} (JsonString TEXT, SettingType TEXT)", SPPID_SETTING_TABLE);
203
                        cmd.ExecuteNonQuery();
204
                    }
205
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_SYMBOL_MAPPING_TABLE)).Length == 0)
206
                    {
207
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, NAME TEXT, SPPID_SYMBOL_PATH TEXT, LEADERLINE BOOLEAN)", SPPID_SYMBOL_MAPPING_TABLE);
208
                        cmd.ExecuteNonQuery();
209
                    }
210
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_ATTRIBUTE_MAPPING_TABLE)).Length == 0)
211
                    {
212
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, SPPID_ATTRIBUTE TEXT)", SPPID_ATTRIBUTE_MAPPING_TABLE);
213
                        cmd.ExecuteNonQuery();
214
                    }
215
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_LABEL_INFO_TABLE)).Length == 0)
216
                    {
217
                        cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT PRIMARY KEY, LOCATION INT DEFAULT 0, LEADERLINE BOOLEAN)", SPPID_LABEL_INFO_TABLE);
218
                        cmd.ExecuteNonQuery();
219
                    }
220
                    if (dt.Select(string.Format("NAME = '{0}'", SPPID_DRAWING_INFO)).Length == 0)
221
                    {
222
                        cmd.CommandText = string.Format("CREATE TABLE {0} (PATH TEXT PRIMARY KEY, DRAWINGNUMBER TEXT, DRAWINGNAME TEXT, DOCUMENT Text)", SPPID_DRAWING_INFO);
223
                        cmd.ExecuteNonQuery();
224
                    }
225
                }
226

    
227
                #region Check Column 업데이트시 예비용
228
                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
229
                using (SQLiteDataReader dr = cmd.ExecuteReader())
230
                using (DataTable dt = new DataTable())
231
                {
232
                    dt.Load(dr);
233
                    if (!dt.Columns.Contains("LEADERLINE"))
234
                    {
235
                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN LEADERLINE BOOLEAN", SPPID_SYMBOL_MAPPING_TABLE);
236
                        cmd.ExecuteNonQuery();
237
                    }
238
                }
239

    
240
                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_SETTING_TABLE);
241
                using (SQLiteDataReader dr = cmd.ExecuteReader())
242
                using (DataTable dt = new DataTable())
243
                {
244
                    dt.Load(dr);
245
                    if (!dt.Columns.Contains("SettingType"))
246
                    {
247
                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN SettingType Text", SPPID_SETTING_TABLE);
248
                        cmd.ExecuteNonQuery();
249
                    }
250
                }
251

    
252
                cmd.CommandText = string.Format("SELECT * FROM {0}", SPPID_DRAWING_INFO);
253
                using (SQLiteDataReader dr = cmd.ExecuteReader())
254
                using (DataTable dt = new DataTable())
255
                {
256
                    dt.Load(dr);
257
                    if (!dt.Columns.Contains("DOCUMENT"))
258
                    {
259
                        cmd.CommandText = string.Format("ALTER TABLE {0} ADD COLUMN DOCUMENT Text", SPPID_DRAWING_INFO);
260
                        cmd.ExecuteNonQuery();
261
                    }
262
                }
263
                #endregion
264
            }
265
        }
266

    
267
        public static DataTable SelectProjectSymbol()
268
        {
269
            DataTable dt = new DataTable();
270
            Project_Info projectInfo = Project_Info.GetInstance();
271
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
272
            {
273
                try
274
                {
275
                    connection.Open();
276
                    using (SQLiteCommand cmd = connection.CreateCommand())
277
                    {
278
                        cmd.CommandText = string.Format(@"
279
                            SELECT s.UID, s.Name, st.Type, sp.SPPID_SYMBOL_PATH, sp.LEADERLINE FROM {1} as st, {0} as s 
280
                                LEFT OUTER JOIN {2} as sp 
281
                                    ON s.UID = SP.UID 
282
                            WHERE s.SymbolType_UID = st.UID 
283
                            ORDER BY st.TYPE ASC;", Symbol_TABLE, SymbolType_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
284
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
285
                            dt.Load(dr);
286

    
287
                        DataTable dtClone = dt.Clone();
288
                        dtClone.Columns["UID"].DataType = typeof(string);
289
                        foreach (DataRow row in dt.Rows)
290
                        {
291
                            dtClone.ImportRow(row);
292
                        }
293
                        dt.Dispose();
294
                        dt = dtClone;
295
                    }
296
                    connection.Close();
297
                }
298
                catch (Exception ex)
299
                {
300

    
301
                }
302
                finally
303
                {
304
                    connection.Dispose();
305
                }
306
            }
307

    
308
            return dt;
309
        }
310

    
311
        public static DataTable SelectProjectChildSymbol()
312
        {
313
            DataTable result = new DataTable();
314
            result.Columns.Add("UID");
315
            result.Columns.Add("Name");
316
            result.Columns.Add("Type");
317
            result.Columns.Add("SPPID_SYMBOL_PATH");
318
            
319
            Project_Info projectInfo = Project_Info.GetInstance();
320
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
321
            using (DataTable dt = new DataTable())
322
            {
323
                try
324
                {
325
                    connection.Open();
326
                    using (SQLiteCommand cmd = connection.CreateCommand())
327
                    {
328
                        cmd.CommandText = string.Format(@"
329
                            SELECT AdditionalSymbol FROM Symbol");
330
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
331
                            dt.Load(dr);
332
                        List<string> childList = new List<string>();
333
                        foreach (DataRow row in dt.Rows)
334
                        { 
335
                            if (row["AdditionalSymbol"] != null && !DBNull.Value.Equals(row["AdditionalSymbol"]) && !string.IsNullOrEmpty((string)row["AdditionalSymbol"]))
336
                            {
337
                                string[] array = row["AdditionalSymbol"].ToString().Split(new char[] { '/' });
338
                                foreach (var childString in array)
339
                                {
340
                                    childList.Add(childString.Split(new char[] { ',' })[2]);
341
                                }
342
                            }
343

    
344
                        }
345

    
346
                        dt.Clear();
347
                        cmd.Reset();
348
                        cmd.CommandText = string.Format(@"
349
                            SELECT * FROM {0}", SPPID_SYMBOL_MAPPING_TABLE);
350
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
351
                            dt.Load(dr);
352

    
353
                        childList = childList.Distinct().ToList();
354
                        foreach (var child in childList)
355
                        {
356
                            string mappingPath = string.Empty;
357
                            DataRow[] rows = dt.Select(string.Format("UID = '{0}'", child));
358
                            if (rows.Length == 1)
359
                                mappingPath = !DBNull.Value.Equals(rows[0]["SPPID_SYMBOL_PATH"]) ? (string)rows[0]["SPPID_SYMBOL_PATH"] : null;
360

    
361
                            DataRow newRow = result.NewRow();
362
                            newRow["UID"] = child;
363
                            newRow["Name"] = child;
364
                            newRow["Type"] = "Child Symbol";
365
                            newRow["SPPID_SYMBOL_PATH"] = mappingPath;
366
                            result.Rows.Add(newRow);
367
                        }
368
                    }
369
                    connection.Close();
370
                }
371
                catch (Exception ex)
372
                {
373

    
374
                }
375
                finally
376
                {
377
                    connection.Dispose();
378
                }
379
            }
380

    
381
            return result;
382
        }
383

    
384
        public static DataTable SelectProjectLine()
385
        {
386
            DataTable dt = new DataTable();
387
            Project_Info projectInfo = Project_Info.GetInstance();
388
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
389
            {
390
                try
391
                {
392
                    connection.Open();
393
                    using (SQLiteCommand cmd = connection.CreateCommand())
394
                    {
395
                        cmd.CommandText = string.Format(@"
396
                            SELECT l.UID, l.Name, sp.SPPID_SYMBOL_PATH FROM {0} as l 
397
                                LEFT OUTER JOIN {1} as sp 
398
                                    ON l.UID = SP.UID ;", LineTypes_TABLE, SPPID_SYMBOL_MAPPING_TABLE);
399
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
400
                            dt.Load(dr);
401
                    }
402
                    connection.Close();
403
                }
404
                catch (Exception ex)
405
                {
406

    
407
                }
408
                finally
409
                {
410
                    connection.Dispose();
411
                }
412
            }
413

    
414
            return dt;
415
        }
416

    
417
        public static DataTable SelectProjectLineProperties()
418
        {
419
            DataTable dt = new DataTable();
420
            Project_Info projectInfo = Project_Info.GetInstance();
421
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
422
            {
423
                try
424
                {
425
                    connection.Open();
426
                    using (SQLiteCommand cmd = connection.CreateCommand())
427
                    {
428
                        cmd.CommandText = string.Format(@"
429
                            SELECT lp.UID, lp.DisplayName, sp.SPPID_SYMBOL_PATH, spa.SPPID_ATTRIBUTE
430
                            FROM {0} as lp 
431
                                 LEFT OUTER JOIN {1} as sp 
432
                                      ON lp.UID = sp.UID
433
                                 LEFT OUTER JOIN {2} as spa 
434
                                      ON lp.UID = spa.UID;", LineProperties_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE);
435
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
436
                            dt.Load(dr);
437
                    }
438
                    connection.Close();
439
                }
440
                catch (Exception ex)
441
                {
442

    
443
                }
444
                finally
445
                {
446
                    connection.Dispose();
447
                }
448
            }
449

    
450
            return dt;
451
        }
452

    
453
        public static DataTable SelectProjectAttribute()
454
        {
455
            DataTable dt = new DataTable();
456
            Project_Info projectInfo = Project_Info.GetInstance();
457
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
458
            {
459
                try
460
                {
461
                    connection.Open();
462
                    using (SQLiteCommand cmd = connection.CreateCommand())
463
                    {
464
                        cmd.CommandText = string.Format(@"
465
                            SELECT sa.UID, sa.DisplayAttribute, st.TYPE, spa.SPPID_ATTRIBUTE, sp.SPPID_SYMBOL_PATH, spl.LOCATION, spl.LEADERLINE, sa.Property
466
                            FROM {1} as sa, {0} as st 
467
                                 LEFT OUTER JOIN {2} as sp 
468
                                      ON sa.UID = SP.UID 
469
                                LEFT OUTER JOIN {3} as spa 
470
                                     ON sa.UID = spa.UID
471
                                LEFT OUTER JOIN {4} as spl 
472
                                     ON sa.UID = spl.UID
473
                            WHERE sa.SymbolType_UID = st.UID AND (sa.Property != 2 OR sa.Property IS NULL);", SymbolType_TABLE, SymbolAttribute_TABLE, SPPID_SYMBOL_MAPPING_TABLE, SPPID_ATTRIBUTE_MAPPING_TABLE, SPPID_LABEL_INFO_TABLE);
474
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
475
                            dt.Load(dr);
476
                    }
477
                    connection.Close();
478
                }
479
                catch (Exception ex)
480
                {
481

    
482
                }
483
                finally
484
                {
485
                    connection.Dispose();
486
                }
487
            }
488

    
489
            return dt;
490
        }
491

    
492
        public static DataTable SelectID2SymbolTable()
493
        {
494
            DataTable dt = new DataTable();
495
            Project_Info projectInfo = Project_Info.GetInstance();
496
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
497
            {
498
                try
499
                {
500
                    connection.Open();
501
                    using (SQLiteCommand cmd = connection.CreateCommand())
502
                    {
503
                        cmd.CommandText = @"SELECT * FROM Symbol";
504
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
505
                            dt.Load(dr);
506
                    }
507
                    connection.Close();
508
                }
509
                catch (Exception ex)
510
                {
511

    
512
                }
513
                finally
514
                {
515
                    connection.Dispose();
516
                }
517
            }
518

    
519
            return dt;
520
        }
521

    
522
        public static DataTable SelectDrawingInfo()
523
        {
524
            DataTable dt = new DataTable() { Locale = CultureInfo.CurrentCulture };
525
            Project_Info projectInfo = Project_Info.GetInstance();
526
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
527
            {
528
                try
529
                {
530
                    connection.Open();
531
                    using (SQLiteCommand cmd = connection.CreateCommand())
532
                    {
533
                        cmd.CommandText = string.Format("SELECT * FROM {0}",SPPID_DRAWING_INFO);
534
                        //using (SQLiteDataAdapter da = new SQLiteDataAdapter(cmd))
535
                        //    da.Fill(dt);
536
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
537
                        {
538
                            dt.Columns.Add("PATH", typeof(string));
539
                            dt.Columns.Add("DRAWINGNUMBER", typeof(string));
540
                            dt.Columns.Add("DRAWINGNAME", typeof(string));
541
                            dt.Columns.Add("DOCUMENT", typeof(SPPID.Model.SPPID_Document));
542
                            while (dr.Read())
543
                            {
544
                                DataRow row = dt.NewRow();
545
                                row["PATH"] = dr["PATH"];
546
                                row["DRAWINGNUMBER"] = dr["DRAWINGNUMBER"];
547
                                row["DRAWINGNAME"] = dr["DRAWINGNAME"];
548
                                string jsonString = (string)dr["DOCUMENT"];
549
                                JsonSerializerSettings settings = new JsonSerializerSettings
550
                                {
551
                                    NullValueHandling = NullValueHandling.Ignore,
552
                                    ObjectCreationHandling = ObjectCreationHandling.Replace
553
                                };
554
                                SPPID.Model.SPPID_Document doc = JsonConvert.DeserializeObject<SPPID.Model.SPPID_Document>(jsonString, settings);
555
                                row["DOCUMENT"] = doc;
556
                                dt.Rows.Add(row);
557
                            }
558
                            //dt.Load(dr, LoadOption.Upsert);
559
                        }
560
                            
561
                    }
562
                    connection.Close();
563
                }
564
                catch (Exception ex)
565
                {
566

    
567
                }
568
                finally
569
                {
570
                    connection.Dispose();
571
                }
572
            }
573

    
574
            return dt;
575
        }
576

    
577
        public static bool InsertSymbolMapping(List<Tuple<string, string, string, bool>> datas)
578
        {
579
            Project_Info projectInfo = Project_Info.GetInstance();
580
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
581
            {
582
                try
583
                {
584
                    connection.Open();
585
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
586
                    {
587
                        try
588
                        {
589
                            using (SQLiteCommand cmd = connection.CreateCommand())
590
                            {
591
                                foreach (var item in datas)
592
                                {
593
                                    cmd.Parameters.Clear();
594
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, NAME, SPPID_SYMBOL_PATH, LEADERLINE) VALUES (@UID, @NAME, @SPPID_SYMBOL_PATH, @LEADERLINE)", SPPID_SYMBOL_MAPPING_TABLE);
595
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
596
                                    cmd.Parameters.AddWithValue("@NAME", item.Item2);
597
                                    cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
598
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4);
599
                                    cmd.ExecuteNonQuery();
600
                                }
601
                            }
602
                            transaction.Commit();
603
                            connection.Close();
604
                        }
605
                        catch (Exception ex)
606
                        {
607
                            transaction.Rollback();
608
                        }
609
                        finally
610
                        {
611
                            transaction.Dispose();
612
                        }
613
                    }
614
                }
615
                catch (Exception ex)
616
                {
617
                    return false;
618
                }
619
                finally
620
                {
621
                    connection.Dispose();
622
                }
623
            }
624

    
625
            return true;
626
        }
627

    
628
        public static bool InsertAttributeMapping(List<Tuple<string, string>> datas)
629
        {
630
            Project_Info projectInfo = Project_Info.GetInstance();
631
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
632
            {
633
                try
634
                {
635
                    connection.Open();
636
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
637
                    {
638
                        try
639
                        {
640
                            using (SQLiteCommand cmd = connection.CreateCommand())
641
                            {
642
                                foreach (var item in datas)
643
                                {
644
                                    cmd.Parameters.Clear();
645
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE);
646
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
647
                                    cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2);
648
                                    cmd.ExecuteNonQuery();
649
                                }
650
                            }
651
                            transaction.Commit();
652
                            connection.Close();
653
                        }
654
                        catch (Exception ex)
655
                        {
656
                            transaction.Rollback();
657
                        }
658
                        finally
659
                        {
660
                            transaction.Dispose();
661
                        }
662
                    }
663
                }
664
                catch (Exception ex)
665
                {
666
                    return false;
667
                }
668
                finally
669
                {
670
                    connection.Dispose();
671
                }
672
            }
673
            return true;
674
        }
675

    
676
        public static bool InsertLabelInfoMapping(List<Tuple<string, int, bool>> datas)
677
        {
678
            Project_Info projectInfo = Project_Info.GetInstance();
679
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
680
            {
681
                try
682
                {
683
                    connection.Open();
684
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
685
                    {
686
                        try
687
                        {
688
                            using (SQLiteCommand cmd = connection.CreateCommand())
689
                            {
690
                                foreach (var item in datas)
691
                                {
692
                                    cmd.Parameters.Clear();
693
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE);
694
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
695
                                    cmd.Parameters.AddWithValue("@LOCATION", item.Item2);
696
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3);
697
                                    cmd.ExecuteNonQuery();
698
                                }
699
                            }
700
                            transaction.Commit();
701
                            connection.Close();
702
                        }
703
                        catch (Exception ex)
704
                        {
705
                            transaction.Rollback();
706
                        }
707
                        finally
708
                        {
709
                            transaction.Dispose();
710
                        }
711
                    }
712
                }
713
                catch (Exception ex)
714
                {
715
                    return false;
716
                }
717
                finally
718
                {
719
                    connection.Dispose();
720
                }
721
            }
722
            return true;
723
        }
724

    
725
        public static bool InsertDrawingInfo(string path, string drawingNumber, string drawingName, SPPID.Model.SPPID_Document document)
726
        {
727
            Project_Info projectInfo = Project_Info.GetInstance();
728
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
729
            {
730
                try
731
                {
732
                    connection.Open();
733
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
734
                    {
735
                        try
736
                        {
737
                            using (SQLiteCommand cmd = connection.CreateCommand())
738
                            {
739
                                cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (PATH, DRAWINGNUMBER, DRAWINGNAME, DOCUMENT) VALUES (@PATH, @DRAWINGNUMBER, @DRAWINGNAME, @DOCUMENT)", SPPID_DRAWING_INFO);
740
                                cmd.Parameters.AddWithValue("@PATH", path);
741
                                cmd.Parameters.AddWithValue("@DRAWINGNUMBER", drawingNumber);
742
                                cmd.Parameters.AddWithValue("@DRAWINGNAME", drawingName);
743
                                cmd.Parameters.AddWithValue("@DOCUMENT", JsonConvert.SerializeObject(document));
744
                                cmd.ExecuteNonQuery();
745
                            }
746
                            transaction.Commit();
747
                            connection.Close();
748
                        }
749
                        catch (Exception ex)
750
                        {
751
                            transaction.Rollback();
752
                        }
753
                        finally
754
                        {
755
                            transaction.Dispose();
756
                        }
757
                    }
758
                }
759
                catch (Exception ex)
760
                {
761
                    return false;
762
                }
763
                finally
764
                {
765
                    connection.Dispose();
766
                }
767
            }
768
            return true;
769
        }
770
    }
771
}
클립보드 이미지 추가 (최대 크기: 500 MB)