Standard |
Comboboxes |
ShowText |
Basic |
name (Form) |
54 |
SUB ShowText(oEvent AS OBJECT) DIM oForm AS OBJECT DIM inCom AS INTEGER DIM oFieldList AS OBJECT DIM stFieldID AS STRING DIM stQuery AS STRING DIM stFieldValue AS STRING oForm = oEvent.Source aComboboxen() = Split(oForm.getByName("combofields").Tag,",") FOR inCom = LBound(aComboboxen) TO UBound(aComboboxen) oFieldList = oForm.getByName(Trim(aComboboxen(inCom))) stFieldID = oForm.getString(oForm.findColumn(oFieldList.Tag)) oFieldList.Refresh() IF stFieldID <> "" THEN stQuery = oFieldList.ListSource IF InStr(stQuery,"order by") > 0 THEN stSql = Left(stQuery, InStr(stQuery,"order by")-1) ELSE stSql = stQuery END IF IF InStr(stSql,"where") THEN st = Right(stSql, Len(stSql)-InStr(stSql,"where")-4) IF InStr(Left(st, InStr(st,"=")),".""ID""") THEN a() = Split(Right(st, Len(st)-InStr(st,"=")-1),".") ELSE a() = Split(Left(st, InStr(st,"=")-1),".") END IF stSql = stSql + "AND "+a(0)+".""ID"" = "+stFieldID ELSE stSql = stSql + "WHERE ""ID"" = "+stFieldID END IF oDatasource = ThisComponent.Parent.CurrentController IF NOT (oDatasource.isConnected()) THEN oDatasource.connect() END IF oConnection = oDatasource.ActiveConnection() oSQL_Command = oConnection.createStatement() oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next stFieldValue = oResult.getString(1) WEND oFieldList.Text = stFieldValue ELSE oFieldList.Text = "" END IF NEXT inCom END SUB |
Standard |
Comboboxes |
TextSelectionSaveValue |
Basic |
name (Form) name_correlated_subquery (Form) name_tablecontrol (Form) |
263 |
SUB TextSelectionSaveValue(oEvent AS OBJECT) DIM oDatasource AS OBJECT DIM oConnection AS OBJECT DIM oResult AS OBJECT DIM oSQL_Command AS OBJECT DIM NameIDField AS STRING DIM NameTableField1 AS STRING DIM NameTableField2 AS STRING DIM stFieldSeparator AS STRING DIM NameTable1 AS STRING DIM NameTable2 AS STRING DIM NameTab12ID AS STRING DIM Position AS INTEGER DIM oFieldList AS OBJECT DIM oField AS OBJECT DIM oForm AS OBJECT DIM stQuery AS STRING DIM stContent AS STRING DIM i AS INTEGER DIM stContentField2 AS STRING DIM a_stParts() AS STRING DIM stmsgbox1 AS STRING DIM stmsgbox2 AS STRING DIM inID1 AS INTEGER DIM inID2 AS INTEGER DIM LengthField1 AS INTEGER DIM LengthField2 AS INTEGER IF InStr(oEvent.Source.ImplementationName,"ODatabaseForm") THEN oForm = oEvent.Source aComboboxen() = Split(oForm.getByName("combofields").Tag,",") FOR inCom = LBound(aComboboxen) TO UBound(aComboboxen) NameTable2 = "" a() = Split(Trim(aComboboxen(inCom)),">") IF Ubound(a) > 0 THEN oFieldList = oForm.getByName(a(0)).getByName(a(1)) ELSE oFieldList = oForm.getByname(a(0)) END IF stQuery = oFieldList.ListSource aFields() = Split(stQuery, """") stContent = "" FOR i=LBound(aFields)+1 TO UBound(aFields) IF Trim(UCASE(aFields(i))) = "ORDER BY" THEN EXIT FOR ELSEIF Trim(UCASE(aFields(i))) = "FROM" THEN stContent = stContent+" §§ " ELSEIF Trim(UCASE(aFields(i))) = "WHERE" THEN stContent = stContent+" §§ " ELSE stContent = stContent+Trim(aFields(i)) END IF NEXT i aContent() = Split(stContent, " §§ ") aFirst() = Split(aContent(0),"||") IF UBound(aFirst) > 0 THEN IF UBound(aContent) > 1 THEN aTest() = Split(aFirst(0),".") NameTable1 = aTest(0) NameTableField1 = aTest(1) Erase aTest stFieldSeparator = Join(Split(aFirst(1),"'"),"") aTest() = Split(aFirst(2),".") NameTable2 = aTest(0) NameTableField2 = aTest(1) Erase aTest aTest() = Split(aContent(2),"=") aTest1() = Split(aTest(0),".") IF aTest1(1) <> "ID" THEN NameTab12ID = aTest1(1) IF aTest1(0) = NameTable1 THEN Position = 2 ELSE Position = 1 END IF ELSE Erase aTest1 aTest1() = Split(aTest(1),".") NameTab12ID = aTest1(1) IF aTest1(0) = NameTable1 THEN Position = 2 ELSE Position = 1 END IF END IF ELSE IF UBound(aFirst) > 1 THEN NameTableField1 = aFirst(0) stFieldSeparator = Join(Split(aFirst(1),"'"),"") NameTableField2 = aFirst(2) ELSE NameTableField1 = aFirst(0) NameTableField2 = aFirst(1) END IF NameTable1 = aContent(1) END IF ELSE NameTableField1 = aFirst(0) NameTable1 = aContent(1) END IF LengthField1 = ColumnSize(NameTable1,NameTableField1) IF NameTableField2 <> "" THEN IF NameTable2 <> "" THEN LengthField2 = ColumnSize(NameTable2,NameTableField2) ELSE LengthField2 = ColumnSize(NameTable1,NameTableField2) END IF ELSE LengthField2 = 0 END IF stContent = oFieldList.getCurrentValue() stContent = Trim(stContent) IF stContent <> "" THEN IF NameTableField2 <> "" THEN a_stParts = Split(stContent, stFieldSeparator, 2) IF Position = 2 THEN stContent = Trim(a_stParts(0)) IF UBound(a_stParts()) > 0 THEN stContentField2 = Trim(a_stParts(1)) ELSE stContentField2 = "" END IF ELSE stContentField2 = Trim(a_stParts(0)) IF UBound(a_stParts()) > 0 THEN stContent = Trim(a_stParts(1)) ELSE stContent = "" END IF END IF END IF IF (LengthField1 > 0 AND Len(stContent) > LengthField1) OR (LengthField2 > 0 AND Len(stContentField2) > LengthField2) THEN stmsgbox1 = "Field "+NameTableField1+" must not exceed "+LengthField1+ " characters in length."+CHR(13) stmsgbox2 = "Field "+NameTableField2+" must not exceed "+LengthField2+ " characters in length."+CHR(13) IF (LengthField1 > 0 AND Len(stContent) > LengthField1) AND (LengthField2 > 0 AND Len(stContentField2) > LengthField2) THEN msgbox ("The entered text is too long."+CHR(13)+stmsgbox1+stmsgbox2+"Please shorten it.",64,"Invalid entry") ELSEIF (LengthField1 > 0 AND Len(stContent) > LengthField1) THEN msgbox ("The entered text is too long."+CHR(13)+stmsgbox1+"Please shorten it.",64,"Invalid entry") ELSE msgbox ("The entered text is too long."+CHR(13)+stmsgbox2+"Please shorten it.",64,"Invalid entry") END IF ELSE stContent = String_to_SQL(stContent) IF stContentField2 <> "" THEN stContentField2 = String_to_SQL(stContentField2) END IF inID1 = -1 inID2 = -1 oDatasource = ThisComponent.Parent.CurrentController If NOT (oDatasource.isConnected()) Then oDatasource.connect() End If oConnection = oDatasource.ActiveConnection() oSQL_Command = oConnection.createStatement() IF NameTableField2 <> "" AND NOT IsEmpty(stContentField2) AND NameTable2 <> "" THEN stSql = "SELECT ""ID"" FROM """+NameTable2+""" WHERE """+NameTableField2+"""='"+stContentField2+"'" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inID2 = oResult.getInt(1) WEND IF inID2 = -1 THEN stSql = "INSERT INTO """+NameTable2+""" ("""+NameTableField2+""") VALUES ('"+stContentField2+"') " oSQL_Command.executeUpdate(stSql) stSql = "CALL IDENTITY()" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inID2 = oResult.getInt(1) WEND END IF stSql = "SELECT ""ID"" FROM """+NameTable1+""" WHERE """+NameTab12ID+"""='"+inID2+"' AND """+NameTableField1+""" = '"+stContent+"'" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inID1 = oResult.getInt(1) WEND IF inID1 = -1 THEN stSql = "INSERT INTO """+NameTable1+""" ("""+NameTableField1+""","""+NameTab12ID+""") VALUES ('"+stContent+"','"+inID2+"') " oSQL_Command.executeUpdate(stSql) stSql = "CALL IDENTITY()" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inID1 = oResult.getInt(1) WEND END IF END IF IF NameTableField2 <> "" AND NameTable2 = "" THEN stSql = "SELECT ""ID"" FROM """+NameTable1+""" WHERE """+NameTableField1+"""='"+stContent+"' AND """+NameTableField2+"""='"+stContentField2+"'" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inID1 = oResult.getInt(1) WEND IF inID1 = -1 THEN stSql = "INSERT INTO """+NameTable1+""" ("""+NameTableField1+""","""+NameTableField2+""") VALUES ('"+stContent+"','"+stContentField2+"') " oSQL_Command.executeUpdate(stSql) stSql = "CALL IDENTITY()" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inID1 = oResult.getInt(1) WEND END IF END IF IF NameTableField2 = "" THEN stSql = "SELECT ""ID"" FROM """+NameTable1+""" WHERE """+NameTableField1+"""='"+stContent+"'" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inID1 = oResult.getInt(1) WEND IF inID1 = -1 THEN stSql = "INSERT INTO """+NameTable1+""" ("""+NameTableField1+""") VALUES ('"+stContent+"') " oSQL_Command.executeUpdate(stSql) stSql = "CALL IDENTITY()" oResult = oSQL_Command.executeQuery(stSql) WHILE oResult.next inID1 = oResult.getInt(1) WEND END IF END IF oForm.updateLong(oForm.findColumn(oFieldList.Tag),inID1) END IF ELSE oForm.updateNULL(oForm.findColumn(oFieldList.Tag),NULL) END IF NEXT inCom END IF END SUB |