프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ ea54adc8

이력 | 보기 | 이력해설 | 다운로드 (25.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 Newtonsoft.Json;
7
using System.IO;
8
using Converter.SPPID.DB;
9
using Converter.BaseModel;
10
using System.Windows.Forms;
11
using Converter.SPPID.Model;
12
using System.Drawing;
13
using Llama;
14
using System.Data;
15
using Plaice;
16
using Microsoft.VisualBasic;
17

    
18
namespace Converter.SPPID.Util
19
{
20
    public enum SlopeType
21
    {
22
        None,
23
        Slope,
24
        HORIZONTAL,
25
        VERTICAL
26
    }
27
    public class SPPIDUtil
28
    {
29
        public static bool ConvertToSPPIDInfo(string jsonString)
30
        {
31
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
32
            try
33
            {
34
                SPPID_DBInfo jsonSPPIDInfo = JsonConvert.DeserializeObject<SPPID_DBInfo>(jsonString);
35

    
36
                _SPPIDInfo.DBType = jsonSPPIDInfo.DBType;
37
                _SPPIDInfo.Service = jsonSPPIDInfo.Service;
38
                _SPPIDInfo.Site = jsonSPPIDInfo.Site;
39
                _SPPIDInfo.ServerIP = jsonSPPIDInfo.ServerIP;
40
                _SPPIDInfo.Port = jsonSPPIDInfo.Port;
41
                _SPPIDInfo.DBUser = jsonSPPIDInfo.DBUser;
42
                _SPPIDInfo.DBPassword = jsonSPPIDInfo.DBPassword;
43
                _SPPIDInfo.PlantPath = jsonSPPIDInfo.PlantPath;
44
                _SPPIDInfo.PlantDic = jsonSPPIDInfo.PlantDic;
45
                _SPPIDInfo.PlantPID = jsonSPPIDInfo.PlantPID;
46
                _SPPIDInfo.PlantPIDDic = jsonSPPIDInfo.PlantPIDDic;
47
                _SPPIDInfo.Plant = jsonSPPIDInfo.Plant;
48
                _SPPIDInfo.Enable = jsonSPPIDInfo.Enable;
49
                _SPPIDInfo.SelectedPlant = jsonSPPIDInfo.SelectedPlant;
50
                _SPPIDInfo.PlantList = jsonSPPIDInfo.PlantList;
51

    
52
            }
53
            catch (Exception ex)
54
            {
55
                _SPPIDInfo.Enable = false;
56
                return false;
57
            }
58
            return true;
59
        }
60

    
61
        public static bool ConvertToETCSetting(string jsonString)
62
        {
63
            ETCSetting _ETCSetting = ETCSetting.GetInstance();
64
            try
65
            {
66
                ETCSetting jsonETCSetting = JsonConvert.DeserializeObject<ETCSetting>(jsonString);
67

    
68
                _ETCSetting.NoteSymbolPath = jsonETCSetting.NoteSymbolPath;
69
                _ETCSetting.TextSymbolPath = jsonETCSetting.TextSymbolPath;
70
                _ETCSetting.DrainValveSize = jsonETCSetting.DrainValveSize;
71
                _ETCSetting.VendorPackageSymbolPath = jsonETCSetting.VendorPackageSymbolPath;
72
                _ETCSetting.TextLocation = jsonETCSetting.TextLocation;
73
                _ETCSetting.NoteLocation = jsonETCSetting.NoteLocation;
74
                _ETCSetting.LineNumberLocation = jsonETCSetting.LineNumberLocation;
75
                _ETCSetting.FlowMarkSymbolPath = jsonETCSetting.FlowMarkSymbolPath;
76
                _ETCSetting.BorderFilePath = jsonETCSetting.BorderFilePath;
77
            }
78
            catch (Exception ex)
79
            {
80
                return false;
81
            }
82
            return true;
83
        }
84

    
85
        public static bool ConvertToGridSetting(string jsonString)
86
        {
87
            GridSetting _GridSetting = GridSetting.GetInstance();
88
            try
89
            {
90
                GridSetting jsonGridSetting = JsonConvert.DeserializeObject<GridSetting>(jsonString);
91

    
92
                _GridSetting.UseSnapGrid = jsonGridSetting.UseSnapGrid;
93
                _GridSetting.Density = jsonGridSetting.Density;
94
                _GridSetting.Unit = jsonGridSetting.Unit;
95
                _GridSetting.DrainValveCellCount = jsonGridSetting.DrainValveCellCount;
96
            }
97
            catch (Exception ex)
98
            {
99
                return false;
100
            }
101
            return true;
102
        }
103

    
104
        public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY)
105
        {
106
            try
107
            {
108
                string[] pointArr = sPoint.Split(new char[] { ',' });
109
                if (pointArr.Length == 2)
110
                {
111
                    dX = Convert.ToDouble(pointArr[0]);
112
                    dY = Convert.ToDouble(pointArr[1]);
113
                }
114
            }
115
            catch (Exception)
116
            {
117
                dX = 0;
118
                dY = 0;
119
                return false;
120
            }
121

    
122
            return true;
123
        }
124

    
125
        public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height)
126
        {
127
            decimal calcX = 0;
128
            decimal calcY = 0;
129
            decimal tempX = Convert.ToDecimal(dX);
130
            decimal tempY = Convert.ToDecimal(dY);
131
            decimal tempWidth = Convert.ToDecimal(SPPID_Width);
132
            decimal tempHeight = Convert.ToDecimal(SPPID_Height);
133
            decimal tempDwgX = Convert.ToDecimal(dDwgX);
134
            decimal tempDwgY = Convert.ToDecimal(dDwgY);
135

    
136
            calcX = (tempX * tempWidth) / tempDwgX;
137
            calcY = tempHeight - ((tempY * tempHeight) / tempDwgY);
138
            dX = Convert.ToDouble(calcX);
139
            dY = Convert.ToDouble(calcY);
140
        }
141

    
142
        public static void ConvertGridPoint(ref double x, ref double y)
143
        {
144
            GridSetting _GridSetting = GridSetting.GetInstance();
145
            if (_GridSetting.UseSnapGrid)
146
            {
147
                if (_GridSetting.Unit == GridUnit.Inch)
148
                {
149
                    double length = _GridSetting.Density * 0.0254;
150
                    double tempX = x;
151
                    double tempY = y;
152
                    x = Math.Round(tempX / length) * length;
153
                    y = Math.Round(tempY / length) * length;
154
                }
155
            }
156
        }
157

    
158
        public static void ConvertGridPointOnlyOnePoint(ref double value)
159
        {
160
            GridSetting _GridSetting = GridSetting.GetInstance();
161
            if (_GridSetting.UseSnapGrid)
162
            {
163
                if (_GridSetting.Unit == GridUnit.Inch)
164
                {
165
                    double temp = value;
166
                    value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length;
167
                }
168
            }
169
        }
170
        public static double ConvertGridPointOnlyOnePoint(double value)
171
        {
172
            GridSetting _GridSetting = GridSetting.GetInstance();
173
            if (_GridSetting.UseSnapGrid)
174
            {
175
                if (_GridSetting.Unit == GridUnit.Inch)
176
                {
177
                    double temp = value;
178
                    value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length;
179
                }
180
            }
181

    
182
            return value;
183
        }
184

    
185
        public static SlopeType CalcSlope(double x1, double y1, double x2, double y2, double degree = 15)
186
        {
187
            if (x1 - x2 == 0)
188
            {
189
                return SlopeType.VERTICAL;
190
            }
191
            else
192
            {
193
                double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
194
                if (angle <= degree)
195
                    return SlopeType.HORIZONTAL;
196
                else if (angle >= 90 - degree)
197
                    return SlopeType.VERTICAL;
198
                else
199
                    return SlopeType.Slope;
200
            }
201
        }
202
        public static double CalcAngle(double x1, double y1, double x2, double y2)
203
        {
204
            double result = 90;
205
            if (x1 - x2 != 0)
206
            {
207
                result = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
208
            }
209
            return result;
210
        }
211
        public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y)
212
        {
213

    
214
            double distance = 0;
215
            if (lineX1 == lineX2)
216
                distance = Math.Abs(x - lineX1);
217
            else
218
            {
219
                double a;
220
                double b;
221
                double c;
222

    
223
                a = (lineY2 - lineY1) / (lineX2 - lineX1);
224
                b = -1;
225
                c = -a * lineX1 + lineY1;
226

    
227
                distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5);
228
            }
229
            return distance;
230
        }
231

    
232
        public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
233
        {
234
            double a1;
235
            double a2;
236
            double b1;
237
            double b2;
238

    
239
            if (x1 == x2)
240
                a1 = 0;
241
            else
242
                a1 = (y2 - y1) / (x2 - x1);
243
            if (x3 == x4)
244
                a2 = 0;
245
            else
246
                a2 = (y4 - y3) / (x4 - x3);
247

    
248
            b1 = -a1 * x1 + y1;
249
            b2 = -a2 * x3 + y3;
250

    
251
            if (x1 == x2 && x3 == x4)
252
            {
253
                return null;
254
            }
255
            else if (x1 == x2)
256
            {
257
                return new double[] { x1, a2*x1 + b2 };
258
            }
259
            else if (x3 == x4)
260
            {
261
                return new double[] { x3, a1 * x3 + b1 };
262
            }
263
            else
264
            {
265
                return new double[] { -(b1 - b2) / (a1 - a2), a1 * -(b1 - b2) / (a1 - a2) + b1 };
266
            }            
267
        }
268

    
269
        public static double CalcGradient(double x1, double y1, double x2, double y2)
270
        {
271
            double result = double.NaN;
272

    
273
            if (x1 != x2)
274
                result = (y2 - y1) / (x2 - x1);
275

    
276
            return result;
277
        }
278

    
279
        public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
280
        {
281
            return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
282
        }
283

    
284
        public static object FindObjectByUID(Document document, string UID)
285
        {
286
            if (!string.IsNullOrEmpty(UID) && UID != "None")
287
            {
288
                foreach (Symbol item in document.SYMBOLS)
289
                {
290
                    if (item.UID == UID)
291
                        return item;
292
                }
293

    
294
                foreach (Line item in document.LINES)
295
                {
296
                    if (item.UID == UID)
297
                        return item;
298
                }
299

    
300
                foreach (Text item in document.TEXTINFOS)
301
                {
302
                    if (item.UID == UID)
303
                        return item;
304
                }
305

    
306
                foreach (Note item in document.NOTES)
307
                {
308
                    if (item.UID == UID)
309
                        return item;
310
                }
311

    
312
                foreach (LineNumber item in document.LINENUMBERS)
313
                {
314
                    if (item.UID == UID)
315
                        return item;
316
                }
317

    
318
                foreach (Equipment item in document.Equipments)
319
                {
320
                    if (item.UID == UID)
321
                        return item;
322
                }
323

    
324
                foreach (SpecBreak item in document.SpecBreaks)
325
                {
326
                    if (item.UID == UID)
327
                        return item;
328
                }
329

    
330
                foreach (EndBreak item in document.EndBreaks)
331
                {
332
                    if (item.UID == UID)
333
                        return item;
334
                }
335

    
336
                foreach (VendorPackage item in document.VendorPackages)
337
                {
338
                    if (item.UID == UID)
339
                        return item;
340
                }
341
            }
342

    
343
            return null;
344
        }
345

    
346
        public static List<Line> FindLinesByModelId(Document document, string ModelItemId)
347
        {
348
            List<Line> lines = new List<Line>();
349
            foreach (Line item in document.LINES)
350
            {
351
                if (item.SPPID.ModelItemId == ModelItemId)
352
                    lines.Add(item);
353
            }
354

    
355
            return lines;
356
        }
357

    
358
        public static void FindConnectedSymbolGroup(Document document, Symbol symbol, List<Symbol> group)
359
        {
360
            if (!group.Contains(symbol))
361
                group.Add(symbol);
362

    
363
            foreach (var connector in symbol.CONNECTORS)
364
            {
365
                object connectedItem = FindObjectByUID(document, connector.CONNECTEDITEM);
366
                if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
367
                {
368
                    Symbol connSymbol = connectedItem as Symbol;
369
                    if (!group.Contains(connSymbol))
370
                    {
371
                        group.Add(connSymbol);
372
                        FindConnectedSymbolGroup(document, connSymbol, group);
373
                    }
374
                }
375
            }
376
        }
377

    
378
        public static Symbol FindCenterAtThreeSymbols(Document document, List<Symbol> group)
379
        {
380
            Symbol result = null;
381

    
382
            // Group의 가운데 찾기
383
            if (group.Count == 3)
384
            {
385
                foreach (var symbol in group)
386
                {
387
                    int count = 0;
388
                    foreach (var connector in symbol.CONNECTORS)
389
                    {
390
                        object item = FindObjectByUID(document, connector.CONNECTEDITEM);
391
                        if (item != null && item.GetType() == typeof(Symbol) && group.Contains(item as Symbol))
392
                            count++;
393
                    }
394

    
395
                    if (count == 2)
396
                    {
397
                        result = symbol;
398
                        break;
399
                    }
400
                }
401
            }
402

    
403
            return result;
404
        }
405

    
406
        private static void GetConnectedSymbol(Document document, Symbol symbol, List<Symbol> symbolGroup)
407
        {
408
            foreach (Connector connector in symbol.CONNECTORS)
409
            {
410
                object item = FindObjectByUID(document, connector.CONNECTEDITEM);
411
                if (item != null && item.GetType() == typeof(Symbol))
412
                {
413
                    Symbol connSymbol = item as Symbol;
414
                    if (connSymbol != null && !symbolGroup.Contains(connSymbol))
415
                    {
416
                        symbolGroup.Add(connSymbol);
417
                        GetConnectedSymbol(document, connSymbol, symbolGroup);
418
                    }
419
                }
420
            }
421
        }
422

    
423
        public static Connector FindSymbolConnectorByUID(Document document, string uid, Symbol targetSymbol)
424
        {
425
            foreach (var connector in targetSymbol.CONNECTORS)
426
            {
427
                if (connector.CONNECTEDITEM == uid)
428
                {
429
                    return connector;
430
                }
431
            }
432

    
433
            return null;
434
        }
435

    
436
        public static Symbol FindSymbolByRepresentationID(Document document, string repID)
437
        {
438
            Symbol findSymbol = null;
439
            foreach (var symbol in document.SYMBOLS)
440
            {
441
                if (symbol.SPPID.RepresentationId == repID)
442
                {
443
                    findSymbol = symbol;
444
                }
445
                else
446
                {
447
                    ChildSymbol childSymbol = FindChildSymbolByRepresentationID(document, symbol, repID);
448
                    if (childSymbol != null)
449
                        findSymbol = symbol;
450
                }
451

    
452
                if (findSymbol != null)
453
                    break;
454
            }
455

    
456
            return findSymbol;
457
        }
458

    
459
        public static ChildSymbol FindChildSymbolByRepresentationID(Document document, Symbol symbol, string repID)
460
        {
461
            ChildSymbol childSymbol = null;
462

    
463
            foreach (ChildSymbol loopChild in symbol.ChildSymbols)
464
            {
465
                if (loopChild.SPPID.RepresentationId == repID)
466
                {
467
                    childSymbol = loopChild;
468
                    break;
469
                }
470
                else
471
                {
472
                    childSymbol = FindChildSymbolByRepresentationIDLoop(document, repID, loopChild);
473
                    if (childSymbol != null)
474
                        break;
475
                }
476
            }
477

    
478
            return childSymbol;
479
        }
480

    
481
        private static ChildSymbol FindChildSymbolByRepresentationIDLoop(Document document, string repID, ChildSymbol childSymbol)
482
        {
483
            ChildSymbol findChild = null;
484

    
485
            foreach (var item in childSymbol.ChildSymbols)
486
            {
487
                if (item.SPPID.RepresentationId == repID)
488
                {
489
                    findChild = item;
490
                    break;
491
                }
492
                else
493
                {
494
                    findChild = FindChildSymbolByRepresentationIDLoop(document, repID, item);
495
                    if (findChild != null)
496
                        break;
497
                }
498
            }
499

    
500
            return findChild;
501
        }
502

    
503
        public static bool IsBranchLine(Line line1, Line line2)
504
        {
505
            bool result = true;
506

    
507
            Connector conn1 = line1.CONNECTORS.Find(x => x.CONNECTEDITEM == line2.UID);
508
            Connector conn2 = line2.CONNECTORS.Find(x => x.CONNECTEDITEM == line1.UID);
509

    
510
            if (conn1 != null && conn2 != null)
511
                result = false;
512

    
513
            return result;
514
        }
515

    
516
        public static bool IsBranchLine(Line line)
517
        {
518
            Connector connector = line.CONNECTORS.Find(x =>
519
            x.ConnectedObject != null &&
520
            x.ConnectedObject.GetType() == typeof(Line) &&
521
            IsBranchLine(line, x.ConnectedObject as Line));
522
            return connector != null ? true : false;
523
        }
524

    
525
        public static bool IsBranchedLine(Document document,Line line)
526
        {
527
            return document.LINES.Find(x => x.CONNECTORS.Find(y => y.CONNECTEDITEM == line.UID && IsBranchLine(x, y.ConnectedObject as Line)) != null) != null ? true : false;
528
        }
529

    
530
        public static void CalcOverlap(double[] range1, double[] range2, ref double x, ref double y, ref bool overlapX, ref bool overlapY)
531
        {
532
            if (range1[0] <= range2[2] && range1[2] >= range2[0])
533
            {
534
                overlapX = true;
535
                x = Math.Min(Math.Abs(range1[0] - range2[2]), Math.Abs(range1[2] - range2[0]));
536
            }
537

    
538
            if (range1[1] <= range2[3] && range1[3] >= range2[1])
539
            {
540
                overlapY = true;
541
                y = Math.Min(Math.Abs(range1[1] - range2[3]), Math.Abs(range1[3] - range2[1]));
542
            }
543
        }
544

    
545
        public static bool IsOverlap(double[] range1, double[] range2)
546
        {
547
            if (range1[0] <= range2[2] && range1[2] >= range2[0] && range1[1] <= range2[3] && range1[3] >= range2[1])
548
                return true;
549
            else
550
                return false;
551
        }
552

    
553
        public static void CalcNewCoordinateForSymbol(Symbol symbol, Symbol prevSymbol, double distanceX, double distanceY)
554
        {
555
            SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
556
            GridSetting _GridSetting = GridSetting.GetInstance();
557
            if (slopeType == SlopeType.HORIZONTAL)
558
            {
559
                double length = (Math.Ceiling(distanceX / _GridSetting.Length) + 1) * _GridSetting.Length;
560
                if (prevSymbol.SPPID.ORIGINAL_X < symbol.SPPID.ORIGINAL_X)
561
                    symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + length;
562
                else
563
                    symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - length;
564
            }
565
            else if (slopeType == SlopeType.VERTICAL)
566
            {
567
                double length = (Math.Ceiling(distanceY / _GridSetting.Length) + 1) * _GridSetting.Length;
568
                if (prevSymbol.SPPID.ORIGINAL_Y < symbol.SPPID.ORIGINAL_Y)
569
                    symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + length;
570
                else
571
                    symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - length;
572
            }
573
        }
574

    
575
        public static Line GetConnectedLine(Symbol symbol1, Symbol symbol2)
576
        {
577
            Line line = null;
578
            Connector connector1 = symbol1.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) &&
579
            ((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol2) != null);
580
            Connector connector2 = symbol2.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) &&
581
            ((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol1) != null);
582
            if (connector1 != null && connector2 != null)
583
                line = connector1.ConnectedObject as Line;
584

    
585
            return line;
586
        }
587

    
588
        public static int GetBranchLineCount(Document document, Line line)
589
        {
590
            return document.LINES.FindAll(x => IsBranchLine(line, x) && x.CONNECTORS.Find(y => y.ConnectedObject == line) != null).Count;
591
        }
592

    
593
        public static bool GetLineConnectorPoint(Line line, Connector connector, ref double x, ref double y)
594
        {
595
            bool bStart = false;
596
            int index = line.CONNECTORS.IndexOf(connector);
597
            if (index == 0)
598
            {
599
                x = line.SPPID.START_X;
600
                y = line.SPPID.START_Y;
601
                bStart = true;
602
            }
603
            else
604
            {
605
                x = line.SPPID.END_X;
606
                y = line.SPPID.END_Y;
607
            }
608
            return bStart;
609
        }
610

    
611
        public static bool IsSegment(Document document, Line line1, Line line2)
612
        {
613
            bool result = false;
614

    
615
            SpecBreak specBreak = document.SpecBreaks.Find(x =>
616
                (x.DownStreamUID == line1.UID && x.UpStreamUID == line2.UID) || 
617
                (x.DownStreamUID == line2.UID && x.UpStreamUID == line1.UID));
618

    
619
            EndBreak endBreak = document.EndBreaks.Find(x =>
620
            (x.OWNER == line1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line2.UID) ||
621
            (x.OWNER == line2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line1.UID));
622

    
623
            if (specBreak != null || endBreak != null)
624
                result = true;
625

    
626
            return result;
627
        }
628

    
629
        public static bool IsSegment(Document document, Symbol symbol1, Symbol symbol2)
630
        {
631
            bool result = false;
632
            SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
633
            (x.DownStreamUID == symbol1.UID && x.UpStreamUID == symbol2.UID) ||
634
            (x.DownStreamUID == symbol2.UID && x.UpStreamUID == symbol1.UID));
635

    
636
            EndBreak startEndBreak = document.EndBreaks.Find(x =>
637
            (x.OWNER == symbol1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID) ||
638
            (x.OWNER == symbol2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID));
639

    
640
            if (startSpecBreak != null || startEndBreak != null)
641
                result = true;
642

    
643
            return result;
644
        }
645
        public static void test()
646
        {
647
            Placement placement = new Placement();
648
            //placement.PIDApplyParameters()
649
            LMADataSource dataSource = new LMADataSource();
650
            
651
            LMAFilter filter = new LMAFilter();
652
            //LMACriterion criterion = new LMACriterion();
653
            filter.ItemType = "Label";
654
            //criterion.SourceAttributeName = "NAME";
655
            //criterion.Operator = "=";
656
            //criterion.set_ValueAttribute(name);
657
            //filter.get_Criteria().Add(criterion);
658
            _LMAItems items = dataSource.Collect("Label", Filter: filter);
659
            
660

    
661
            ReleaseCOMObjects(dataSource);
662
        }
663
        public static DataTable GetUnitInfo()
664
        {
665
            LMADataSource dataSource = new LMADataSource();
666
            LMUnits units = new LMUnits();
667
            units.Collect(dataSource);
668
            DataTable dt = new DataTable();
669
            dt.Columns.Add("LEVEL", typeof(string));
670
            dt.Columns.Add("SP_ID", typeof(string));
671
            dt.Columns.Add("PARENTID", typeof(string));
672
            dt.Columns.Add("NAME", typeof(string));
673
            foreach (LMUnit unit in units)
674
            {
675
                string dir = unit.get_Dir_Path();
676
                string[] array = dir.Split('\\');
677
                List<string> parents = new List<string>();
678
                string prevId = "-1";
679
                for (int i = 1; i < array.Length; i++)
680
                {
681
                    string name = array[i];
682
                    string uid = Guid.NewGuid().ToString();
683
                    DataRow[] rows = dt.Select(string.Format("LEVEL = '{0}' AND NAME = '{1}' AND PARENTID = '{2}'", i, name, prevId));
684
                    if (rows.Length == 0)
685
                        dt.Rows.Add(i, uid, prevId, name);
686
                    else
687
                        uid = rows[0]["SP_ID"].ToString();
688
                    prevId = uid;
689
                }
690
            }
691

    
692
            dt.Columns.Remove("LEVEL");
693

    
694
            ReleaseCOMObjects(units);
695
            ReleaseCOMObjects(dataSource);
696

    
697
            return dt;
698
        }
699
        public static string T_OPTIONSETTING_Value(string name)
700
        {
701
            string result = string.Empty;
702
            LMADataSource dataSource = new LMADataSource();
703
            LMOptionSettings settings = new LMOptionSettings();
704

    
705
            LMAFilter filter = new LMAFilter();
706
            LMACriterion criterion = new LMACriterion();
707
            filter.ItemType = "OptionSetting";
708
            criterion.SourceAttributeName = "NAME";
709
            criterion.Operator = "=";
710
            criterion.set_ValueAttribute(name);
711
            filter.get_Criteria().Add(criterion);
712
            settings.Collect(dataSource, Filter: filter);
713

    
714
            foreach (LMOptionSetting item in settings)
715
            {
716
                result = item.get_Value();
717
                break;
718
            }
719

    
720
            ReleaseCOMObjects(criterion);
721
            ReleaseCOMObjects(filter);
722
            ReleaseCOMObjects(settings);
723
            ReleaseCOMObjects(dataSource);
724
            return result;
725
        }
726

    
727
        public static void ReleaseCOMObjects(params object[] objVars)
728
        {
729
            int intNewRefCount = 0;
730
            foreach (object obj in objVars)
731
            {
732
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
733
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
734
            }
735
        }
736
    }
737
}
클립보드 이미지 추가 (최대 크기: 500 MB)