Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim c 'As ADODB.Connection
- Dim com 'As ADODB.Command
- dim com2
- Dim rs 'As ADODB.Recordset
- dim rs2
- dim rs3
- 'Parameters that will be reused
- 'Queries in one place
- dim qry
- dim qry2
- dim qry3
- If not(GOOD_QTY = 0 and BAD_QTY = 0) Then
- qry = "SELECT DISTINCT TOP 1 SEQUENCE_NO FROM OPERATION WHERE (WORKORDER_BASE_ID = ?) AND (WORKORDER_LOT_ID = ?) AND (WORKORDER_SPLIT_ID = ?) AND (WORKORDER_SUB_ID = ?) and(SEQUENCE_NO < ?) ORDER BY SEQUENCE_NO DESC"
- qry2 = "SELECT case when quantity is null then 0 else quantity end AS Good_QTY FROM (SELECT WORKORDER_BASE_ID, WORKORDER_LOT_ID, WORKORDER_SPLIT_ID, WORKORDER_SUB_ID, OPERATION_SEQ_NO, SUM(GOOD_QTY) AS Quantity FROM LABOR_TICKET where workorder_type = 'W' GROUP BY WORKORDER_BASE_ID, WORKORDER_LOT_ID, WORKORDER_SPLIT_ID, WORKORDER_SUB_ID, OPERATION_SEQ_NO) as a WHERE (WORKORDER_BASE_ID = ?) AND (WORKORDER_LOT_ID = ?) AND (WORKORDER_SPLIT_ID = ?) AND (WORKORDER_SUB_ID = ?) AND (OPERATION_SEQ_NO = ?)"
- qry3 = "Select Desired_qty from Work_Order where Base_ID = ?"
- Set c = CreateObject("ADODB.Connection")
- c.ConnectionString = "Provider=SQLOLEDB;Server=DB3;Database=VMFG1;Integrated Security = SSPI"
- Set com = CreateObject("adodb.command")
- com.CommandType = 1 'adCmdText
- c.Open
- Set com.ActiveConnection = c
- com.CommandText = qry
- com.Parameters.Append com.CreateParameter("wo", 200,1, 25,WORKORDER_BASE_ID) '("@wo,adVarChar,adParamInput,25,WORKORDER_BASE_ID)
- com.Parameters.Append com.CreateParameter("lot", 200,1, 25,WORKORDER_LOT_ID) '("@lot,adVarChar,adParamInput,25,WORKORDER_LOT_ID)
- com.Parameters.Append com.CreateParameter("split", 200,1, 25,WORKORDER_SPLIT_ID) '("@split,adVarChar,adParamInput,25,WORKORDER_SPLIT_ID)
- com.Parameters.Append com.CreateParameter("sub", 200,1, 25,WORKORDER_SUB_ID) '("@sub,adVarChar,adParamInput,25,WORKORDER_SUB_ID)
- com.Parameters.Append com.CreateParameter("op", 3, 1,,OPERATION_SEQ_NO) '("@op,adInteger,adParamInput,OPERATION_SEQ_NO)
- set rs = com.Execute
- 'com.commandtext = qry3
- 'set rs3 = com.execute
- if rs.recordcount > 0 then
- com.parameters(4).value = rs(OPERATION_SEQ_NO)
- com.commandtext = qry2
- set rs2 = com.execute
- if rs2.recordcount > 0 then
- if rs3.recordcount > 0 then
- if rs2("good_qty") < good_qty + bad_qty + rs3("good_qty") + rs3("BAD_QTY") then
- macro_success = false
- macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") + already clocked in quantity good (" & rs3("good_qty") & ") + already clocked in quantity bad (" & rs3("bad_qty") & ") Totaled(" & (good_qty + bad_qty + rs3("good_qty") + rs3("BAD_QTY")) & ") are greater than the previous Operation (" & rs2("good_qty") & ")"
- else
- macro_success = true
- end if
- else
- if rs2("good_qty") < good_qty + bad_qty then
- macro_success = false
- macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") Totaled(" & (good_qty + bad_qty) & ") are greater than the previous Operation (" & rs2("good_qty") & ")"
- else
- macro_success = true
- end if
- end if
- else
- macro_success = false
- macro_message = "The previous operation does not have any parts clocked in"
- end if
- else
- Set com2 = CreateObject("adodb.command")
- com2.CommandType = 1 'adCmdText
- Set com2.ActiveConnection = c
- com2.CommandText = qry3
- com2.Parameters.Append com2.CreateParameter("wo", 200,1, 25,WORKORDER_BASE_ID)'("@wo,adVarChar,adParamInput,25)
- 'set rs2 = com2.execute
- set rs2 = createobject("adodb.recordset")
- rs2.open com2,,3,1 'com2,c,adOpenStatic,adLockReadOnly
- if rs2.recordcount > 0 then
- if rs3.recordcount > 0 then
- if rs2("Desired_qty") < good_qty + bad_qty + rs3("good_qty") + rs3("BAD_QTY") then
- macro_success = false
- macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") + already clocked in quantity good (" & rs3("good_qty") & ") + already clocked in quantity bad (" & rs3("bad_qty") & ") Totaled(" & (good_qty + bad_qty + rs3("good_qty") + rs3("BAD_QTY")) & ") are greater than the Work Order quantity (" & rs2("Desired_qty") & ")"
- else
- macro_success = true
- end if
- else
- if rs2("Desired_qty") < good_qty + bad_qty then
- macro_success = false
- macro_message = "The quantity good (" & good_qty & ") + the quantity bad (" & bad_qty & ") Totaled(" & (good_qty + bad_qty) & ") are greater than the Work Order quantity (" & rs2("Desired_qty") & ")"
- else
- macro_success = true
- end if
- end if
- else
- macro_success = false
- macro_message = "Invalid Work Order is nothing " & (rs2 is nothing) & " rc" & rs.recordcount & " eof " & rs.eof & " bof " & rs.bof & " state " & rs.state & " dq " & rs2("Desired_qty")'how the heck does the quantity even work?!
- end if
- end if
- c.Close
- Set rs = Nothing
- set rs2 = nothing
- set rs3 = nothing
- Set c = Nothing
- Set com = Nothing
- set com2 = nothing
- end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement