jobAdapt.BOConnect()
jobAdapt.BOConnect()
Hello,
I have been working on a customization within Job Closing that disallows the job from being completed and closed when the completed quantity does not match the production quantity, and display a message when this is the case. I was able to use the Rule Wizard to disable the JobComplete and JobClosed fields when the criteria of CompleteQty is not equal to the ProdQty, however I have been running into issues getting the error message to display.
I have tried setting up a method directive, however it does not provide the necessary fields within pre-processing or post processing (used while on the JobNum field)to achieve the desired effect ( that I have been able to find that is to say). I have also attempted to use the Form Event Wizard, however as I have a negligible level of experience with VB Net (or coding in general) I am running into many syntax errors. If there are any tips anyone would share with me, it would be greatly appreciated.
I feel I know what I would like it to do, just not sure how to get there, so I will just list it out here.
If the row rule (used to disable JobClose and JobComplete) equals true then display message box. I understand the syntax of the message box portion, it's just everything else that is stopping me.
I suspect Job closing from will be simpler to do than MES.
But copied and pasted the code below anyway... it still might will give you some ideas.
'// Custom VB.NET code
'// MES EndActForm
Private Sub LaborDtl_BeforeFieldChange(ByVal sender As object, ByVal args As DataColumnChangeEventArgs) Handles LaborDtl_Column.ColumnChanging
Select Case args.Column.ColumnName
Case "LaborQty"
Dim gotJob As Boolean = false
Dim jobAdapt As JobEntryAdapter = New JobEntryAdapter(EndActForm)
jobAdapt.BOConnect()
try
gotJob = jobAdapt.GetByID(args.Row("JobNum"))
catch e as exception
end try
Dim previousQuantityReported as decimal = 0
try
previousQuantityReported = GetPreviousQuantityReported(args.Row("JobNum"),args.Row("AssemblySeq"),args.Row("oprSeq"))
catch e as exception
end try
Dim currentQuantityReported as decimal = args.ProposedValue
Dim totalQuantityReported as decimal = CDEC(previousQuantityReported) + CDEC(currentQuantityReported)
Dim remainingQuantity as decimal = jobAdapt.JobEntryData.Tables("JobHead").Rows(0)("ProdQty") - previousQuantityReported
if gotJob
try
Dim dRes As DialogResult
if totalQuantityReported <> jobAdapt.JobEntryData.Tables("JobHead").Rows(0)("ProdQty")
if totalQuantityReported > jobAdapt.JobEntryData.Tables("JobHead").Rows(0)("ProdQty")
MessageBox.Show("A message...", "Confirm Labor Quantity")
args.Proposedvalue = 0
else
if args.ProposedValue < jobAdapt.JobEntryData.Tables("JobHead").Rows(0)("ProdQty")
if previousQuantityReported = 0
dRes = MessageBox.Show("Another message...", "Confirm Labor Quantity", MessageBoxButtons.YesNo)
else
dRes = MessageBox.Show("And one more message...", "Confirm Labor Quantity", MessageBoxButtons.YesNo)
end if
If (dRes = DialogResult.Yes) Then
'Continue
'args.Cancel = True
Else
args.proposedValue = 0
End If
end if
end if
else
'We are OK - we match prod quantity.
end if
catch e as exception
end try
else
end if
jobAdapt.Dispose()
Case Else
End Select
End Sub
'//****************************
Private Function GetPreviousQuantityReported(jobNum as string, assemblySeq as integer, oprSeq as integer) as decimal
Dim previousQty as decimal = 0
DIm lbrDS as System.Data.DataSet
Dim whereClause as string = "JobNum = '" + jobNum + "' and AssemblySeq = '" + assemblySeq.ToString() + "' and OprSeq = '" + oprSeq.ToString() + "'"
Dim recSelected as boolean = false
try
'try to get labor transactions for job
lbrDS = SearchFunctions.listLookup(oTrans,"LaborDtlSearchAdapter",recSelected,false,whereClause)
if recSelected
for each lbrRow as DataRow in lbrDS.Tables(0).Rows
if lbrRow("LaborQty") > 0
previousQty = previousQty + lbrRow("LaborQty")
end if
next
else
end if
catch e as exception
end try
return previousQty
End Function
End Module
Thanks for the response B-Ordway. I feel like having your code to look at has already been quite helpful. I do have a couple of questions about what certain lines are achieving. If you don't mind taking the time to help me understand, it would be greatly appreciated.
jobAdapt.BOConnect()
gotJob = jobAdapt.GetByID(args.Row("JobNum"))
Dim remainingQuantity as decimal = jobAdapt.JobEntryData.Tables("JobHead").Rows(0)("ProdQty") - previousQuantityReported
These are all related to the Job adapter, but I'm guessing you won't need any adapters.
Off the top of my head, I believe all the fields you'll want to compare will all be included in the dataset for the Job Closing form. (but I didn't check this)
In my case, all the fields I needed were not included in the data-set for the MES form.
So I had to use an adapter to retrieve that data.
>>jobAdapt.BOConnect()
The Job Adapter - business object connect command
>>gotJob = jobAdapt.GetByID(args.Row("JobNum"))
The dim holds an argument for the adapter connection - get the job records by job number
>> Dim remainingQuantity as decimal = jobAdapt.JobEntryData.Tables("JobHead").Rows(0)("ProdQty") - previousQuantityReported
calculation using the JobHead.ProdQty - retrieved from the JobHead table via the adapter
Note: If you have access to Epicweb...
You might want to seaarch for and download the Business Object Tester. (and the ICE tools manuals too).
With the Business Object Tester you can interact directly with the Epicor dll's & get a feel for how they work in the program (i.e. business objects/adapters).