#include "apdefap.h"
void OnOpenPicture(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
#define GetObject GetObject
__object *pdl=NULL;
__object *pic=NULL;
__object *obj=NULL;
int iRecordCount;
long Charge;
BOOL bintern;
extern __object *gcn, *grsDaten;
char strSQLStatement[900];
char sType[50];
char sNummer[150];
int n=0;
bintern = TRUE;
pdl = __object_create("PDLRuntime");
pic=pdl->GetPicture(lpszPictureName);
obj=pic->GetObject("Kombinationsfeld1");
obj->NumberLines=0;
    if (gcn->State==0)
    {
    printf("Connection Failed.  Reconnecting\r\n");
    if (ConnectToDB () == 0)
    bintern=TRUE;
    else
    bintern=FALSE;
    
      return;
    }   
printf (gcn->State);
    
    if (bintern)
    {
    grsDaten = __object_create("ADODB.RecordSet");
        
    // runs a SELECT statement against the connection object to populate the recordset object
    // there are several ways to do this and I have chosen this one because it allows me to define a dynamic recordset
    // which means that I can navigate through the results and also return the record count.
    sprintf(strSQLStatement, "SELECT Mischernummer,Bezeichnung FROM Mischungen ORDER BY Mischernummer");
     grsDaten->CursorLocation = 3;
    grsDaten->Open(strSQLStatement, gcn,1,3);
            
    // outputs how many rows were returned from the above query
        iRecordCount = grsDaten->RecordCount();
                  //  printf("Mischungen: iRecordCount: %d \r\n", iRecordCount);
n = 0;
//Cycle through recordset and add item to combobox.
while (!grsDaten->eof)
{
n++;
strcpy(sNummer,(char *)grsDaten->Fields(0));
strcpy(sType,(char *)grsDaten->Fields(1));
strcat(sNummer," ");
// Index selektieren
obj->NumberLines=n;
obj->AddItem(n,strcat(sNummer,sType));
 
grsDaten->Movenext;
}
    grsDaten->Close;
__object_delete(grsDaten);
    }
__object_delete(obj);
__object_delete(pic);
__object_delete(pdl);
}