Le forum (ô combien francophone) des utilisateurs de Powerbuilder.
Pages: 1
A la demande de chet_92,
j'ai refait une interface pb.
Le but, pouvoir avoir une datawindow dynamique d'une table, d'une procedure stockée, ou d'une vue.
il est possible de faire des jointures dans la requete sql.
je detaillerai cela apres.
à importer en premier !
le fichier str_infosobject.srs
$PBExportHeader$str_infosobject.srs $PBExportComments$[STRUCTURE]** structure d'informations global type str_infosobject from structure string as_titre string as_source[] string as_code string as_parametre string as_variable_type[] string as_variable[] string as_root[] string as_choix string as_variable_acces[] string as_nomobjet[] datawindow adw_dw datawindow adw_dwliste[] end type
voila, il faudra prendre en compte cet objet ensuite.
faites un import du fichier w__requete_sql_dyn.srw :
$PBExportHeader$w__requete_sql_dyn.srw $PBExportComments$[RESP] Fenetre de requete SQL forward global type w__requete_sql_dyn from window end type type cb_valider from commandbutton within w__requete_sql_dyn end type type mle_type from multilineedit within w__requete_sql_dyn end type type mle_code from multilineedit within w__requete_sql_dyn end type end forward global type w__requete_sql_dyn from window integer x = 361 integer y = 160 integer width = 2958 integer height = 1956 boolean titlebar = true string title = "Requete SQL" boolean controlmenu = true windowtype windowtype = response! long backcolor = 79741120 string icon = "Query5!" event ue_impression ( ) cb_valider cb_valider mle_type mle_type mle_code mle_code end type global w__requete_sql_dyn w__requete_sql_dyn type prototypes FUNCTION boolean AnimateWindow( long lhWnd, long lTm, long lFlags) LIBRARY 'user32' end prototypes type variables end variables on w__requete_sql_dyn.create this.cb_valider=create cb_valider this.mle_type=create mle_type this.mle_code=create mle_code this.Control[]={this.cb_valider,& this.mle_type,& this.mle_code} end on on w__requete_sql_dyn.destroy destroy(this.cb_valider) destroy(this.mle_type) destroy(this.mle_code) end on event open;/**********************************************************************************************/ /* Nom : open */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ str_infosobject lstr_infos long ll_cpt lstr_infos = message.powerobjectparm if not isvalid(lstr_infos) then close(this) return end if setpointer(hourglass!) mle_code.text = lstr_infos.as_titre for ll_cpt = 1 to upperbound(lstr_infos.as_nomobjet) mle_type.text = mle_type.text + lstr_infos.as_nomobjet[ll_cpt] + char(13) + char(10) next animateWindow ( Handle( this ),500,16) end event type cb_valider from commandbutton within w__requete_sql_dyn integer y = 1768 integer width = 2930 integer height = 92 integer taborder = 30 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "&Valider la requête sql" end type event clicked;/**********************************************************************************************/ /* Nom : clicked cb_valider */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ string ls_sql ls_sql = mle_code.Text closewithreturn(parent,ls_sql) end event type mle_type from multilineedit within w__requete_sql_dyn integer x = 1627 integer width = 1298 integer height = 1760 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 33422824 boolean hscrollbar = true boolean vscrollbar = true boolean displayonly = true borderstyle borderstyle = stylelowered! end type type mle_code from multilineedit within w__requete_sql_dyn integer width = 1618 integer height = 1760 integer taborder = 10 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" long textcolor = 33554432 long backcolor = 15793151 boolean hscrollbar = true boolean vscrollbar = true borderstyle borderstyle = stylelowered! end type
puis de w__tablesql_dyn.srw :
$PBExportHeader$w__tablesql_dyn.srw $PBExportComments$[RESP] Fenetre de recherche de tables forward global type w__tablesql_dyn from window end type type cb_sql from commandbutton within w__tablesql_dyn end type type st_liste from statictext within w__tablesql_dyn end type type cb_filtrerliste from commandbutton within w__tablesql_dyn end type type cb_trierliste from commandbutton within w__tablesql_dyn end type type cb_saveliste from commandbutton within w__tablesql_dyn end type type cb_retrieveliste from commandbutton within w__tablesql_dyn end type type dw_liste from datawindow within w__tablesql_dyn end type type gb_liste from groupbox within w__tablesql_dyn end type end forward global type w__tablesql_dyn from window integer x = 41 integer y = 48 integer width = 3159 integer height = 1980 boolean titlebar = true string title = "Construction dynamique datawindow suivant une requete SQL" boolean controlmenu = true windowtype windowtype = response! long backcolor = 31909606 string icon = "Database!" cb_sql cb_sql st_liste st_liste cb_filtrerliste cb_filtrerliste cb_trierliste cb_trierliste cb_saveliste cb_saveliste cb_retrieveliste cb_retrieveliste dw_liste dw_liste gb_liste gb_liste end type global w__tablesql_dyn w__tablesql_dyn type prototypes end prototypes type variables string is_name string is_type_colonne[] string is_sql_liste end variables forward prototypes public function long wf_dw_nbobject (datawindow adw_dw, boolean ab_colonne_titre, ref string as_ret[]) public subroutine wf_modify_dwresult (datawindow adw_liste, boolean ab_listing) end prototypes public function long wf_dw_nbobject (datawindow adw_dw, boolean ab_colonne_titre, ref string as_ret[]);/**********************************************************************************************/ /* Nom : wf_dw_object */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ string ls_objects string ls_object_list[], ls_vide[], ls_titre[], ls_colonne[] string ls_delimeter = "~t" string ls_colonne_titre = '_t' long ll_found_index, ll_next_index, ll_i, ll_max ls_objects = adw_dw.Object.DataWindow.Objects ls_object_list = ls_vide is_type_colonne = ls_vide if len(ls_objects) > 0 then ll_found_index = 1 ll_next_index = pos(ls_objects, ls_delimeter, ll_found_index) do while ll_next_index > 0 ls_object_list[upperbound(ls_object_list) + 1] = mid(ls_objects, ll_found_index, ll_next_index - ll_found_index) ll_found_index = ll_next_index + 1 ll_next_index = pos(ls_objects, ls_delimeter, ll_found_index) loop ls_object_list[upperbound(ls_object_list) + 1] = mid(ls_objects, ll_found_index, len(ls_objects)) end if ll_max = upperbound(ls_object_list) for ll_i = 1 to ll_max if Right(lower(ls_object_list[ll_i]), 2) = ls_colonne_titre then ls_titre[upperbound(ls_titre) + 1] = ls_object_list[ll_i] else ls_colonne[upperbound(ls_colonne) + 1] = ls_object_list[ll_i] if adw_dw = dw_liste then is_type_colonne[upperbound(is_type_colonne) + 1] = & ls_object_list[ll_i] + "~t " +adw_dw.Describe(ls_object_list[ll_i]+".ColType") end if end if next choose case ab_colonne_titre case true as_ret = ls_titre case false as_ret = ls_colonne end choose ll_max = upperbound(as_ret) return ll_max end function public subroutine wf_modify_dwresult (datawindow adw_liste, boolean ab_listing);////////////////////////////////////////////////////////////////////////////// // // Nom : wf_Modify_DwResult (EXTERNE) // But : Modifier les attributs visuels de la DW générée // script : // Argument : adw_liste, datawindow recevant le résultat // // Return : // Comment : // section : // History : // //////////////////////////////////////////////////////////////////////////////// string ls_TextList[], ls_ColList[] Integer li_nbrObj, li_i1 Long ll_maxheight = 0 Boolean lb_maxheight = False // Modifier la couleur de fond adw_liste.Object.DataWindow.Color='31778020' // Modifier le style et la couleur des textes li_nbrObj = wf_dw_nbobject(adw_liste,true,ls_TextList) FOR li_i1 = 1 TO li_nbrObj IF li_i1 = 1 THEN ll_maxheight = Long(adw_liste.Describe(ls_TextList[li_i1] +".Height")) IF ll_maxheight <> Long(adw_liste.Describe(ls_TextList[li_i1] +".Height")) THEN lb_maxheight = TRUE IF ll_maxheight < Long(adw_liste.Describe(ls_TextList[li_i1] +".Height")) THEN ll_maxheight = Long(adw_liste.Describe(ls_TextList[li_i1] +".Height")) END IF adw_liste.Modify(ls_TextList[li_i1] + ".Background.Mode='0'") adw_liste.Modify(ls_TextList[li_i1] + ".Background.Color='67108864'") adw_liste.Modify(ls_TextList[li_i1] + ".Border='6'") NEXT // Mettre tous les objets textes à la hauteur maxi IF lb_maxheight = TRUE THEN FOR li_i1 = 1 TO li_nbrObj adw_liste.Modify(ls_TextList[li_i1] +".Height='" + string(ll_maxheight) + "'") NEXT END IF // Modifier le style et la couleur des colonnes li_nbrObj = wf_dw_nbobject(adw_liste,false,ls_ColList) FOR li_i1 = 1 TO li_nbrObj IF ab_listing = True THEN adw_liste.Modify(ls_ColList[li_i1] + ".Background.Mode='1'") adw_liste.Modify("DataWindow.Detail.Color= '" + string(12582911) + & "~tif( mod(getRow(),2 ) = 0 ," + string(12582911) + ", rgb(255, 211, 168))'") ELSE adw_liste.Modify(ls_ColList[li_i1] + ".Background.Mode='0'") END IF adw_liste.Modify(ls_ColList[li_i1] + ".Background.Color='16777215'") adw_liste.Modify(ls_ColList[li_i1] + ".Border='0'") NEXT adw_liste.Modify("DataWindow.ReadOnly=Yes") end subroutine on w__tablesql_dyn.create this.cb_sql=create cb_sql this.st_liste=create st_liste this.cb_filtrerliste=create cb_filtrerliste this.cb_trierliste=create cb_trierliste this.cb_saveliste=create cb_saveliste this.cb_retrieveliste=create cb_retrieveliste this.dw_liste=create dw_liste this.gb_liste=create gb_liste this.Control[]={this.cb_sql,& this.st_liste,& this.cb_filtrerliste,& this.cb_trierliste,& this.cb_saveliste,& this.cb_retrieveliste,& this.dw_liste,& this.gb_liste} end on on w__tablesql_dyn.destroy destroy(this.cb_sql) destroy(this.st_liste) destroy(this.cb_filtrerliste) destroy(this.cb_trierliste) destroy(this.cb_saveliste) destroy(this.cb_retrieveliste) destroy(this.dw_liste) destroy(this.gb_liste) end on type cb_sql from commandbutton within w__tablesql_dyn integer x = 2551 integer y = 408 integer width = 526 integer height = 92 integer taborder = 50 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "Re&quete SQL" end type event clicked;/**********************************************************************************************/ /* Nom : clicked cb_sql */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ str_infosobject lstr_infos string ls_sql string ls_presentation string ls_syntax string ls_erreur setpointer(hourglass!) lstr_infos.as_titre = is_sql_liste lstr_infos.as_nomobjet = is_type_colonne //if upperbound(lstr_infos.as_nomobjet) > 0 then openwithparm(w__requete_sql_dyn,lstr_infos) ls_sql = message.StringParm if len(trim(ls_sql)) > 1 then ls_presentation = "style(type=grid)" ls_syntax = SQLCA.SyntaxFromSQL(ls_sql,ls_presentation, ls_erreur) IF Len(ls_erreur) > 0 THEN MessageBox("Information", & "Erreur dans: " + ls_erreur) RETURN END IF dw_liste.Create( ls_syntax, ls_erreur) IF Len(ls_erreur) > 0 THEN MessageBox("Information", & "Erreur dans: " + ls_erreur) RETURN END IF dw_liste.Settransobject(sqlca) is_sql_liste = ls_sql st_liste.text = string(dw_liste.rowcount()) + ' ligne(s)' wf_Modify_DwResult(dw_liste,true) end if //end if end event type st_liste from statictext within w__tablesql_dyn integer x = 2551 integer y = 1780 integer width = 526 integer height = 52 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" long textcolor = 16711680 long backcolor = 31909606 boolean focusrectangle = false end type type cb_filtrerliste from commandbutton within w__tablesql_dyn integer x = 2551 integer y = 76 integer width = 526 integer height = 92 integer taborder = 20 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "F&iltrer" end type event clicked;/**********************************************************************************************/ /* Nom : clicked cb_filtrerliste */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ string ls_null setnull(ls_null) if dw_liste.setfilter(ls_null) = 1 then dw_liste.filter() end if st_liste.text = string(dw_liste.rowcount()) + ' ligne(s)' end event type cb_trierliste from commandbutton within w__tablesql_dyn integer x = 2551 integer y = 184 integer width = 526 integer height = 92 integer taborder = 30 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "T&rier" end type event clicked;/**********************************************************************************************/ /* Nom : clicked cb_trierliste */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ string ls_null setnull(ls_null) if dw_liste.setsort(ls_null) = 1 then dw_liste.sort() end if st_liste.text = string(dw_liste.rowcount()) + ' ligne(s)' end event type cb_saveliste from commandbutton within w__tablesql_dyn integer x = 2551 integer y = 1676 integer width = 526 integer height = 92 integer taborder = 60 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "E&nregistrer sous..." end type event clicked;/**********************************************************************************************/ /* Nom : clicked cb_saveliste */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ dw_liste.saveas() end event type cb_retrieveliste from commandbutton within w__tablesql_dyn integer x = 2551 integer y = 292 integer width = 526 integer height = 92 integer taborder = 40 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string text = "C&harger la liste" end type event clicked;/**********************************************************************************************/ /* Nom : clicked cb_retrieveliste */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ setpointer(hourglass!) dw_liste.retrieve() st_liste.text = string(dw_liste.rowcount()) + ' ligne(s)' end event type dw_liste from datawindow within w__tablesql_dyn integer x = 14 integer y = 44 integer width = 2519 integer height = 1816 integer taborder = 10 boolean hscrollbar = true boolean vscrollbar = true boolean livescroll = true borderstyle borderstyle = stylelowered! end type event rowfocuschanged;/**********************************************************************************************/ /* Nom : rowfocuschanged */ /* But : */ /* Arguments: */ /* Appel : */ /* Remarques: */ /* Histo : SKA - fev 2005 */ /**********************************************************************************************/ if currentrow > 0 then this.selectrow(0,false) this.selectrow(currentrow,true) end if end event type gb_liste from groupbox within w__tablesql_dyn integer x = 2533 integer y = 16 integer width = 571 integer height = 1844 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" long textcolor = 16711680 long backcolor = 31909606 borderstyle borderstyle = styleraised! end type
Hors ligne
ah super idée je te rajouterai bien 50 pépites pour ca mais bon ... c'est pas moi le banquier
Hors ligne
voila...
il suffit de faire un open(w__tablesql_dyn)
et la...suivez les etapes...
comme vous pouvez le voir, vous pouvez faire un "select * from ..."
apres, il suffit de faire un Retrieve... ou de filtrer suivant le resultat que vous voulez obtenir...
et ensuite enregistrez sous un format proposé...
j'ai fait des tests sur Sybase, et SqlAnywhere 5.0
si certaines personnes peuvent le faire sous un autre SGBD, histoire de voir ce que ca donne...
merci merci
Hors ligne
correction faite pour le fichier "w__requete_sql_dyn.srw"
je ne sais pour quel raison, ca plantait... un mauvais copier-coller....
Hors ligne
Autre correction faite pour ces fichiers d'imports...
et voila, ouf !
Hors ligne
petite precision...
Ce module SQL se sert de la transaction SQLCA de votre appli... s'il n'y a pas de bases de données, ca ne marchera pas...
PS: Ce module SQL sera imbriqué dans l'outil Find Pick...
Hors ligne
super ça marche en pb 10 et sous informix
il est trop fort super Pick
Hors ligne
Tests effectués sous Oracle 8i en PB6.5.
Ca marche nickel m'sieur Pick
Hors ligne
Pages: 1