K3 BOS Form Plug-in Development - Table Header Value Change Events

Keywords: SQL less

In creating the form plug-in, each class has the following code:

  1.    
  2. 'Definition BillEvent Interface. Statements that must be made, To get the event  
  3. Private WithEvents m_BillInterface  As BillEvent  
  4.    
  5. Public Sub Show(ByVal oBillInterface As Object)  
  6.    
  7.     'BillEvent Interface implementation  
  8.     'Be careful: This method must exist, Do not modify  
  9.     Set m_BillInterface = oBillInterface  
  10.    
  11. End Sub  
  12.   
  13. Private Sub Class_Terminate()  
  14.    
  15.     'Release interface objects  
  16.     'Be careful: This method must exist, Do not modify  
  17.     Set m_BillInterface = Nothing  
  18.   
  19. End Sub  


Here I mainly write down an event that starts when a field value in the form header changes.

Here, there are several questions that need to be considered:

1. How does the value change event of the form trigger?

Change events of BillEvent objects can be triggered, for example:

  1. Private Sub m_BillInterface_Change(ByVal <u>dct</u> As KFO.IDictionary, ByVal dctFld As KFO.IDictionary, ByVal Col As LongByVal Row As Long, Cancel As Boolean)  

 

2. After obtaining the data dictionary, how do you know whether the form value changes or the form value changes?

  1. Select Case dct.Value("Fpage")  
  2.     Case 1  
  3.     .......  
  4. End Select  

Case 1 represents the header and case 2 represents the body (at present, this is only my guess, not authoritative, I do not know where to follow this information, if a friend knows it, also tell me).

 

3. How do you determine which field value change triggered the change of form value when it started?

  1. If UCase(dct.Value("FFieldName")) = UCase("FBase") Then  
  2.   .....  
  3. End If  

dct.Value("FFieldName") can get the key fields of the control on the form, and I guess where I know it, but I don't know why. But it works.

UCase: Converts strings to uppercase. As for VB, I am still a beginner, so these basic knowledge points are still written at the beginning.

4. How to print the output information in the console for debugging or other purposes?

  1. Debug.Print "Input the data you want to output......"  

 

5. In the development of form plug-in, how to get data through SQL statements?

  1. strSQL = "Select item.FNumber FNumber,item.FName FName,Scph,mu1.FNumber DhslUnit,Dhsl,mu2.FNumber ScslUnit,Scsl,YwgCount,isnull(JhDate,'') JhDate,Remark,FComboBox " & _  
  2.                  "From t_BOS200000035 bos " & _  
  3.                  "Join t_BOS200000035Entry2 bosEntry " & _  
  4.                  "On bos.FID = bosEntry.FID " & _  
  5.                  "Join t_Icitem item " & _  
  6.                  "On bosEntry.Hpdh = item.FItemID " & _  
  7.                  "Join t_MeasureUnit mu1 " & _  
  8.                  "On mu1.FMeasureUnitID = bosEntry.DhslUnit " & _  
  9.                  "Join t_MeasureUnit mu2 " & _  
  10.                  "On mu2.FMeasureUnitID = bosEntry.ScslUnit " & _  
  11.                  "Where bos.FBase = " & strCustomer  
  12.                    
  13. Debug.Print strSQL  
  14.               
  15. Set rs = m_BillInterface.K3Lib.GetData(strSQL)  

Using K3Lib.GetData("sql statement") you can get the result set after querying.

 

6. How to empty the data in the table?

  1. For i = 1 To m_BillInterface.Data("Page2").UBound Step 1  
  2.     m_BillInterface.RemoveRow False, 2, 1  
  3. Next  

 

7. How to assign values to tables or insert data sets into tables?

  1. j = 1  
  2. Do While Not rs.EOF          
  3.     m_BillInterface.InsertNewRowAndFill 2, j, _  
  4.                                         "FBase1", rs.Fields("FNumber").Value, _  
  5.                                         "FText1", rs.Fields("Scph").Value, _  
  6.                                         "FBase2", rs.Fields("DhslUnit").Value, _  
  7.                                         "FQty", rs.Fields("Dhsl").Value, _  
  8.                                         "FBase3", rs.Fields("ScslUnit").Value, _  
  9.                                         "FQty1", rs.Fields("Scsl").Value, _  
  10.                                         "FInteger", rs.Fields("YwgCount").Value, _  
  11.                                         "FNOTE", rs.Fields("Remark").Value, _  
  12.                                         "FDate2", rs.Fields("JhDate").Value, _  
  13.                                         "FComboBox", rs.Fields("FComboBox").Value  
  14.     rs.MoveNext  
  15.     j = j + 1  
  16. Loop  

InsertNewRowAndFill function
Insert a new row in the multi-entry document body and fill in the data.
grammar
    Object.InsertNewRowAndFill (nPage As Long, nRow As Long, ParamArray vFieldsData() As Variant)

Notes
1. The parameter nRow must be a valid line number.

Namely: must be greater than or equal to 1, less than the largest row of document entries; must be continuous with the row of existing data.
For example, in order to add new lines and insert data in line 3 of a document entry, the first step is to confirm that the maximum line of a document entry is greater than 3, and the second is a single line.
The second line of the volume entry requires data.


2. Variable parameter vFieldsData format is:
[Field 1 Key Name, Value of Field 1], [Field 2 Key Name, Value of Field 2], [... ] [Key name of field n, value of field n]

Key field names can be found from the following, which is what I currently think of as a method:

You can find it in the drop-down list in the properties window.

 

8. The key code of the above example:

  1. Private Sub m_BillInterface_Change(ByVal dct As KFO.IDictionary, ByVal dctFld As KFO.IDictionary, ByVal Col As LongByVal Row As Long, Cancel As Boolean)  
  2.   
  3.     Dim strSQL As String, i As Integer, j As Integer  
  4.     Dim rs As ADODB.Recordset  
  5.     Dim Fnumber As String  
  6.   
  7.     Dim strCustomer As String  
  8.     Select Case dct.Value("Fpage")  
  9.     Case 1  
  10.      If UCase(dct.Value("FFieldName")) = UCase("FBase"Then  
  11.        
  12.         strCustomer = m_BillInterface.GetFieldValue("FBase", -1, Enu_ValueType_FFLD)  
  13.         strSQL = "Select item.FNumber FNumber,item.FName FName,Scph,mu1.FNumber DhslUnit,Dhsl,mu2.FNumber ScslUnit,Scsl,YwgCount,isnull(JhDate,'') JhDate,Remark,FComboBox " & _  
  14.                  "From t_BOS200000035 bos " & _  
  15.                  "Join t_BOS200000035Entry2 bosEntry " & _  
  16.                  "On bos.FID = bosEntry.FID " & _  
  17.                  "Join t_Icitem item " & _  
  18.                  "On bosEntry.Hpdh = item.FItemID " & _  
  19.                  "Join t_MeasureUnit mu1 " & _  
  20.                  "On mu1.FMeasureUnitID = bosEntry.DhslUnit " & _  
  21.                  "Join t_MeasureUnit mu2 " & _  
  22.                  "On mu2.FMeasureUnitID = bosEntry.ScslUnit " & _  
  23.                  "Where bos.FBase = " & strCustomer  
  24.             Debug.Print strSQL  
  25.               
  26.             Set rs = m_BillInterface.K3Lib.GetData(strSQL)  
  27.             For i = 1 To m_BillInterface.Data("Page2").UBound Step 1  
  28.                  m_BillInterface.RemoveRow False, 2, 1  
  29.             Next  
  30.                   
  31.             j = 1  
  32.             Do While Not rs.EOF  
  33.               
  34.                 m_BillInterface.InsertNewRowAndFill 2, j, _  
  35.                                                         "FBase1", rs.Fields("FNumber").Value, _  
  36.                                                         "FText1", rs.Fields("Scph").Value, _  
  37.                                                         "FBase2", rs.Fields("DhslUnit").Value, _  
  38.                                                         "FQty", rs.Fields("Dhsl").Value, _  
  39.                                                         "FBase3", rs.Fields("ScslUnit").Value, _  
  40.                                                         "FQty1", rs.Fields("Scsl").Value, _  
  41.                                                         "FInteger", rs.Fields("YwgCount").Value, _  
  42.                                                         "FNOTE", rs.Fields("Remark").Value, _  
  43.                                                         "FDate2", rs.Fields("JhDate").Value, _  
  44.                                                         "FComboBox", rs.Fields("FComboBox").Value  
  45.                 rs.MoveNext  
  46.                 j = j + 1  
  47.             Loop  
  48.       End If  
  49.     End Select  
  50.                
  51. End Sub  


 

How does 9.K3 BOS call stored procedures?

  1. if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Proc_K3_ProductionOrdersByCustomer]'and OBJECTPROPERTY(id, N'IsProcedure') = 1)  
  2. drop procedure [dbo].[Proc_K3_ProductionOrdersByCustomer]  
  3. GO  
  4. ------------------------------------  
  5. --Purpose: To query record information   
  6. --Project name: K3  
  7. --Explain:  
  8. --Time: 2012-1-30 15:30:59  
  9. ------------------------------------  
  10. CREATE PROCEDURE Proc_K3_ProductionOrdersByCustomer  
  11.     @strCustomer int  
  12. AS  
  13.     Select item.FNumber FNumber,item.FName FName,Scph,mu1.FNumber DhslUnit,Dhsl,mu2.FNumber ScslUnit,Scsl,YwgCount,isnull(JhDate,'') JhDate,Remark,FComboBox  
  14.     From t_BOS200000035 bos  
  15.     Join t_BOS200000035Entry2 bosEntry  
  16.     On bos.FID = bosEntry.FID  
  17.     Join t_Icitem item  
  18.     On bosEntry.Hpdh = item.FItemID  
  19.     Join t_MeasureUnit mu1  
  20.     On mu1.FMeasureUnitID = bosEntry.DhslUnit  
  21.     Join t_MeasureUnit mu2  
  22.     On mu2.FMeasureUnitID = bosEntry.ScslUnit  
  23.     Where bos.FBase = @strCustomer  
  24. GO  
  25.   
  26. exec Proc_K3_ProductionOrdersByCustomer 878  


Called in Bos as follows:

  1. strSQL = "exec Proc_K3_ProductionOrdersByCustomer " & strCustomer  
  2.   
  3. Set rs = m_BillInterface.K3Lib.GetData(strSQL)  

Personally, I understand that statements passed in by m_BillInterface.K3Lib.GetData() can be executed in GetData statements as long as they are executable under the query analyzer.

Posted by slamMan on Mon, 08 Apr 2019 12:06:31 -0700