Solved

Need some help with ListView and dispaly

Posted on 2011-03-15
7
515 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
Comment Utility
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
Comment Utility
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
Comment Utility
Can you add some log line to capture how much time each function is taking in milli seconds?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:tsp2002
Comment Utility
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
Comment Utility
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
Comment Utility
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 32

Assisted Solution

by:sarabande
sarabande earned 250 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now