프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / DB / Project_DB.cs @ 224535bb

이력 | 보기 | 이력해설 | 다운로드 (30.3 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 (!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();
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 (SQLiteDataReader dr = cmd.ExecuteReader())
535
                            dt.Load(dr);
536
                    }
537
                    connection.Close();
538
                }
539
                catch (Exception ex)
540
                {
541

    
542
                }
543
                finally
544
                {
545
                    connection.Dispose();
546
                }
547
            }
548

    
549
            return dt;
550
        }
551

    
552
        public static bool InsertSymbolMapping(List<Tuple<string, string, string, bool>> datas)
553
        {
554
            Project_Info projectInfo = Project_Info.GetInstance();
555
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
556
            {
557
                try
558
                {
559
                    connection.Open();
560
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
561
                    {
562
                        try
563
                        {
564
                            using (SQLiteCommand cmd = connection.CreateCommand())
565
                            {
566
                                foreach (var item in datas)
567
                                {
568
                                    cmd.Parameters.Clear();
569
                                    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);
570
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
571
                                    cmd.Parameters.AddWithValue("@NAME", item.Item2);
572
                                    cmd.Parameters.AddWithValue("@SPPID_SYMBOL_PATH", item.Item3);
573
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item4);
574
                                    cmd.ExecuteNonQuery();
575
                                }
576
                            }
577
                            transaction.Commit();
578
                            connection.Close();
579
                        }
580
                        catch (Exception ex)
581
                        {
582
                            transaction.Rollback();
583
                        }
584
                        finally
585
                        {
586
                            transaction.Dispose();
587
                        }
588
                    }
589
                }
590
                catch (Exception ex)
591
                {
592
                    return false;
593
                }
594
                finally
595
                {
596
                    connection.Dispose();
597
                }
598
            }
599

    
600
            return true;
601
        }
602

    
603
        public static bool InsertAttributeMapping(List<Tuple<string, string>> datas)
604
        {
605
            Project_Info projectInfo = Project_Info.GetInstance();
606
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
607
            {
608
                try
609
                {
610
                    connection.Open();
611
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
612
                    {
613
                        try
614
                        {
615
                            using (SQLiteCommand cmd = connection.CreateCommand())
616
                            {
617
                                foreach (var item in datas)
618
                                {
619
                                    cmd.Parameters.Clear();
620
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, SPPID_ATTRIBUTE) VALUES (@UID, @SPPID_ATTRIBUTE)", SPPID_ATTRIBUTE_MAPPING_TABLE);
621
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
622
                                    cmd.Parameters.AddWithValue("@SPPID_ATTRIBUTE", item.Item2);
623
                                    cmd.ExecuteNonQuery();
624
                                }
625
                            }
626
                            transaction.Commit();
627
                            connection.Close();
628
                        }
629
                        catch (Exception ex)
630
                        {
631
                            transaction.Rollback();
632
                        }
633
                        finally
634
                        {
635
                            transaction.Dispose();
636
                        }
637
                    }
638
                }
639
                catch (Exception ex)
640
                {
641
                    return false;
642
                }
643
                finally
644
                {
645
                    connection.Dispose();
646
                }
647
            }
648
            return true;
649
        }
650

    
651
        public static bool InsertLabelInfoMapping(List<Tuple<string, int, bool>> datas)
652
        {
653
            Project_Info projectInfo = Project_Info.GetInstance();
654
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
655
            {
656
                try
657
                {
658
                    connection.Open();
659
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
660
                    {
661
                        try
662
                        {
663
                            using (SQLiteCommand cmd = connection.CreateCommand())
664
                            {
665
                                foreach (var item in datas)
666
                                {
667
                                    cmd.Parameters.Clear();
668
                                    cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (UID, LOCATION, LEADERLINE) VALUES (@UID, @LOCATION, @LEADERLINE)", SPPID_LABEL_INFO_TABLE);
669
                                    cmd.Parameters.AddWithValue("@UID", item.Item1);
670
                                    cmd.Parameters.AddWithValue("@LOCATION", item.Item2);
671
                                    cmd.Parameters.AddWithValue("@LEADERLINE", item.Item3);
672
                                    cmd.ExecuteNonQuery();
673
                                }
674
                            }
675
                            transaction.Commit();
676
                            connection.Close();
677
                        }
678
                        catch (Exception ex)
679
                        {
680
                            transaction.Rollback();
681
                        }
682
                        finally
683
                        {
684
                            transaction.Dispose();
685
                        }
686
                    }
687
                }
688
                catch (Exception ex)
689
                {
690
                    return false;
691
                }
692
                finally
693
                {
694
                    connection.Dispose();
695
                }
696
            }
697
            return true;
698
        }
699

    
700
        public static bool InsertDrawingInfo(string path, string drawingNumber, string drawingName, SPPID.Model.SPPID_Document document)
701
        {
702
            Project_Info projectInfo = Project_Info.GetInstance();
703
            using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", projectInfo.DBFilePath)))
704
            {
705
                try
706
                {
707
                    connection.Open();
708
                    using (SQLiteTransaction transaction = connection.BeginTransaction())
709
                    {
710
                        try
711
                        {
712
                            using (SQLiteCommand cmd = connection.CreateCommand())
713
                            {
714
                                cmd.CommandText = string.Format("INSERT OR REPLACE INTO {0} (PATH, DRAWINGNUMBER, DRAWINGNAME, DOCUMENT) VALUES (@PATH, @DRAWINGNUMBER, @DRAWINGNAME, @DOCUMENT)", SPPID_DRAWING_INFO);
715
                                cmd.Parameters.AddWithValue("@PATH", path);
716
                                cmd.Parameters.AddWithValue("@DRAWINGNUMBER", drawingNumber);
717
                                cmd.Parameters.AddWithValue("@DRAWINGNAME", drawingName);
718
                                cmd.Parameters.AddWithValue("@DOCUMENT", JsonConvert.SerializeObject(document));
719
                                cmd.ExecuteNonQuery();
720
                            }
721
                            transaction.Commit();
722
                            connection.Close();
723
                        }
724
                        catch (Exception ex)
725
                        {
726
                            transaction.Rollback();
727
                        }
728
                        finally
729
                        {
730
                            transaction.Dispose();
731
                        }
732
                    }
733
                }
734
                catch (Exception ex)
735
                {
736
                    return false;
737
                }
738
                finally
739
                {
740
                    connection.Dispose();
741
                }
742
            }
743
            return true;
744
        }
745
    }
746
}
클립보드 이미지 추가 (최대 크기: 500 MB)