Mdf walkthrough

Custom Class Generator

CCG is the core of entire framework.

You can describe your entities (equipment, orders, materials, lots, sublots, handling units and personnel) and an useful Visual Studio addin create sql tables, data sets and .NET classes.

In example, in your MES application you want to model an equipmet like a Tank with a Volume property. So you add a new EquipmentClass (Tank), an EquipmentProperty (decimal Volume) and associate property to equipment class. Launching Visual Studio addin, CCG creates for you Tanks tables, Mdf.Custom.Equipment.DsEquipment, a data set to access the table, and the Tank class.

Here you can find the Tank.Mdf.cs generated from the CCG

1#region Using
2
3using System;
4using System.Collections.Generic;
5using System.Text;
6using System.Transactions;
7using Mdf.Base;
8using Mdf.Custom.Equipment.DsCustomEquipmentTableAdapters;
9
10#endregion
11
12namespace Mdf.Custom.Equipment
13{
14    public partial class Tank : Mdf.Base.MdfObject
15    {
16        #region Class definition
17
18        private DsCustomEquipment dsCustomEquipment;
19
20        /// <summary>
21        /// Initialize a new instance of tank class
22        /// </summary>
23        public Tank()
24        {
25            dsCustomEquipment = new DsCustomEquipment();
26            TankRow = dsCustomEquipment.Tanks.NewTanksRow();
27            TankRow.EquipmentClassID = "Tank";
28        }
29
30        /// <summary>
31        /// Initialize a new instance of tank class
32        /// </summary>
33        /// <param name="tankID">The tank id of the tank</param>
34        public Tank(string tankID)
35        {
36            dsCustomEquipment = new DsCustomEquipment();
37            TankRow = GetTankByTankID(tankID);
38            dsCustomEquipment.Tanks.ImportRow(TankRow);
39        }
40
41        #endregion
42
43        #region Methods
44
45        /// <summary>
46        /// Save data into database
47        /// </summary>
48        public override void Save()
49        {
50            TanksTableAdapter tanksTableAdapter = new TanksTableAdapter();
51            using (TransactionScope transactionScope = new TransactionScope())
52            {
53                if (TankRow.RowState == System.Data.DataRowState.Detached)
54                {
55                    dsCustomEquipment.Tanks.AddTanksRow(TankRow);
56                    Mdf.Equipment.Equipment.Add(TankID, Description, EquipmentClassID, ParentEquipmentID);
57                }
58                else
59                {
60                    Mdf.Equipment.Equipment.Modify(TankID, Description, EquipmentClassID, ParentEquipmentID);
61                }
62                tanksTableAdapter.Update(dsCustomEquipment);
63                transactionScope.Complete();
64            }
65        }
66        
67        /// <summary>
68        /// Delete tank from database
69        /// </summary>
70        public override void Delete()
71        {
72            TanksTableAdapter tanksTableAdapter = new TanksTableAdapter();
73            using (TransactionScope transactionScope = new TransactionScope())
74            {
75                if (TankRow.RowState != System.Data.DataRowState.Detached)
76                {
77                    TankRow.Delete();
78                    tanksTableAdapter.Update(dsCustomEquipment);
79                    Mdf.Equipment.Equipment.Delete(TankID);
80                }
81                transactionScope.Complete();
82            }
83        }        
84
85        /// <summary>
86        /// Convert tank primary key into string
87        /// </summary>
88        public override string ToString()
89        {
90            return TankRow.TankID;
91        }
92
93        #endregion
94
95        #region Properties
96
97        /// <summary>
98        /// The tank row
99        /// </summary>
100        public DsCustomEquipment.TanksRow TankRow;
101
102        /// <summary>
103        /// The tank id of the tank
104        /// <summary>
105        public string TankID
106        {
107            get
108            {
109                return TankRow.TankID;
110            }
111            set
112            {
113                TankRow.TankID = value;
114            }
115        }
116
117        /// <summary>
118        /// The description of the tank
119        /// <summary>
120        public string Description
121        {
122            get
123            {
124                return TankRow.Description;
125            }
126            set
127            {
128                TankRow.Description = value;
129            }
130        }
131
132        /// <summary>
133        /// The equipment class id of the tank
134        /// <summary>
135        public string EquipmentClassID
136        {
137            get
138            {
139                return TankRow.EquipmentClassID;
140            }
141        }
142
143        /// <summary>
144        /// The parent equipment id of the tank
145        /// <summary>
146        public string ParentEquipmentID
147        {
148            get
149            {
150                return TankRow.ParentEquipmentID;
151            }
152            set
153            {
154                TankRow.ParentEquipmentID = value;
155            }
156        }
157
158        /// <summary>
159        /// The volume of the tank
160        /// <summary>
161        public decimal Volume
162        {
163            get
164            {
165                return TankRow.Volume;
166            }
167            set
168            {
169                TankRow.Volume = value;
170            }
171        }
172
173        #endregion
174
175        #region Static methods
176
177        #region Add, modify and delete methods
178
179        /// <summary>
180        /// Add new tank row
181        /// </summary>
182        /// <param name="tankID">The tank id of the tank</param>
183        /// <param name="description">The description of the tank</param>
184        /// <param name="parentEquipmentID">The parent equipment of the tank</param>
185        /// <param name="Volume"> The volume of the tank</param>
186        /// <returns>The new tank row</returns>
187        public static DsCustomEquipment.TanksRow Add(string tankID, string description, string parentEquipmentID, decimal volume)
188        {
189            DsCustomEquipment dsCustomEquipment = new DsCustomEquipment();
190            TanksTableAdapter tanksTableAdapter  = new TanksTableAdapter();
191            DsCustomEquipment.TanksRow tanksRow = dsCustomEquipment.Tanks.NewTanksRow();
192
193            tanksRow.Description = description;
194            tanksRow.ParentEquipmentID = parentEquipmentID;
195            tanksRow.TankID = tankID;
196            tanksRow.Volume = volume;
197            tanksRow.EquipmentClassID = "Tank";
198            dsCustomEquipment.Tanks.AddTanksRow(tanksRow);
199            using (TransactionScope transactionScope = new TransactionScope())
200            {
201                Mdf.Equipment.Equipment.Add(tankID, description, tanksRow.EquipmentClassID, parentEquipmentID);
202
203                tanksTableAdapter.Update(tanksRow);
204                transactionScope.Complete();
205            }
206
207            return tanksRow;
208        }
209
210        /// <summary>
211        /// Modify a tank
212        /// </summary>
213        /// <param name="tankID">The tank id of the tank</param>
214        /// <param name="description">The description of the tank</param>
215        /// <param name="parentEquipmentID">The parent equipment of the tank</param>
216        /// <param name="Volume"> The volume of the tank</param>
217        public static void Modify(string tankID, string description, string parentEquipmentID, decimal volume)
218        {
219            TanksTableAdapter tanksTableAdapter = new TanksTableAdapter();
220            DsCustomEquipment.TanksRow tanksRow = GetTankByTankID(tankID);
221
222            tanksRow.Volume = volume;
223
224            using (TransactionScope transactionScope = new TransactionScope())
225            {
226                Mdf.Equipment.Equipment.Modify(tankID, description, tanksRow.EquipmentClassID, parentEquipmentID);
227
228                tanksTableAdapter.Update(tanksRow);
229                transactionScope.Complete();
230            }
231        }
232
233        /// <summary>
234        /// Delete the selected tank
235        /// </summary>
236        /// <param name="tankID">The tank id of the tank</param>
237        public static void Delete(string tankID)
238        {
239            TanksTableAdapter tanksTableAdapter = new TanksTableAdapter();
240            DsCustomEquipment.TanksRow tanksRow = GetTankByTankID(tankID);
241
242            tanksRow.Delete();
243            using (TransactionScope transactionScope = new TransactionScope())
244            {
245                tanksTableAdapter.Update(tanksRow);
246                Mdf.Equipment.Equipment.Delete(tankID);
247                transactionScope.Complete();
248            }
249        }
250
251        #endregion
252
253        #region Exist method
254        
255        /// <summary>
256        /// Check if exist tank row by primary key
257        /// </summary>
258        /// <param name="tankID">The tank id of the tank</param>
259        /// <returns>Return true if row exist</returns>
260        public static bool Exist(string tankID)
261        {
262            DsCustomEquipment dsCustomEquipment = new DsCustomEquipment();
263            TanksTableAdapter tanksTableAdapter = new TanksTableAdapter();
264            tanksTableAdapter.FillByTankID(dsCustomEquipment.Tanks, tankID);
265
266            if (dsCustomEquipment.Tanks.Count > 0)
267            {
268                return true;
269            }
270            else
271            {
272                return false;
273            }
274        }
275        
276        #endregion
277        
278        #region Get methods
279
280        /// <summary>
281        /// Get selected tank row by primary key
282        /// </summary>
283        /// <param name="tankID">The tank id of the tank</param>
284        /// <returns>Return tank identified by PK</returns>
285        public static DsCustomEquipment.TanksRow GetTankByTankID(string tankID)
286        {
287            DsCustomEquipment dsCustomEquipment = new DsCustomEquipment();
288            TanksTableAdapter tanksTableAdapter = new TanksTableAdapter();
289            tanksTableAdapter.FillByTankID(dsCustomEquipment.Tanks, tankID);
290
291            if (dsCustomEquipment.Tanks.Count == 0)
292            {
293                throw new Exception(ErrorResource.EquipmentNotFound);
294            }
295
296            DsCustomEquipment.TanksRow tanksRow = dsCustomEquipment.Tanks[0];
297            return tanksRow;
298        }
299
300        /// <summary>
301        /// Get all tank rows
302        /// </summary>
303        /// <returns>Return data set with all tank rows</returns>
304        public static DsCustomEquipment GetTanks()
305        {
306            DsCustomEquipment dsCustomEquipment = new DsCustomEquipment();
307            TanksTableAdapter tanksTableAdapter = new TanksTableAdapter();
308            tanksTableAdapter.Fill(dsCustomEquipment.Tanks);
309            return dsCustomEquipment;
310        }
311
312        /// <summary>
313        /// Return number of rows
314        /// </summary>
315        public static int Count
316        {
317            get
318            {
319                TanksTableAdapter tanksTableAdapter = new TanksTableAdapter();
320                System.Nullable<int> count = tanksTableAdapter.Count();
321                if (count != null)
322                {
323                    return (int)count;
324                }
325                else
326                {
327                    return 0;
328                }
329            }
330        }
331        
332        #endregion
333
334        #endregion
335    }
336}
337

Next step is Using partial class

 

Mdf - Mes development framework

Mdf - Mes development framework

Mdf - MES Development Framework born after an experience in MES Development with standard development tools like Visual Studio .NET 2005. We were unsatisfied from the available tools nowadays, so we are looking for a methodology that can help you to write robust industrial solution compliant to ISA-95 standards.

Download the Mdf latest version here.