프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 1ed39474

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

1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Drawing;
5
using System.Data;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10
using System.Threading;
11
using System.IO;
12
using Microsoft.VisualBasic;
13
using Ingr.RAD2D;
14
using Converter.BaseModel;
15
using Converter.SPPID.Properties;
16
using Converter.SPPID.DB;
17
using Converter.SPPID.Util;
18
using Converter.SPPID.Form;
19
using Converter.SPPID.Model;
20
using Plaice;
21
using Llama;
22
using DevExpress.XtraSplashScreen;
23
using Newtonsoft.Json;
24

    
25
namespace Converter.SPPID.Wrapper
26
{
27
    public partial class ConverterDocking : UserControl
28
    {
29
        Ingr.RAD2D.Application radApp;
30
        dynamic application;
31
        public ConverterDocking()
32
        {
33
            InitializeComponent();
34
            application = Interaction.GetObject("", "PIDAutomation.Application");
35
            WrapperApplication wApp = new WrapperApplication(application.Application);
36
            radApp = wApp.RADApplication;
37

    
38
            try
39
            {
40
                textEditDrawingX.EditValue = Settings.Default.DrawingX;
41
                textEditDrawingY.EditValue = Settings.Default.DrawingY;
42
            }
43
            catch (Exception ex)
44
            {
45
                StringBuilder sb = new StringBuilder();
46
                sb.AppendLine(ex.Message);
47
                sb.AppendLine(ex.StackTrace);
48
                MessageBox.Show(sb.ToString());
49
            }
50
            
51

    
52
#if DEBUG
53
            simpleButton1.Visible = true;
54

    
55
            
56
#endif
57
        }
58

    
59
        private void btnConverter_Click(object sender, EventArgs e)
60
        {
61
            ConverterForm converterForm = new ConverterForm();
62
            if (converterForm.ShowDialog() == DialogResult.OK)
63
            {
64
                try
65
                {
66
                    CloseOPCForm.Run();
67

    
68
                    for (int i = 0; i < converterForm.Documents.Count; i++)
69
                    {
70
                        SPPID_Document document = converterForm.Documents[i];
71
                        if (document.SetSPPIDMapping() && document.Enable)
72
                        {
73
                            AutoModeling modeling = new AutoModeling(document, application, radApp);
74
                            modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
75
                            modeling.Run();
76
                        }
77
                    }
78
                }
79
                catch (Exception ex)
80
                {
81
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
82
                }
83
                finally
84
                {
85
                    CloseOPCForm.Stop();
86
                }
87

    
88
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
89
            }
90
        }
91

    
92
        private void btnLinkOPC_Click(object sender, EventArgs e)
93
        {
94
            LMADataSource dataSource = new LMADataSource();
95
            LMDrawings drawings = new LMDrawings();
96

    
97
            try
98
            {
99
                Project_Info _ProjectInfo = Project_Info.GetInstance();
100
                _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
101
                if (Project_DB.ConnTestAndCreateTable())
102
                {
103
                    DataTable dt = Project_DB.SelectSPPID_DB_INFO();
104
                    if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
105
                        SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
106
                    else
107
                        SPPID_DBInfo.Clear();
108

    
109
                    SPPID_DBInfo sPPID_DBInfo = SPPID_DBInfo.GetInstance();
110
                    if (sPPID_DBInfo.Enable)
111
                    {
112
                        drawings.Collect(dataSource);
113

    
114
                        DataTable drawingTable = Project_DB.SelectDrawingInfo();
115
                        drawingTable.Columns.Add("EXIST", typeof(bool));
116
                        drawingTable.Columns.Add("SPPIDPATH", typeof(string));
117

    
118
                        foreach (LMDrawing item in drawings)
119
                        {
120
                            DataRow[] rows = drawingTable.Select(string.Format("DRAWINGNUMBER = '{0}'", item.Attributes["DrawingNumber"].get_Value()));
121
                            foreach (DataRow row in rows)
122
                            {
123
                                row["EXIST"] = true;
124
                                row["DRAWINGNAME"] = item.Attributes["Name"].get_Value();
125
                                row["SPPIDPATH"] = item.get_Path();
126
                            }
127
                        }
128

    
129
                        List<SPPID_Document> allDocuments = new List<SPPID_Document>();
130
                        foreach (DataRow row in drawingTable.Rows)
131
                        {
132
                            SPPID_Document document = JsonConvert.DeserializeObject<SPPID_Document>(row["DOCUMENT"].ToString());
133
                            allDocuments.Add(document);
134
                        }
135

    
136
                        AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp);
137
                        opc.Run();
138
                        //dynamic doc = application.Drawings.OpenDrawing(drawingTable.Rows[0]["DRAWINGNAME"]);
139

    
140
                        //doc.CloseDrawing(true);
141

    
142

    
143

    
144
                        //radApp.Documents.Open(sPPID_DBInfo.PlantPath + @"\" + drawingTable.Rows[0]["SPPIDPATH"].ToString());
145
                    }
146
                }
147
                else
148
                {
149
                    MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
150
                }
151
            }
152
            catch (Exception ex)
153
            {
154
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
155
            }
156
            finally
157
            {
158
                ReleaseCOMObjects(dataSource);
159
                ReleaseCOMObjects(drawings);
160
            }
161
        }
162

    
163
        public void ReleaseCOMObjects(params object[] objVars)
164
        {
165
            int intNewRefCount = 0;
166
            foreach (object obj in objVars)
167
            {
168
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
169
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
170
            }
171
        }
172

    
173

    
174
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
175
        {
176
            if (radApp.ActiveSelectSet.Count > 0)
177
            {
178
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
179
                if (line2D != null)
180
                {
181
                    double minX = 0;
182
                    double minY = 0;
183
                    double maxX = 0;
184
                    double maxY = 0;
185
                    line2D.Range(out minX, out minY, out maxX, out maxY);
186

    
187
                    Settings.Default.DrawingX = maxX - minX;
188
                    Settings.Default.DrawingY = maxY - minY;
189
                    Settings.Default.Save();
190

    
191
                    textEditDrawingX.EditValue = Settings.Default.DrawingX;
192
                    textEditDrawingY.EditValue = Settings.Default.DrawingY;
193
                }
194
                else
195
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
196
            }
197
            else
198
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
199
        }
200

    
201
        static Command command;
202
        int CmdID;
203
        string CmdCLSID;
204
        bool isActiveInPlace;
205
        CommandTypeConstants CommandTypeConstants;
206
        string argList;
207
        string DLLName;
208
        string HelpFile;
209

    
210
        private void simpleButton1_Click(object sender, EventArgs e)
211
        {
212
            Placement _placement = new Placement();
213
            LMADataSource dataSource = new LMADataSource();//placement.PIDDataSource;
214

    
215
            LMConnector connector = dataSource.GetConnector("");
216

    
217
            LMSymbol symbol1 = connector.ConnectItem1SymbolObject;
218
            LMSymbol symbol2 = connector.ConnectItem2SymbolObject;
219

    
220
        }
221

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