/******************************************* Module DBdisplay Editor Version: 1.0 Author: Thierry LEFORT Last update: 06/22/2001 *******************************************/ typeof ed = Editor ;; typeof font = ObjFont ;; typeof EditorWin = ObjWin ;; typeof RealWin = ObjWin ;; typeof VirtualWin = ObjWin ;; typeof Alias = S ;; /*ODBC variables*/ typeof lastODBCAlias = S ;; typeof Login = S ;; typeof Password = S ;; typeof db= SqlDB ;; /*Data Base*/ typeof table = S ;; /*Labels*/ typeof AliasTexte = ObjText ;; typeof AliasEditTexte = ObjText ;; /*typeof LoginTexte = ObjText ;;*/ typeof TableTexte = ObjText ;; typeof SqlLabel = ObjText ;; typeof SqlReq = ObjText ;; typeof labelEvent = ObjText ;; typeof labelListe = ObjText ;; typeof labelAttributs = ObjText ;; typeof check = ObjCheck ;; typeof comboBox = ObjBox;; typeof comboBoxAttrEvent = ObjBox;; typeof comboBoxAttrListe = ObjBox;; typeof TableModifButtn = ObjButton ;; typeof OdbcModifButtn = ObjButton ;; typeof testBtn = ObjButton ;; typeof ConnectBtn = ObjButton ;; typeof ListeAttrTable = [[S r1] r1];; typeof attrToDisplay = [[ObjBox ObjText ObjText ObjText ObjText] r1];; var OnOff = 1;; fun testDB ()= let SqlCod db ->Result in if Result == SQL_ERROR then let SqlDescErr db -> [etat native message lignes] in _DLGMessageBox _channel EditorWin (_locEditor "DB_ERROR" nil) message 0 else if Result == SQL_NO_DATA then _DLGMessageBox _channel EditorWin (_locEditor "DB_NODATA" nil) (_locEditor "DB_NODATA" nil) 0 else _DLGMessageBox _channel EditorWin (_locEditor "DB_SUCCESS" nil) (_locEditor "DB_SUCCESS" nil) 0 ;; fun fill_combo(combo, list, ind)= if list == nil then 0 else ( fill_combo (_ADDcombo combo 1 hd hd list ) (tl list) (ind+1); 1 ) ;; fun _closeDBPopUp( win, param)= set OnOff = 1; _DSwindow win ;; fun getVirtualCombo(liste) = if liste==nil then nil else let hd liste -> tete in let tete -> [cbo _ _ _ _] in let _GETcombo cbo -> [_ texte] in if !strcmp texte (_locEditor "DB_VIDE" nil) then getVirtualCombo tl liste else texte::getVirtualCombo tl liste ;; fun getVirtualTexte(liste) = if liste==nil then nil else let hd liste -> tete in let tete -> [_ _ Otext _ _] in let _GETtext Otext -> texte in if !strcmp texte "" then getVirtualTexte tl liste else texte::getVirtualTexte tl liste ;; fun getVirtualPrec (liste)= if liste==nil then nil else let hd liste -> tete in let tete -> [cbo _ _ _ Otext] in let _GETtext Otext -> texte in let _GETcombo cbo -> [_ table] in if (!strcmp texte (_locEditor "DB_NOPREC" nil)) || (!strcmp table (_locEditor "DB_VIDE" nil)) then getVirtualPrec tl liste else (table::texte::nil)::getVirtualPrec tl liste ;; fun getTheCbo (liste, texte) = if liste ==nil then nil else let hd liste -> [cbo _ _ _ Otext] in let _GETcombo cbo -> [_ TextToCmp] in if !strcmp TextToCmp texte then Otext else getTheCbo tl liste texte ;; fun setVirtualPrec (liste, listeElem)= if listeElem==nil then nil else let hd tl hd listeElem -> elem in let hd hd listeElem -> cboElem in if elem == nil then ( setVirtualPrec liste tl listeElem; 0 ) else ( let getTheCbo liste cboElem -> tempTxt in if tempTxt != nil then ( _SETtext tempTxt elem; setVirtualPrec liste tl listeElem; 1 ) else ( 0 ) ) ;; fun setVirtualCombo(liste, listeElem) = if liste==nil then nil else let hd liste -> tete in let hd listeElem -> elem in let tete -> [cbo _ _ _ _] in if elem ==nil then ( _SSELcombo cbo (_locEditor "DB_VIDE" nil); setVirtualCombo tl liste tl listeElem; 0 ) else ( _SSELcombo cbo elem; setVirtualCombo tl liste tl listeElem; 1 ) ;; fun setVirtualTexte(liste, listeElem) = if liste==nil then nil else let hd liste -> tete in let hd listeElem -> elem in let tete -> [_ _ Otext _ _] in if elem ==nil then ( _SETtext Otext (_locEditor "DB_VIDE" nil); setVirtualTexte tl liste tl listeElem; 0 ) else ( _SETtext Otext elem; setVirtualTexte tl liste tl listeElem; 1 ) ;; fun cleanVWin (liste) = if liste==nil then 1 else let hd liste -> tete in let tete -> [cbo txt etxt ltxt ptxt] in ( _DScombo cbo; _DStext txt; _DStext etxt; _DStext ltxt; _DStext ptxt; cleanVWin tl liste ) ;; fun list_attr_to_string(list, param)= if list == nil then nil else if (listlength list) == 1 then strcatn param::(hd list)::nil else strcatn param::(hd list)::", "::(list_attr_to_string tl list param)::nil ;; /*************************************************************************** Renvoie le login ou le password d'une base de donnees, on specifie l'alias dans odbcAlias, l'info que l'on souhaite reccueillir dans info ("login" ou "password") les valeurs sont recuperees dans usmress.ini format : odbc.odbcAlias.login odbc.odbcAlias.password attention : odbcAlias, infos ne doivent pas contenir les caracteres suivants : ".*?" ****************************************************************************/ fun GetODBCInfos(odbcAlias,info)= hd switchstr strextr _loadressini strcatn "odbc."::odbcAlias::"."::info::nil ;; fun mkSqlReq() = let _GETcombo comboBox -> [_ table] in let _GETcombo comboBoxAttrListe -> [_ AttrListe] in let _GETcombo comboBoxAttrEvent -> [_ AttrEvent] in let AttrListe::AttrEvent::(getVirtualCombo attrToDisplay) -> list_Attr in let if (_GETcheck check) then "SELECT DISTINCT " else "SELECT " -> tmp in strcatn tmp::(list_attr_to_string list_Attr (strcatn " "::table::"."::nil))::" FROM "::table::nil ;; fun cbVirtualCombo(combo, param, ind, texte) = _SETtext SqlLabel mkSqlReq ;; fun fillVirtualWIN (liste, listeCombo, Xstart, Ystart, Width)= if liste ==nil then nil else let _CRcombo _channel VirtualWin Xstart Ystart Width/5 200 CB_NOEDIT|CB_AHSCROLL|CB_DOWN "" -> cbo in let _CRtext _channel VirtualWin Xstart+Width/5 Ystart Width/18 20 ET_ALIGN_RIGHT (_locEditor "DB_NAMEC" nil) -> label in let _CReditLine _channel VirtualWin Xstart+23*Width/90 Ystart (13*Width/30) 20 ET_BORDER|ET_TABFOCUS "" -> editL in let _CRtext _channel VirtualWin Xstart+31*Width/45 Ystart Width/10 20 ET_ALIGN_RIGHT (_locEditor "DB_SUBSTR" nil) -> labelP in let _CReditLine _channel VirtualWin Xstart+71*Width/90 Ystart (7*Width/30) 20 ET_BORDER|ET_TABFOCUS (_locEditor "DB_NOPREC" nil) -> editP in ( _CBcombo cbo @cbVirtualCombo nil; fill_combo cbo ((_locEditor "DB_VIDE" nil)::nil)::listeCombo 1; _SSELcombo cbo (_locEditor "DB_VIDE" nil); [cbo label editL labelP editP]::(fillVirtualWIN tl liste listeCombo Xstart Ystart+22 Width) ) ;; fun _comboTable (combo, param, ind, texte) = _RSTcombo comboBoxAttrListe; _RSTcombo comboBoxAttrEvent; cleanVWin attrToDisplay; set ListeAttrTable = SqlRequest db "GET_COLUMNS" (SQL_NIL texte)::nil; set attrToDisplay = fillVirtualWIN ListeAttrTable ListeAttrTable 5 5 700; _PAINTwindow _SHOWwindow VirtualWin WINDOW_UNHIDDEN; _PAINTwindow _SHOWwindow RealWin WINDOW_UNHIDDEN; fill_combo comboBoxAttrEvent ListeAttrTable 1; _ENcombo comboBoxAttrEvent 1; fill_combo comboBoxAttrListe ListeAttrTable 1; _ENcombo comboBoxAttrListe 1; _SETtext SqlLabel mkSqlReq ;; /*CallBack for DLGmessagebox DBsuccess*/ fun _dbconnect (msgBox, param, ok) = let param -> [tmpAlias tmpLogin tmpPassword win] in ( set Alias = tmpAlias; set Login = tmpLogin; set Password = tmpPassword; fill_combo comboBox SqlRequest db "GET_TABLES" nil 1; _ENcombo comboBox 1; _PAINTcombo _SHOWcombo comboBox WINDOW_UNHIDDEN ) ;; fun connectionDB (aliasDB, loginDB, pwdDB)= let if aliasDB ==nil then "" else aliasDB -> al in if strcmp lastODBCAlias al then ( let if loginDB ==nil then "" else loginDB -> lo in let if pwdDB ==nil then "" else pwdDB -> pwd in let SqlCreate _channel al lo pwd -> dbtmp in if dbtmp != nil then /*DB success*/ ( set db = dbtmp; _DLGrflmessage _DLGMessageBox _channel EditorWin (_locEditor "WINDOW_NAME_DBCONNECT" nil) (_locEditor "DBCONNECT_SUCCESS" nil) 0 @_dbconnect [al lo pwd EditorWin]; 0 ) else /*DB failed*/ ( _DLGMessageBox _channel EditorWin (_locEditor "WINDOW_NAME_DBCONNECT" nil) (_locEditor "DBCONNECT_FAILURE" nil) 0; 0 ); set lastODBCAlias = al; 1 ) else 0 ;; fun cbConnect (btn, param) = let _GETtext param -> tmpAlias in let GetODBCInfos tmpAlias "login" -> tmpLogin in let GetODBCInfos tmpAlias "password" -> tmpPwd in connectionDB tmpAlias tmpLogin tmpPwd ;; fun _OdbcOk(Otext, param, truc)= let _GETtext Otext -> tmpAlias in let GetODBCInfos tmpAlias "login" -> tmpLogin in let GetODBCInfos tmpAlias "password" -> tmpPwd in connectionDB tmpAlias tmpLogin tmpPwd ;; fun cbCbo (combo, param, xi, yi)= _SETtext SqlLabel mkSqlReq ;; fun cbCheck(check, param, state)= _SETtext SqlLabel mkSqlReq ;; fun cbTest(btn, param)= let _GETtext SqlLabel -> debut in let _GETtext SqlReq -> fin in SqlRequest db strcatn debut::" "::fin::nil nil; testDB ;; fun cbLoad(list)= _SETtext AliasEditTexte set Alias = (getInfo list "alias"); set lastODBCAlias = Alias; set Login= GetODBCInfos Alias "login"; set Password = GetODBCInfos Alias "password"; set table = (getInfo list "table"); if Alias==nil then ( /*DB_Connect_PopUp EditorWin "" "" ""*/ 0 ) else ( let SqlCreate _channel Alias (if !strcmp Login nil then "" else Login) (if !strcmp Password nil then "" else Password) -> dbtmp in if dbtmp != nil then /*DB success*/ ( set db = dbtmp; let SqlRequest db "GET_TABLES" nil -> tmp in fill_combo comboBox tmp 1; 0 ) else /*DB failed*/ ( _DLGMessageBox _channel EditorWin (_locEditor "WINDOW_NAME_DBCONNECT" nil) (_locEditor "DBCONNECT_FAILURE" nil) 0; 0 ); set ListeAttrTable = SqlRequest db "GET_COLUMNS" (SQL_NIL table)::nil; set attrToDisplay = fillVirtualWIN ListeAttrTable ListeAttrTable 5 5 700; fill_combo comboBoxAttrEvent ListeAttrTable 1; fill_combo comboBoxAttrListe ListeAttrTable 1; _ENcombo comboBoxAttrListe 1; _ENcombo comboBoxAttrEvent 1; _ENcombo comboBox 1; _SSELcombo comboBox table; _SSELcombo comboBoxAttrListe (getInfo list "AttrListe"); _SSELcombo comboBoxAttrEvent (getInfo list "AttrEvent"); setVirtualCombo attrToDisplay lineextr (getInfo list "ListeCombo"); setVirtualTexte attrToDisplay lineextr (getInfo list "ListeName"); setVirtualPrec attrToDisplay strextr (getInfo list "listePrec"); _SETtext SqlLabel (getInfo list "SQLlabel"); _SETtext SqlReq (getInfo list "SQLfin"); _SETcheck check atoi hd hd strextr (getInfo list "check"); 0 ); 0;; fun cbSave (filename, n)= let _GETtext SqlLabel -> SQLText in let _GETtext SqlReq -> FINSQL in let _GETtext AliasEditTexte -> AliasDB in let _GETcombo comboBoxAttrListe -> [_ AttrListe] in let _GETcombo comboBoxAttrEvent -> [_ AttrEvent] in let _GETcombo comboBox -> [_ table] in let itoa _GETcheck check -> tmp in ("action"::"start"::"start"::nil):: ("action"::"show.user"::nil):: ("action"::"show.admin"::nil):: ("actionC"::"hide"::nil):: ("actionC"::"clickOnProductInList"::nil):: ("actionC"::"clickOnProductInShelves"::nil):: ("actionC"::"doubleClickOnProductInShelves"::nil):: ("actionC"::"doubleClickOnProductInList"::nil):: ("eventC"::"in"::nil):: ("eventC"::"out"::nil):: ("eventC"::"clickOnProductInList"::nil):: ("eventC"::"doubleClickOnProductInList"::nil):: ("event"::"pushDblclickOnProductInList"::nil):: ("event"::"pushClickOnProductInList"::nil):: ("zoneC"::"DBDisplay"::nil):: ("alias":: AliasDB ::nil):: ("table":: table ::nil):: ("AttrListe":: AttrListe ::nil):: ("AttrEvent":: AttrEvent ::nil):: ("ListeName":: (linebuild getVirtualTexte attrToDisplay) ::nil):: ("ListeCombo":: (linebuild getVirtualCombo attrToDisplay) ::nil):: ("listePrec":: (strbuild getVirtualPrec attrToDisplay)::nil):: ("SQLfin":: FINSQL::nil):: ("SQLlabel":: SQLText::nil):: ("check":: tmp::nil):: nil;; /*Callbacks pour la gestion des évènements graphique*/ fun cbReSize (win, param, Wt, Ht)= let 10 -> step in let 20 -> Tstep in let 50 -> Lbtn in let (Wt/2)-3*step/2-Lbtn -> endlabel in let Wt/2-2*step -> Llabel in let Ht-5*step-5*Tstep -> Hlist in let 80 -> LabelSQL in ( /*DB alias*/ _SIZEtext AliasTexte 100 2*Tstep step step+5; _SIZEtext AliasEditTexte Wt/2-(2*step+175) Tstep step+100 step+10; _SIZEbutton ConnectBtn 70 Tstep step+90+ Wt/2-(2*step+160) step+10; /*DB Table*/ _SIZEtext TableTexte Lbtn Tstep*2 2*step+endlabel+Lbtn step+Tstep/2 ; /*Modif DB access*/ _SIZEbutton OdbcModifButtn Lbtn Tstep step+endlabel step+Tstep/2 ; /*Modif DB Table*/ _SIZEcombo comboBox Wt-(2*step+endlabel+2*Lbtn)-step 500 2*step+endlabel+2*Lbtn step+Tstep/2; /*Attribut Liste*/ _SIZEtext labelListe Llabel Tstep step 15+2*Tstep ; _SIZEcombo comboBoxAttrListe Llabel 500 step 15+3*Tstep; /*Attribut des évènements click, DblCick et de push*/ _SIZEtext labelEvent Llabel Tstep step+Wt/2 15+2*Tstep ; _SIZEcombo comboBoxAttrEvent Llabel 500 step+Wt/2 15+3*Tstep; _SIZEtext labelAttributs Wt-2*step Tstep-5 step 25+4*Tstep; _SIZEwindow RealWin Wt-4*step Ht-(35+5*Tstep)-5*Tstep-step step (25+5*Tstep); _SIZEcheck check 120 Tstep step Ht-5*Tstep+step/2 ; _SIZEbutton testBtn Lbtn Tstep Wt-step-Lbtn Ht-Tstep-step; _SIZEtext SqlLabel Wt-2*step 2*Tstep step Ht-3*Tstep-step; _SIZEtext SqlReq Wt-3*step-Lbtn Tstep step Ht-Tstep-step ) ;; fun cbPro () = let BigToAsc BigInvn BigFromAsc _getpack _checkpack "dms/db/dbdisplay/dbdisplay.conf" BigFromAsc "db06414e70b5249d" -> s in let if (strlen s)!=9 then nil else [htoi substr s 1 4 htoi substr s 5 4] -> [datedebut periode] in if periode==nil then (_DLGMessageBox _channel nil _locEditor "PRO_WARNING" nil _locEditor "PRO_INVALID_MSG" nil 0;0) else if periode==0 then 1 else let ((time>>1)&0x3fffffff)/43200-datedebut -> x in if x<0 then (_DLGMessageBox _channel nil _locEditor "PRO_WARNING" nil _locEditor "PRO_INVALID_MSG" nil 0;0) else if x<=periode then (_DLGMessageBox _channel nil _locEditor "PRO_WARNING" nil _locEditor "PRO_LIMITED_MSG" (itoa (periode-x))::nil 0;1) else (_DLGMessageBox _channel nil _locEditor "PRO_WARNING" nil _locEditor "PRO_ENDLIMITED_MSG" nil 0;0) ;; fun CreateApi(filename)= set font = _CRfont _channel 14 0 FF_WEIGHT "Arial"; set ed = _StartEditor _channel nil 0 0 800 600 WN_NORMAL EDITOR_NORMAL @cbLoad @cbSave @cbPro; set EditorWin = getEditWin ed ; let _GETwindowSizePosition EditorWin -> [Wt Ht _ _] in let 10 -> step in let 20 -> Tstep in let 50 -> Lbtn in let (Wt/2)-3*step/2-Lbtn -> endlabel in let Wt/2-2*step -> Llabel in let Ht-5*step-5*Tstep -> Hlist in let 80 -> LabelSQL in ( /*DB alias*/ set AliasTexte = _CRtext _channel EditorWin step step+5 100 2*Tstep ET_ALIGN_LEFT (_locEditor "DB_ALIAS" nil); set AliasEditTexte = _CReditLine _channel EditorWin step+100 step+10 Wt/2-(2*step+175) Tstep ET_BORDER|ET_TABFOCUS|ET_AHSCROLL ""; _CBlineOk AliasEditTexte @_OdbcOk []; set ConnectBtn = _CRbutton _channel EditorWin step+90+ Wt/2-(2*step+160) step+10 70 Tstep 0 (_locEditor "DB_CONECTION" nil); _CBbutton ConnectBtn @cbConnect AliasEditTexte; /*DB Table*/ set TableTexte = _CRtext _channel EditorWin 2*step+endlabel+Lbtn step+Tstep/2 Lbtn Tstep*2 ET_ALIGN_LEFT (_locEditor "DB_TABLE" nil); /*Modif DB Table*/ _ENcombo set comboBox = _CBcombo _CRcombo _channel EditorWin 2*step+endlabel+2*Lbtn step+Tstep/2 Wt-(2*step+endlabel+2*Lbtn)-step 500 CB_NOEDIT|CB_AHSCROLL|CB_DOWN "" @_comboTable nil 0; /*Attribut Liste*/ set labelListe= _CRtext _channel EditorWin step 15+2*Tstep Llabel Tstep ET_ALIGN_LEFT (_locEditor "DB_ATTRLISTE" nil); _ENcombo set comboBoxAttrListe = _CBcombo _CRcombo _channel EditorWin step 15+3*Tstep Llabel 500 CB_NOEDIT|CB_AHSCROLL|CB_DOWN "" @cbCbo nil 0; /*Attribut des évènements click, DblCick et de push*/ set labelEvent = _CRtext _channel EditorWin step+Wt/2 15+2*Tstep Llabel Tstep ET_ALIGN_LEFT (_locEditor "DB_ATTREVENT" nil); _ENcombo set comboBoxAttrEvent = _CBcombo _CRcombo _channel EditorWin step+Wt/2 15+3*Tstep Llabel 500 CB_NOEDIT|CB_AHSCROLL|CB_DOWN "" @cbCbo nil 0; set labelAttributs = _CRtext _channel EditorWin step 25+4*Tstep Wt-2*step Tstep-5 ET_ALIGN_LEFT (_locEditor "DB_ATTRIBUTS" nil); let _CRscrollWindow _channel EditorWin 2*step (25+5*Tstep)*2 Wt-2*step Ht-(35+5*Tstep)-4*Tstep-step Wt-2*step 1200 WN_CHILDINSIDE|WN_VSCROLL|WN_HSCROLL|WN_DOWN "" -> [RW VW] in ( set RealWin = RW; set VirtualWin = VW ); _CBcheck set check = _CRcheck _channel EditorWin step Ht-5*Tstep+step/2 300 Tstep 0 (_locEditor "SEL_DISTINCT" nil) @cbCheck nil; _CBbutton set testBtn = _CRbutton _channel EditorWin Wt-step-Lbtn Ht-Tstep-step Lbtn Tstep 0 "Test" @cbTest nil; set SqlLabel = _CRtext _channel EditorWin step Ht-3*Tstep-step Wt-2*step 2*Tstep ET_ALIGN_LEFT (_locEditor "DB_SQL_LABEL" nil); set SqlReq = _CReditLine _channel EditorWin step Ht-Tstep-step Wt-3*step-Lbtn Tstep ET_BORDER|ET_TABFOCUS|ET_AHSCROLL ""; _CBwinSize EditorWin @cbReSize nil ); 1 ;; fun IniEditor(filename)= CreateApi filename; if filename==nil then nil else openDMI ed; 0 ;;