Solved

Need some help with ListView and dispaly

Posted on 2011-03-15
7
526 Views
Last Modified: 2013-11-20
"the code is okay...everything works wine.....just the display delay"



Hello,
I need some help with my ListView.
Below is the code how I read the sql table and set the data to my ListView m_List1

Because of the big  size of the data I will get the a display like my the pictures I have enclosed.
Can I change that....so the user sees the empty ListView with all rows....and if I have all data read....
the data should be displayed in a second in my ListView.

I hope you understand my question.
500 points with a solution.
Best regards,
Thomas






void CLieferscheine_Dialog::Lieferscheine_lesen(void)
{
      
      //SQL Server
      m_strConnection = _T("Driver={SQL Server}; Server=DSERVER; Database=OMSDATEN;Uid=;Pwd;");
      
      CString sql;
      
       //-----------------------------------------------------------------------------------------------------------
      //Initialize the Recordset and binding pointers
      m_ptrRs = NULL;  
    m_piAdoRecordBinding = NULL;  

      //Initialize the COM environment
      ::CoInitialize(NULL);
      try
      {
            //Create the recordset object
            m_ptrRs.CreateInstance(__uuidof(Recordset));  
                
//-------------------------- Suche einzelnen Auftrag vom Hauptmenu -------------------------
            //ohne Typ 50 ... bei Benteler die Verpackung
CString str_suche_Jahr="2011";

      sql.Format("SELECT * FROM ViewLieferscheine WHERE LieferscheinNr<%d\
        AND DATEPART(Year,Lieferscheindatum)='%s'\
        ORDER BY LieferscheinNr,Lieferscheindatum DESC",2000000,str_suche_Jahr);
                           //------------------------------------------------------------------------------------------

    _bstr_t bstrQuery(sql);
 
//Open the recordset object Tabelle
 m_ptrRs->Open(_variant_t(bstrQuery),(LPCTSTR)m_strConnection, adOpenDynamic, adLockOptimistic, adCmdUnknown);


//Get a pointer to the record-binding interface Coils
if(FAILED(m_ptrRs->QueryInterface(__uuidof(IADORecordBinding),(LPVOID *)&m_piAdoRecordBinding)))     _com_issue_error(E_NOINTERFACE);
 
            //Bind the record class to the recordset
      //      m_piAdoRecordBinding->BindToRecordset(&m_rsRecSet);  auf REM setzen wichtig  
      
      
                   //***************************************************************************
      
        _variant_t Holder_LieferscheinNr;
        _variant_t Holder_Name1;
        _variant_t Holder_Name2;
        _variant_t Holder_StrassePostfach;
        _variant_t Holder_Ort;
                 _variant_t Holder_Land;
        _variant_t Holder_KundenNr;
        _variant_t Holder_Lieferbedingung_Nr;
        _variant_t Holder_Lieferbedingung_Bezeichnung;
        _variant_t Holder_Lieferscheindatum;
        _variant_t Holder_Sachbearbeiter;
                 _variant_t Holder_Postleitzahl;
      
        int Holder_Gewicht;
        bool Holder_Fakturiert;

                 CString str_LieferscheinNr;
        CString str_Name1;    
        CString str_Name2;  
                  CString str_Ort;
                  CString str_Land;
        CString str_StrassePostfach;
        CString str_KDNr;    
        CString str_Lieferbedingung_Nr;
        CString str_Lieferbedingung_Bezeichnung;
        CString str_Lieferscheindatum;
        CString str_Postleitzahl;
        CString str_Sachbearbeiter;
        CString str_Fakturiert;
        CString str_Gewicht;

      
          

              int Spalte =1;
             int hoechstes_Jahr=0;
             int Zeile=0;


             
             
          if(m_ptrRs->BOF) goto Ende_der_while_Schleife;
       
             //-------------------------------- Lese Datei ------------------------------------
             m_ptrRs->MoveFirst();
       
            while(!m_ptrRs->EndOfFile)
                     {
                Holder_LieferscheinNr              = m_ptrRs->GetCollect("LieferscheinNr");
      Holder_Name1                         = m_ptrRs->GetCollect("VersandName1");
      Holder_Name2                            = m_ptrRs->GetCollect("VersandName2");
      Holder_StrassePostfach                 = m_ptrRs->GetCollect("VersandStrassePostfach");
      Holder_Postleitzahl                              = m_ptrRs->GetCollect("VersandPostleitzahl");
      Holder_Ort                                            = m_ptrRs->GetCollect("VersandOrt");
      Holder_Land                                            = m_ptrRs->GetCollect("VersandLand");
      Holder_KundenNr                                      = m_ptrRs->GetCollect("DebitorenNr");
                Holder_Lieferscheindatum                         = m_ptrRs->GetCollect("Lieferscheindatum");
      Holder_Lieferbedingung_Nr                         = m_ptrRs->GetCollect("Lieferbedingung");
      Holder_Lieferbedingung_Bezeichnung          = m_ptrRs->GetCollect("TextbausteinD");
                Holder_Fakturiert                                          = m_ptrRs->GetCollect("Fakturiert");
                Holder_Gewicht                                              = m_ptrRs->GetCollect("Gewicht");
      Holder_Sachbearbeiter                                   = m_ptrRs->GetCollect("Sachbearbeiter");
                              

             //----------- Copy _variant_t into CString ----------ABNr
             if(Holder_LieferscheinNr.vt!=VT_NULL)
                  {
                        str_LieferscheinNr=(LPCSTR)(_bstr_t)Holder_LieferscheinNr.bstrVal;
                        str_LieferscheinNr.TrimRight();
                        m_LiefNr=str_LieferscheinNr;
                  }
                  else
                  {
                        str_LieferscheinNr.Empty();
                  }
      //----------- Copy _variant_t into CString ----------Name1
             if(Holder_Name1.vt!=VT_NULL)
      {
      str_Name1=(LPCSTR)(_bstr_t)Holder_Name1.bstrVal;
      str_Name1.TrimRight();
                  }
                  else
                  {
                        str_Name1.Empty();
                  }
                   //----------- Copy _variant_t into CString ----------Name2
             if(Holder_Name2.vt!=VT_NULL)
                  {
                        str_Name2=(LPCSTR)(_bstr_t)Holder_Name2.bstrVal;
                        str_Name2.TrimRight();
                  }
                  else
                  {
                        str_Name2.Empty();
                  }

                  //if(str_Name2!="") str_Name=str_Name+", "+str_Name2;
      
                   //----------- Copy _variant_t into CString ----------StrassePostfach
             if(Holder_StrassePostfach.vt!=VT_NULL)
                  {
                        str_StrassePostfach=(LPCSTR)(_bstr_t)Holder_StrassePostfach.bstrVal;
                        str_StrassePostfach.TrimRight();
                  }
                  else
                  {
                        str_StrassePostfach.Empty();
                  }
                   //----------- Copy _variant_t into CString ----------Ort
                if(Holder_Ort.vt!=VT_NULL)
                  {
                        str_Ort=(LPCSTR)(_bstr_t)Holder_Ort.bstrVal;
                        str_Ort.TrimRight();
                  }
                  else
                  {
                        str_Ort.Empty();
                  }
                   //----------- Copy _variant_t into CString ----------PLZ
                if(Holder_Postleitzahl.vt!=VT_NULL)
                  {
                        str_Postleitzahl=(LPCSTR)(_bstr_t)Holder_Postleitzahl.bstrVal;
                        str_Postleitzahl.TrimRight();
                  }
                  else
                  {
                        str_Postleitzahl.Empty();
                  }
                  //----------- Copy _variant_t into CString ----------Land
                if(Holder_Land.vt!=VT_NULL)
                  {
                        str_Land=(LPCSTR)(_bstr_t)Holder_Land.bstrVal;
                        str_Land.TrimRight();
                  }
                  else
                  {
                        str_Land.Empty();
                  }
            //      if(str_Land!="")str_Ort=str_Ort+" / "+str_Land;

               //----------- Copy _variant_t into CString ----------Kd-Nr.
                if(Holder_KundenNr.vt!=VT_NULL)
                  {
                        str_KDNr=(LPCSTR)(_bstr_t)Holder_KundenNr.bstrVal;
                str_KDNr.TrimRight();
                  }
                   else
                   {
                         str_KDNr.Empty();
                  }
                  //----------- Copy _variant_t into CString ----------Lieferbedingung_Nr
             if( Holder_Lieferbedingung_Nr.vt!=VT_NULL)
                  {
                        str_Lieferbedingung_Nr=(LPCSTR)(_bstr_t) Holder_Lieferbedingung_Nr.bstrVal;
                        str_Lieferbedingung_Nr.TrimRight();
                  }
                  else
                  {
                        str_Lieferbedingung_Nr.Empty();
                  }
                  //----------- Copy _variant_t into CString ----------Lieferbedingung_Bezeichnung
             if( Holder_Lieferbedingung_Bezeichnung.vt!=VT_NULL)
                  {
                        str_Lieferbedingung_Bezeichnung=(LPCSTR)(_bstr_t) Holder_Lieferbedingung_Bezeichnung.bstrVal;
                        str_Lieferbedingung_Bezeichnung.TrimRight();
                  }
                  else
                  {
                        str_Lieferbedingung_Bezeichnung.Empty();
                  }

                  str_Lieferbedingung_Bezeichnung="("+str_Lieferbedingung_Nr+") "+str_Lieferbedingung_Bezeichnung;
                  //----------- Copy _variant_t into CString ----------Sachbearbeiter
             if( Holder_Sachbearbeiter.vt!=VT_NULL)
                  {
                        str_Sachbearbeiter=(LPCSTR)(_bstr_t) Holder_Sachbearbeiter.bstrVal;
                        str_Sachbearbeiter.TrimRight();
                  }
                  else
                  {
                        str_Sachbearbeiter.Empty();
                  }
                  //------------------------------------------------------- Lieferscheindatum
             
                  if (Holder_Lieferscheindatum.vt!=VT_NULL)
                  {
                str_Lieferscheindatum=( COleDateTime(Holder_Lieferscheindatum.date).Format(_T("%d.%m.%y") ) )  ;
                  }
           //------------------------------------------------------- Fakturiet
           if(Holder_Fakturiert==false) str_Fakturiert="nein";
           if(Holder_Fakturiert==true)  str_Fakturiert="ja";
            //-------------------------------------------------------Gewicht
            str_Gewicht.Format("%d",Holder_Gewicht);
                  str_Gewicht=FormatString(str_Gewicht);//Funktion
             
            
                                                 //----------------------------- Listenelement ------------------------------------
                         m_List1.InsertItem(Zeile,str_LieferscheinNr);  
                     m_List1.SetItemText(Zeile,1,str_Lieferscheindatum);
                               m_List1.SetItemText(Zeile,2,str_Name1);
                     m_List1.SetItemText(Zeile,3,str_KDNr);
                     m_List1.SetItemText(Zeile,4,str_Gewicht);
                     m_List1.SetItemText(Zeile,5,str_Lieferbedingung_Bezeichnung);
                     m_List1.SetItemText(Zeile,6,str_Fakturiert);
                                                   m_List1.SetItemText(Zeile,7,str_Sachbearbeiter);
                  
                                                  //------------------------------------------------------------------------------------
                                    

                                             //Verhindert Error-Meldung BOF / EOF
                  if(m_ptrRs->EndOfFile)break;

                    //nächste Zeile
                    Zeile=Zeile+1;
                    
                    m_ptrRs->MoveNext();

           
            }
        //----------------------------------------------------------------
                  
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      
             
}

//#####################################################################  
            //---------- Any erros? -------------
          catch (_com_error &e)
            {
                  //Display the error
                  CString x=m_LiefNr;
              GenerateError(e.Error(), e.Description());
            }
            //-----------------------------------
      Ende_der_while_Schleife:
      
     

      //***************************************************************************
               

       //Close the recordset
      if(m_ptrRs)  m_ptrRs->Close();    //StatistikMetallwaren
      

      // Do we have a valid pointer to the record binding?
      if(m_piAdoRecordBinding) m_piAdoRecordBinding->Release();      //StatistikMetallwaren
      
      //Set the recordset pointer to NULL
      m_ptrRs = NULL;    //StatistikMetallwaren
      
      //Shut down the COM environment
      ::CoUninitialize();


 
}

1.BMP
0
Comment
Question by:tsp2002
  • 4
  • 2
7 Comments
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 250 total points
ID: 35138027
Is this a one single function? First, Can you break this into 3?

1. Connection to DB
2. Reading from DB into Recordsets
3. Adding the value into the list box

Is this code getting executed immediately while opening the application?

You could add 1 & 2 in a thread. While populating the list you could show a Wait/HourGlass (loading data..) or something similar..This way it will be little faster and won't look ugly as well
0
 

Author Comment

by:tsp2002
ID: 35138065
Is this a one single function?
Yes...a single function


First, Can you break this into 3?

I don´t now
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 35138255
Can you add some log line to capture how much time each function is taking in milli seconds?
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:tsp2002
ID: 35138765
I forgot to tell you that I use a timer in my dialog.


In CmainFrame
CLieferscheine_Dialog *pMeinDialog;
pMeinDialog = new CLieferscheine_Dialog;
pMeinDialog->mb_Kennzahl_first_show_up=true;
pMeinDialog->ShowWindow(SW_SHOW);







Meindialog.cpp
void CLieferscheine_Dialog::OnTimer(UINT nIDEvent)
{
       if(mb_Kennzahl_first_show_up==true)
       {
             //==================================
         Lieferscheine_lesen();//Aufruf von Funktion
             //==================================

              mb_Kennzahl_first_show_up=false;
       }

      CDialog::OnTimer(nIDEvent);
}




BOOL CLieferscheine_Dialog::OnInitDialog()
{
      CDialog::OnInitDialog();

//========================
      SetTimer(1,200,NULL);//   Lieferscheine_lesen();    //Funktion
//========================




I have to run now....will talk tomorrow....hopefully we will find an answer
0
 

Author Comment

by:tsp2002
ID: 35145524
void CLieferscheine_Dialog::Lieferscheine_lesen(void)
{
     
      //SQL Server
      m_strConnection = _T("Driver={SQL Server}; Server=DSERVER; Database=OMSDATEN;Uid=;Pwd;");
     
      CString sql;
     
            m_ptrRs = NULL;  
            m_piAdoRecordBinding = NULL;  

      //Initialize the COM environment
      ::CoInitialize(NULL);
      try
      {
                        m_ptrRs.CreateInstance(__uuidof(Recordset));  
               
                       CString str_suche_Jahr="2011";

                        sql.Format("SELECT * FROM ViewLieferscheine WHERE LieferscheinNr<%d\
                       AND DATEPART(Year,Lieferscheindatum)='%s'\
                       ORDER BY LieferscheinNr,Lieferscheindatum DESC",2000000,str_suche_Jahr);
                         
    _bstr_t bstrQuery(sql);
 
                   //Open the recordset object Tabelle
                  m_ptrRs->Open(_variant_t(bstrQuery),(LPCTSTR)m_strConnection, adOpenDynamic, adLockOptimistic,
                 adCmdUnknown);


                 if(FAILED(m_ptrRs->QueryInterface(__uuidof(IADORecordBinding),(LPVOID *)      
                &m_piAdoRecordBinding)))     _com_issue_error(E_NOINTERFACE);
 
              //Bind the record class to the recordset
             //  m_piAdoRecordBinding->BindToRecordset(&m_rsRecSet);  auf REM setzen wichtig  
     
     
             //***************************************************************************
           _variant_t Holder_LieferscheinNr;
           _variant_t Holder_Name1;
           .
           .
           .

           CString str_LieferscheinNr;
           CString str_Name1;    
           .
           .
           .
            int Spalte =1;
            int hoechstes_Jahr=0;
            int Zeile=0;


             
             
             if(m_ptrRs->BOF) goto Ende_der_while_Schleife;
       
             //-------------------------------- Lese Datei ------------------------------------
             m_ptrRs->MoveFirst();
       
          while(!m_ptrRs->EndOfFile)
          {
                 Holder_LieferscheinNr              = m_ptrRs->GetCollect("LieferscheinNr");
                 Holder_Name1                         = m_ptrRs->GetCollect("VersandName1");
                 .
                 .
                 .
                 .
                 Holder_Sachbearbeiter            = m_ptrRs->GetCollect("Sachbearbeiter");
             //-------------------------------------------------------------------------------------
                   

             //----------- Copy _variant_t into CString ----------
             if(Holder_LieferscheinNr.vt!=VT_NULL)
             {
                      str_LieferscheinNr=(LPCSTR)(_bstr_t)Holder_LieferscheinNr.bstrVal;
                      str_LieferscheinNr.TrimRight();
                      m_LiefNr=str_LieferscheinNr;
              }
              else
              {
                    str_LieferscheinNr.Empty();
               }
.
.
.
.
.

          //----------- Copy _variant_t into CString ----------Sachbearbeiter
          if( Holder_Sachbearbeiter.vt!=VT_NULL)
          {
                   str_Sachbearbeiter=(LPCSTR)(_bstr_t) Holder_Sachbearbeiter.bstrVal;
                   str_Sachbearbeiter.TrimRight();
          }
         else
         {
                 str_Sachbearbeiter.Empty();
         }
         //-------------------------------------------------------            
                           
     

           m_str_LieferscheinNr=str_LieferscheinNr;  
          m_str_Lieferscheindatum=str_Lieferscheindatum;
          m_str_Anschrift=str_Anschrift;
          m_str_KDNr=str_KDNr;
          m_str_Gewicht=str_Gewicht;
          m_str_Lieferbedingung_Bezeichnung=str_Lieferbedingung_Bezeichnung;
          m_str_Fakturiert=str_Fakturiert;
          m_str_Sachbearbeiter=str_Sachbearbeiter;


          //=============================
          Schreibe_Listenelement(Zeile);                        //Call Function
         //=============================





       
                //Verhindert Error-Meldung BOF / EOF
          if(m_ptrRs->EndOfFile)break;

         //nächste Zeile
        Zeile=Zeile+1;
                   
        m_ptrRs->MoveNext();

           
     }
                   
}

//#####################################################################  
            //---------- Any erros? -------------
          catch (_com_error &e)
          {
                  //Display the error
                  CString x=m_LiefNr;
                 GenerateError(e.Error(), e.Description());
           }
            //-----------------------------------
       
           Ende_der_while_Schleife:
     
     

             //Close the recordset
              if(m_ptrRs)  m_ptrRs->Close();          

            // Do we have a valid pointer to the record binding?
           if(m_piAdoRecordBinding) m_piAdoRecordBinding->Release();            
     
          //Set the recordset pointer to NULL
           m_ptrRs = NULL;          
     
         //Shut down the COM environment
          ::CoUninitialize();
}
















//------------------------------------------ New Function ----------------------------------------------
void CLieferscheine_Dialog::Schreibe_Listenelement(int Zeile)
{
          m_List1.InsertItem(Zeile,m_str_LieferscheinNr);  
         m_List1.SetItemText(Zeile,1,m_str_Lieferscheindatum);
         m_List1.SetItemText(Zeile,2,m_str_Anschrift);
        m_List1.SetItemText(Zeile,3,m_str_KDNr);
        m_List1.SetItemText(Zeile,4,m_str_Gewicht);
        m_List1.SetItemText(Zeile,5,m_str_Lieferbedingung_Bezeichnung);
        m_List1.SetItemText(Zeile,6,m_str_Fakturiert);
        m_List1.SetItemText(Zeile,7,m_str_Sachbearbeiter);
}
//-------------------------------------------------------------------------------------------------------














Hello,
I did the adding to the ListView now in a new function.
Did you mean that? It didn´t work. Same result. Let me know, thanks.

I replaced this:
  //----------------------------- Listenelement ------------------------------------
         m_List1.InsertItem(Zeile,str_LieferscheinNr);  
         m_List1.SetItemText(Zeile,1,str_Lieferscheindatum);
         m_List1.SetItemText(Zeile,2,str_Name1);
         m_List1.SetItemText(Zeile,3,str_KDNr);
         m_List1.SetItemText(Zeile,4,str_Gewicht);
         m_List1.SetItemText(Zeile,5,str_Lieferbedingung_Bezeichnung);
         m_List1.SetItemText(Zeile,6,str_Fakturiert);
         m_List1.SetItemText(Zeile,7,str_Sachbearbeiter);
         //------------------------------------------------------------------------------------



with this:

          m_str_LieferscheinNr=str_LieferscheinNr;  
          m_str_Lieferscheindatum=str_Lieferscheindatum;
          m_str_Anschrift=str_Anschrift;
          m_str_KDNr=str_KDNr;
          m_str_Gewicht=str_Gewicht;
          m_str_Lieferbedingung_Bezeichnung=str_Lieferbedingung_Bezeichnung;
          m_str_Fakturiert=str_Fakturiert;
          m_str_Sachbearbeiter=str_Sachbearbeiter;


          //=============================
          Schreibe_Listenelement(Zeile);                        //Call Function
         //=============================


                                   

0
 

Author Comment

by:tsp2002
ID: 35147198
Can you add some log line to capture how much time each function is taking in milli seconds?
how should I do thsi?
0
 
LVL 33

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 35147389
you could only read a portion  of the addresses for one call of your OnTimer.

void CLieferscheine_Dialog::OnTimer(UINT nIDEvent)
{
   ...
         if (Lieferscheine_lesen(100))
         {
              // here the read was done
              // probably kill the timer now and return
              ...
             
         }
        // here we have not read all data and need further calls of OnTimer
   ...
}

bool CLieferscheine_Dialog::Lieferscheine_lesen(int numPortion)
{
   ...
  // check member variable if 
  if (m_numAddressesRead == 0)
  {
       // put here all initialisation of recordset and the open
      ...
      // that is the last statement
      m_ptrRs->MoveFirst();

   }
m_numAddressesRead 
   for (int i = 0; i < numPortion; i++)
   {
       if (m_ptrRs->EndOfFile)
       {
            m_numAddressesRead = 0; // reset counter for next query
            // put here all closing statements   
            ....
           return true;
      }
     // here read the data from recordset
     Holder_LieferscheinNr              = m_ptrRs->GetCollect("LieferscheinNr");
     ....
    // fill list control
   ...
  }
  return false;  // means more data available
}

Open in new window



Sara




0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Importing Special Characters in Dynamics GP Through Integration Manager 3 75
Visual Studio community 2015 2 75
source code to scan multiple images 6 90
Problem to event 3 92
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question