0% found this document useful (0 votes)
132 views

Dim As String Dim As String Dim As Dim As

This code is creating a new work order in a manufacturing execution system (MES). It gets the user credentials, starts a new session, and then creates the work order by calling the CreateWOFromProcess function. It also updates additional fields like lot number and scheduled start times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views

Dim As String Dim As String Dim As Dim As

This code is creating a new work order in a manufacturing execution system (MES). It gets the user credentials, starts a new session, and then creates the work order by calling the CreateWOFromProcess function. It also updates additional fields like lot number and scheduled start times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1 Me.WO_ResultText = "Creating Work Order ...

";
2
3 dim userID as string;
4 dim userPwd as string;
5 dim result as aaMES.Result;
6 dim DS as System.Data.DataSet;
7
8 clientType = aaMES.Core.aaClientTypes.clientOperator;
9 userID = Me.UserID;
10 userPwd = Me.UserPwd;
11 specVerId = Me.SpecVerID; ' Can be customized bayed on process or line specific
versions
12
13 'Diagnostic Information
14 me.Diagnostic.Status = 1;
15 me.Diagnostic.StatusMessage = "Create New Work Order";
16 me.Diagnostic.ExecMethod = "CreateWO";
17 me.Diagnostic.ErrorMessage = "";
18
19 debug = me.Debug;
20 if debug then LogMessage("Create WO"); endif;
21
22 'get existing session, if it doesn't exist start new session
23 result = aaMES.Core.aaSession.GetSessions(sessionID, clientType, userID);
24 DS = Result.Dataset_Value;
25 if (DS.Tables(0).Rows.count > 0) then
26 'use an existing connection
27 me.SessionID = DS.Tables(0).Rows(0).item("session_id");
28 me.UserID = DS.Tables(0).Rows(0).item("user_id");
29 else
30 ' start client operator session
31 result = aaMES.Core.aaSession.StartSession( clientType, sessionId );
32
33 if sessionID > 0 then
34 if debug then LogMessage("Session Started"); endif;
35 me.SessionID = sessionID;
36 endif;
37 endif;
38
39 If sessionID > 0 then
40
41 'Dim user as System.String;
42 'user = "Admin";
43 'Dim pwd as System.String;
44 'pwd = "Admin";
45 result = aaMES.Core.aaSession.LogIn(sessionId, userID, userPwd);
46 if result.Success then
47 if debug then LogMessage("MES Logon Succeeded for user "); endif;
48
49 Dim startQty as double;
50
51 startQty = Me.New_Quantity;
52
53 'Starting Job Creation Transaction
54 if debug then LogMessage(" -> Start Transaction"); endif;
55 aaMES.Core.aaTransaction.StartTransaction();
56
57 Dim releaseTime as System.DateTime;
58 releaseTime = Now();
59
60 sValue = StringTrim( Me.New_Customer, 3);
61 if (sValue == "") OR (sValue == null) then
62 sValue = "-";
63 endif;
64
65 result = aaMES.Prod.aaJobExec.CreateWOFromProcess(Me.SessionId,
Me.GetNewWOId.WO_Id, Me.GetProcess.ProcessSelected,
Me.GetProcess.ProcessSelected, startQty, userID , startQty, null,
Me.GetNewWOId.WO_Id + " Desc" , null, null, 1, sValue, Me.New_Process_Order,
Me.New_Long_Lot, null, null, specVerID, null, null );
66 me.Diagnostic.Status = Result.Success;
67 If me.Diagnostic.Status then
68 if debug then LogMessage("Creating WO from Process Succeeded"); endif;
69
70 ' ADD Lot update specs for all entities
71 dim t as string;
72 dim dt as System.DateTime;
73
74 for each opEnt in operEntDict
75 ' Check if operattion is final and set job_bom.update_inv flag to
TRUE
76 if me.Diagnostic.Status then
77 result = aaMES.Prod.aaJob.GetByKey(Me.GetNewWOId.WO_Id, opEnt.Key
, 0);
78 if result.Success and result.DataSet_Value.Tables.Count > 0 and
result.DataSet_Value.Tables(0).Rows.Count > 0 then
79
80 if debug then LogMessage(System.String.Format("WO [{0}] with
Oper:[{1}] found", Me.GetNewWOId.WO_Id,opEnt.Key)); endif;
81
82 isFinalJob = false;
83 isFinalJob = result.DataSet_Value.Tables(0).Rows(0).Item(
"final_job");
84
85 dt = result.DataSet_Value.Tables(0).Rows(0).Item("edit_time"
);
86
87 if isFinalJob then
88 LogMessage (System.String.Format(" => Final Job: WO={0},
Oper={1}, IsFinalJob={2}. Set UpdateInv=1 on BomPos=0",
Me.GetNewWOId.WO_Id, opEnt.Key, isFinalJob));
89 t = null; result = aaMES.EnProd.aaJobBom.UpdateSpecific(
Me.SessionId, Me.GetNewWOId.WO_Id, opEnt.Key, 0, 0,
Me.GetProcess.ProcessSelected, null, null, null, null,
null, null, null, true, null, null, null, null, null,
null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, t );
90 me.Diagnostic.Status = me.Diagnostic.Status AND
result.Success; LogMessage(
"JobBom.UpdateSpecific[UpdateInv]");
91 endif;
92
93 ' Update sched start time to now
94 if me.Diagnostic.Status then

's
95 result = aaMES.Prod.aaJob.UpdateSpecific( Me.SessionId,
Me.GetNewWOId.WO_Id, opEnt.Key, 0,null, null, null, null,
null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null,
null, null, null, null, aaMES.aaDBDateTime.FromDateTime(
System.DateTime.Now), null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, dt );
96 me.Diagnostic.Status = me.Diagnostic.Status AND
result.Success; LogMessage("Job.UpdateSpecific[Sched
Start Time]");
97 endif;
98
99 ' Update sched start time to now for oven seq no 1 and 2
100 if opEnt.Key == "1100" then
101 ' Update sched start for seq 1 time to now
102 if me.Diagnostic.Status then
103 result = aaMES.Prod.aaJob.GetByKey(
Me.GetNewWOId.WO_Id, opEnt.Key, 1);
104 if result.Success and me.Diagnostic.Status and
result.DataSet_Value.Tables.Count > 0 and
result.DataSet_Value.Tables(0).Rows.Count > 0 then

's
105 dt = result.DataSet_Value.Tables(0).Rows(0).Item
("edit_time");
106 result = aaMES.Prod.aaJob.UpdateSpecific(
Me.SessionId, Me.GetNewWOId.WO_Id, opEnt.Key, 1,
null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, aaMES.aaDBDateTime.FromDateTime(
System.DateTime.Now), null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, dt );
107 me.Diagnostic.Status = me.Diagnostic.Status AND
result.Success; LogMessage(
"Job.UpdateSpecific[Sched Start Time]");
108 endif;
109 endif;
110 ' Update sched start for seq 2 time to now
111 if me.Diagnostic.Status then
112 result = aaMES.Prod.aaJob.GetByKey(
Me.GetNewWOId.WO_Id, opEnt.Key, 2);
113 if result.Success and me.Diagnostic.Status and
result.DataSet_Value.Tables.Count > 0 and
result.DataSet_Value.Tables(0).Rows.Count > 0 then

's
114 dt = result.DataSet_Value.Tables(0).Rows(0).Item
("edit_time");
115 result = aaMES.Prod.aaJob.UpdateSpecific(
Me.SessionId, Me.GetNewWOId.WO_Id, opEnt.Key, 2,
null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, aaMES.aaDBDateTime.FromDateTime(
System.DateTime.Now), null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, null, dt );
116 me.Diagnostic.Status = me.Diagnostic.Status AND
result.Success; LogMessage(
"Job.UpdateSpecific[Sched Start Time]");
117 endif;
118 endif;
119 endif;
120
121 endif;
122 endif;
123
124 ' Update specific additional specs
125 if me.Diagnostic.Status then
126 t = null; result = aaMES.EnProd.aaJobSpec.UpdateSpecific(
Me.SessionId, Me.GetNewWOId.WO_Id, opEnt.Key, 0, -1, "LotNo",
Me.New_Long_Lot, null, null, null, null, null, null, null, null,
t );
127 me.Diagnostic.Status = me.Diagnostic.Status AND result.Success;
LogMessage("JobSpec.UpdateSpecific[Lot]");
128 endif;
129
130 if opEnt.Key == "1100" then
131 if me.Diagnostic.Status then
132 t = null; result = aaMES.EnProd.aaJobSpec.UpdateSpecific(
Me.SessionId, Me.GetNewWOId.WO_Id, opEnt.Key, 1, -1, "LotNo",
Me.New_Long_Lot, null, null, null, null, null, null, null,
null, t );
133 me.Diagnostic.Status = me.Diagnostic.Status AND
result.Success; LogMessage("JobSpec.UpdateSpecific[Lot]");
134 endif;
135 if me.Diagnostic.Status then
136 t = null; result = aaMES.EnProd.aaJobSpec.UpdateSpecific(
Me.SessionId, Me.GetNewWOId.WO_Id, opEnt.Key, 2, -1, "LotNo",
Me.New_Long_Lot, null, null, null, null, null, null, null,
null, t );
137 me.Diagnostic.Status = me.Diagnostic.Status AND
result.Success; LogMessage("JobSpec.UpdateSpecific[Lot]");
138 endif;
139 endif;
140 next;
141
142
143
144 if me.Diagnostic.Status then
145 ' All it's OK and we must commit transaction
146 if debug then LogMessage(" <- Commit Transaction"); endif;
147 aaMES.Core.aaTransaction.CommitTransaction();
148 Me.GetAllWOs.WO_Selected = Me.GetNewWOId.WO_Id;
149 Me.LoadWOTrigger = true;
150 if debug then LogMessage("Update WO Spec Succeeded"); endif;
151 Me.WO_ResultText = "Work Order '" + Me.GetNewWOId.WO_Id + "' Created
Successfully.";
152 else
153 me.Diagnostic.ErrorMessage = "Update WO '" + Me.GetNewWOId.WO_Id +
"' Spec Failed";
154 me.Diagnostic.Status = 0;
155 me.ErrorHandlerTrigger = 1;
156 Me.WO_ResultText = "Failed To Create Work Order '" +
Me.GetNewWOId.WO_Id + "'!";
157 endif;
158 '**********************************
159 else
160 Me.Diagnostic.ErrorMessage = "Creating WO '" + Me.GetNewWOId.WO_Id + "'
from Process Failed: " + result.Exception.Message;
161 me.Diagnostic.Status = 0;
162 me.ErrorHandlerTrigger = 1;
163 Me.WO_ResultText = "Failed To Create Work Order '" + Me.GetNewWOId.WO_Id
+ "'! [" + result.Exception.Message + "]";
164 endif;
165 else
166 Me.Diagnostic.ErrorMessage = "User Logon Failed: " + result.Exception.Message;
167 me.Diagnostic.Status = 0;
168 me.ErrorHandlerTrigger = 1;
169 Me.WO_ResultText = Me.Diagnostic.ErrorMessage;
170 endif;
171
172 else
173 Me.Diagnostic.ErrorMessage = "Creating WO '" + Me.GetNewWOId.WO_Id + "' Failed.
Can't connect to session.";
174 me.Diagnostic.Status = 0;
175 me.ErrorHandlerTrigger = 1;
176 Me.WO_ResultText = "Failed To Create Work Order '" + Me.GetNewWOId.WO_Id + "'!";
177 endif;
178
179
180
181
182 Me.CreateWOTrigger = false;
183

You might also like