hytos / DTI_PID / APIDConverter / PIDCustomization.cs @ e49e1de9
이력 | 보기 | 이력해설 | 다운로드 (15.9 KB)
1 | 6348c496 | gaqhf | #region namespaces |
---|---|---|---|
2 | using System; |
||
3 | using System.Collections.Generic; |
||
4 | using System.Configuration; |
||
5 | using System.Data; |
||
6 | using System.Data.Common; |
||
7 | using System.Data.SqlClient; |
||
8 | using System.IO; |
||
9 | using System.Linq; |
||
10 | using System.Runtime.InteropServices; |
||
11 | using System.Text; |
||
12 | using System.Threading; |
||
13 | using System.Windows.Forms; |
||
14 | using Autodesk.AutoCAD.ApplicationServices; |
||
15 | using Autodesk.AutoCAD.DatabaseServices; |
||
16 | using Autodesk.AutoCAD.EditorInput; |
||
17 | using Autodesk.AutoCAD.Geometry; |
||
18 | using Autodesk.AutoCAD.Interop; |
||
19 | using Autodesk.AutoCAD.Interop.Common; |
||
20 | using Autodesk.AutoCAD.Runtime; |
||
21 | using Autodesk.AutoCAD.Windows; |
||
22 | using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; |
||
23 | 8562d7dc | gaqhf | using AVEVA.PID.CustomizationUtility.DB; |
24 | using AVEVA.PID.CustomizationUtility.Model; |
||
25 | using AVEVA.PID.CustomizationUtility.Properties; |
||
26 | |||
27 | 6348c496 | gaqhf | #endregion using namespaces |
28 | namespace AVEVA.PID.CustomizationUtility |
||
29 | { |
||
30 | /// <summary> |
||
31 | /// Singleton class used for customization of P&ID application |
||
32 | /// </summary> |
||
33 | public class PIDCustomization |
||
34 | { |
||
35 | public string ProjectName { get; set; } |
||
36 | public string DrawingID { get; set; } |
||
37 | public string DrawingName { get; set; } |
||
38 | public string MajorRevision { get; set; } |
||
39 | public string MinorRevision { get; set; } |
||
40 | public string Description { get; set; } |
||
41 | public string NameOfUser { get; set; } |
||
42 | public string ClientDwgNo { get; set; } |
||
43 | public string RevisedBy { get; set; } |
||
44 | public string CheckedBy { get; set; } |
||
45 | public string ApprovedBy { get; set; } |
||
46 | public string ApprovedBy2 { get; set; } |
||
47 | public string ApprovedBy3 { get; set; } |
||
48 | public string ClientApprovedBy { get; set; } |
||
49 | public byte[] DrawingData { get; set; } |
||
50 | |||
51 | private static PIDCustomization _instance; |
||
52 | /// <summary> |
||
53 | /// private Constructor make it singleton |
||
54 | /// </summary> |
||
55 | private PIDCustomization() |
||
56 | { |
||
57 | DrawingData = null; |
||
58 | } |
||
59 | |||
60 | public static PIDCustomization GetInstance() |
||
61 | { |
||
62 | if (_instance == null) |
||
63 | { |
||
64 | _instance = new PIDCustomization(); |
||
65 | } |
||
66 | return _instance; |
||
67 | } |
||
68 | |||
69 | /// <summary> |
||
70 | /// Public method called on issue drawing in P&ID |
||
71 | /// </summary> |
||
72 | /// <param name="strRecordId">unique database table id for revision</param> |
||
73 | public void ProcessIssueDrawing(string strRecordId) |
||
74 | { |
||
75 | if (!string.IsNullOrEmpty(strRecordId)) |
||
76 | { |
||
77 | ReadDrawingDetails(strRecordId); |
||
78 | SaveBinaryDrawing(); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /// <summary> |
||
83 | /// public method used for processing block |
||
84 | /// </summary> |
||
85 | /// <param name="BlockId"></param> |
||
86 | public void ProcessBlock(ObjectId BlockId) |
||
87 | { |
||
88 | SetColorForEntity(BlockId,0);// white color |
||
89 | } |
||
90 | |||
91 | d327a608 | gaqhf | public static void GetProjectInfo() |
92 | { |
||
93 | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
||
94 | _ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
||
95 | _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
||
96 | _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
||
97 | _ProjectInfo.Port = Settings.Default.ProjectPort; |
||
98 | _ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
||
99 | _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
||
100 | |||
101 | if (Project_DB.ConnTestAndCreateTable()) |
||
102 | { |
||
103 | _ProjectInfo.Enable = true; |
||
104 | } |
||
105 | else |
||
106 | { |
||
107 | _ProjectInfo.Enable = false; |
||
108 | MessageBox.Show("Fail project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error); |
||
109 | } |
||
110 | } |
||
111 | e3ced1c9 | gaqhf | #region Command |
112 | 6348c496 | gaqhf | /// <summary> |
113 | /// This is test command which gives the idea regarding selection of an entity and assigning different color to it |
||
114 | /// </summary> |
||
115 | 74a0c9d6 | gaqhf | [CommandMethod("APIDConverter")] |
116 | public static void APIDConverter() |
||
117 | 6348c496 | gaqhf | { |
118 | d327a608 | gaqhf | GetInstance(); |
119 | GetProjectInfo(); |
||
120 | 88cb9898 | gaqhf | APIDUtils.SetAvevaExplorer(); |
121 | aabc2b2d | gaqhf | } |
122 | dc270d65 | gaqhf | [CommandMethod("AC")] |
123 | public static void AC() |
||
124 | { |
||
125 | e3ced1c9 | gaqhf | GetInstance(); |
126 | d327a608 | gaqhf | GetProjectInfo(); |
127 | 88cb9898 | gaqhf | APIDUtils.SetAvevaExplorer(); |
128 | dc270d65 | gaqhf | } |
129 | aabc2b2d | gaqhf | [CommandMethod("ConverterForm")] |
130 | 74a0c9d6 | gaqhf | public static void ConverterForm() |
131 | aabc2b2d | gaqhf | { |
132 | dc270d65 | gaqhf | APIDConverter form = new APIDConverter(); |
133 | if (AcadApp.ShowModalDialog(form) == DialogResult.OK) |
||
134 | { |
||
135 | |||
136 | } |
||
137 | } |
||
138 | [CommandMethod("ProjectForm")] |
||
139 | public static void ProjectForm() |
||
140 | { |
||
141 | ProjectForm form = new ProjectForm(); |
||
142 | if (AcadApp.ShowModalDialog(form) == DialogResult.OK) |
||
143 | { |
||
144 | 8562d7dc | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
145 | _ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
||
146 | _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
||
147 | _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
||
148 | _ProjectInfo.Port = Settings.Default.ProjectPort; |
||
149 | _ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
||
150 | _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
||
151 | dc270d65 | gaqhf | |
152 | 8562d7dc | gaqhf | if (Project_DB.ConnTestAndCreateTable()) |
153 | { |
||
154 | _ProjectInfo.Enable = true; |
||
155 | MessageBox.Show("Success project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
156 | } |
||
157 | else |
||
158 | { |
||
159 | _ProjectInfo.Enable = false; |
||
160 | MessageBox.Show("Fail project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error); |
||
161 | } |
||
162 | dc270d65 | gaqhf | } |
163 | } |
||
164 | [CommandMethod("MappingForm")] |
||
165 | public static void MappingForm() |
||
166 | { |
||
167 | MappingForm form = new MappingForm(); |
||
168 | if (AcadApp.ShowModalDialog(form) == DialogResult.OK) |
||
169 | 74a0c9d6 | gaqhf | { |
170 | |||
171 | } |
||
172 | 6348c496 | gaqhf | } |
173 | e3ced1c9 | gaqhf | #endregion |
174 | 6348c496 | gaqhf | #region private methods |
175 | private string SaveBinaryDrawing() |
||
176 | { |
||
177 | FileStream fs = null; |
||
178 | string strDrawing = string.Empty; |
||
179 | try |
||
180 | { |
||
181 | if (!string.IsNullOrEmpty(this.DrawingName)) |
||
182 | { |
||
183 | string strDrawingname = this.DrawingName; |
||
184 | //if(!string.IsNullOrEmpty(this.MajorRevision)) |
||
185 | //{ |
||
186 | // strDrawingname = strDrawingname + "_" + this.MajorRevision; |
||
187 | //} |
||
188 | |||
189 | byte[] drawingData = this.DrawingData; |
||
190 | if (null != drawingData) |
||
191 | { |
||
192 | try |
||
193 | { |
||
194 | if (File.Exists(strDrawingname) == true) |
||
195 | { |
||
196 | Microsoft.VisualBasic.FileSystem.Kill(strDrawingname); |
||
197 | } |
||
198 | } |
||
199 | catch (System.Exception ) |
||
200 | { |
||
201 | } |
||
202 | |||
203 | strDrawing = strDrawingname; |
||
204 | string path = GetDrawingSavePath(); |
||
205 | if (!string.IsNullOrEmpty(path)) |
||
206 | { |
||
207 | strDrawing = path + "\\" + strDrawingname; |
||
208 | } |
||
209 | strDrawing += ".dwg"; |
||
210 | |||
211 | fs = new FileStream(strDrawing, FileMode.Create, FileAccess.Write); |
||
212 | int ArraySize = new int(); |
||
213 | ArraySize = drawingData.GetUpperBound(0); |
||
214 | fs.Write(drawingData, 0, ArraySize); |
||
215 | } |
||
216 | } |
||
217 | } |
||
218 | catch (System.Exception ) |
||
219 | { } |
||
220 | finally |
||
221 | { |
||
222 | if (fs != null) |
||
223 | fs.Close(); |
||
224 | } |
||
225 | return strDrawing; |
||
226 | } |
||
227 | |||
228 | private void ReadDrawingDetails(string strRecordId) |
||
229 | { |
||
230 | SqlConnection connection = null; |
||
231 | try |
||
232 | { |
||
233 | int ID = 0; |
||
234 | int.TryParse(strRecordId, out ID); |
||
235 | if (ID > 0) |
||
236 | { |
||
237 | connection = new SqlConnection(); |
||
238 | connection.ConnectionString = GetConnectionString_Reports(); // GetConnectionString(); |
||
239 | connection.Open(); |
||
240 | |||
241 | string strQry = "Select * from SynchroniseDetails where ID = " + ID; |
||
242 | SqlCommand cmd = new SqlCommand(); |
||
243 | cmd.Connection = connection; |
||
244 | cmd.CommandText = strQry; |
||
245 | cmd.CommandType = CommandType.Text; |
||
246 | SqlDataReader reader = cmd.ExecuteReader(); |
||
247 | |||
248 | if (null != reader && reader.HasRows) |
||
249 | { |
||
250 | while (reader.Read()) |
||
251 | { |
||
252 | ProjectName = reader["ProjectName"].ToString(); |
||
253 | DrawingID = reader["DrawingId"].ToString(); |
||
254 | DrawingName = reader["DrawingName"].ToString(); |
||
255 | MajorRevision = reader["Revision"].ToString(); |
||
256 | MinorRevision = reader["MinorRevision"].ToString(); |
||
257 | Description = reader["Description"].ToString(); |
||
258 | NameOfUser = reader["NameOfUser"].ToString(); |
||
259 | ClientDwgNo = reader["ClientDwgNo"].ToString(); |
||
260 | RevisedBy = reader["RevisedBy"].ToString(); |
||
261 | CheckedBy = reader["CheckedBy"].ToString(); |
||
262 | ApprovedBy = reader["ApprovedBy"].ToString(); |
||
263 | ApprovedBy2 = reader["ApprovedBy2"].ToString(); |
||
264 | ApprovedBy3 = reader["ApprovedBy3"].ToString(); |
||
265 | ClientApprovedBy= reader["ClientApprovedBy"].ToString(); |
||
266 | DrawingData = reader["DrawingData"] != null ? (byte[])reader["DrawingData"] : null; |
||
267 | } |
||
268 | } |
||
269 | } |
||
270 | } |
||
271 | catch (System.Exception ) |
||
272 | { } |
||
273 | finally |
||
274 | { |
||
275 | if (connection != null) |
||
276 | connection.Close(); |
||
277 | } |
||
278 | } |
||
279 | private string GetRecordId() |
||
280 | { |
||
281 | string strRecordId = string.Empty; |
||
282 | SqlConnection connection = null; |
||
283 | try |
||
284 | { |
||
285 | connection = new SqlConnection(); |
||
286 | connection.ConnectionString = GetConnectionString_Reports(); // GetConnectionString(); |
||
287 | connection.Open(); |
||
288 | |||
289 | string strQry = "Select Max(ID) from SynchroniseDetails"; |
||
290 | SqlCommand cmd = new SqlCommand(); |
||
291 | cmd.Connection = connection; |
||
292 | cmd.CommandText = strQry; |
||
293 | cmd.CommandType = CommandType.Text; |
||
294 | SqlDataReader reader = cmd.ExecuteReader(); |
||
295 | if (null != reader && reader.HasRows) |
||
296 | { |
||
297 | strRecordId = reader.GetString(0).ToString(); |
||
298 | } |
||
299 | } |
||
300 | catch (System.Exception ) |
||
301 | { } |
||
302 | finally |
||
303 | { |
||
304 | if (connection != null) |
||
305 | connection.Close(); |
||
306 | } |
||
307 | return strRecordId; |
||
308 | } |
||
309 | private string GetConnectionString() |
||
310 | { |
||
311 | string strConn = string.Empty; |
||
312 | if (Utilities.strSQLWinAuthentication.ToUpper() == "YES") |
||
313 | { |
||
314 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLDatabaseName); |
||
315 | } |
||
316 | else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO") |
||
317 | { |
||
318 | string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword; |
||
319 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLDatabaseName + ";" + strAccessString); |
||
320 | } |
||
321 | |||
322 | return strConn; |
||
323 | } |
||
324 | |||
325 | private string GetConnectionString_Reports() |
||
326 | { |
||
327 | string strConn = string.Empty; |
||
328 | if (Utilities.strSQLWinAuthentication.ToUpper() == "YES") |
||
329 | { |
||
330 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLReportsDatabaseName); |
||
331 | } |
||
332 | else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO") |
||
333 | { |
||
334 | string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword; |
||
335 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLReportsDatabaseName + ";" + strAccessString); |
||
336 | } |
||
337 | |||
338 | return strConn; |
||
339 | } |
||
340 | |||
341 | e9ed6b7b | gaqhf | private string GetConnectionString_Admin() |
342 | { |
||
343 | string strConn = string.Empty; |
||
344 | if (Utilities.strSQLWinAuthentication.ToUpper() == "YES") |
||
345 | { |
||
346 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLAdminDatabaseName); |
||
347 | } |
||
348 | else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO") |
||
349 | { |
||
350 | string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword; |
||
351 | strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLAdminDatabaseName + ";" + strAccessString); |
||
352 | } |
||
353 | |||
354 | return strConn; |
||
355 | } |
||
356 | |||
357 | 6348c496 | gaqhf | private string GetDrawingSavePath() |
358 | { |
||
359 | return System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); |
||
360 | } |
||
361 | |||
362 | /// <summary> |
||
363 | /// Sets the color of the entity |
||
364 | /// </summary> |
||
365 | /// <param name="objIdBlockId">block id</param> |
||
366 | /// <param name="iColor">color to be assigned</param> |
||
367 | private void SetColorForEntity(ObjectId objIdBlockId, short iColor) |
||
368 | { |
||
369 | Transaction trans = null; |
||
370 | try |
||
371 | { |
||
372 | if (objIdBlockId != ObjectId.Null) |
||
373 | { |
||
374 | 8562d7dc | gaqhf | Autodesk.AutoCAD.ApplicationServices.Document doc = AcadApp.DocumentManager.MdiActiveDocument; |
375 | 6348c496 | gaqhf | Database db = HostApplicationServices.WorkingDatabase; |
376 | trans = doc.TransactionManager.StartTransaction(); |
||
377 | using (doc.LockDocument()) |
||
378 | { |
||
379 | using (trans) |
||
380 | { |
||
381 | if (objIdBlockId.IsErased == false) |
||
382 | { |
||
383 | Entity objDb = (Entity)trans.GetObject(objIdBlockId, OpenMode.ForWrite); |
||
384 | if (objDb != null) |
||
385 | { |
||
386 | objDb.ColorIndex = iColor; |
||
387 | } |
||
388 | } |
||
389 | trans.Commit(); |
||
390 | } |
||
391 | } |
||
392 | } |
||
393 | } |
||
394 | catch (System.Exception ) |
||
395 | { |
||
396 | } |
||
397 | finally |
||
398 | { |
||
399 | if (trans != null) |
||
400 | { |
||
401 | trans.Dispose(); |
||
402 | } |
||
403 | } |
||
404 | } |
||
405 | #endregion |
||
406 | 6b3cb476 | gaqhf | |
407 | |||
408 | |||
409 | #region TEST |
||
410 | [CommandMethod("TestS", Autodesk.AutoCAD.Runtime.CommandFlags.UsePickSet)] |
||
411 | public static void TestSelection() |
||
412 | { |
||
413 | 59184d1b | gaqhf | APIDUtils.CreateDrawingAndOpen("testA1", "1", "Aveva-Metric", "1"); |
414 | 6b3cb476 | gaqhf | } |
415 | |||
416 | |||
417 | #endregion |
||
418 | 6348c496 | gaqhf | } |
419 | } |