프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 9628f54b

이력 | 보기 | 이력해설 | 다운로드 (7.79 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
using System.Runtime.InteropServices;
25

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

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

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

    
56
            
57
#endif
58
        }
59

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

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

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

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

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

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

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

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

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

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

    
141
                        //doc.CloseDrawing(true);
142

    
143

    
144

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

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

    
174

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

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

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

    
202
        private void simpleButton1_Click(object sender, EventArgs e)
203
        {
204
            Placement _placement = new Placement();
205
            LMADataSource dataSource = new LMADataSource();//placement.PIDDataSource;
206

    
207
            
208

    
209
        }
210
        [DllImport("user32.dll")]
211
        public static extern int FindWindow(string lpClassName, string lpWindowName);
212
        
213
    }
214
}
클립보드 이미지 추가 (최대 크기: 500 MB)