GetPresentationCount Example for C#

//LEADDICOMNet1 is a predefined LEADDicomNet object
private void TestGetPresentationCount ( )
{
   const string UID_CT_IMAGE_STORAGE = "1.2.840.10008.5.1.4.1.1.2";
   // Computed Tomography Image Storage
   int x = 0 ;
   int id = 0;
   int maxid = 0;
   string Out = null;
   //create the Associate Class as Request
   LEADDICOMNet1.CreateAssociate(true);
   //set the Associate to the default
   LEADDICOMNet1.DefaultAssociate(LEADDICOMNet1.hPDU);
   //get current id's and display them
   Out = "";
   maxid = 0;
   for (x = 0; x < LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU); x++)
   {
      id = LEADDICOMNet1.GetPresentationID(LEADDICOMNet1.hPDU, x);
      Out = Out + id;
      Out = Out + "\r";
      //store the highest id
      if (id > maxid)
         maxid = id;
   }
   MessageBox.Show(Out);
   id = maxid + 2;
   //id must be unique and odd number
   //change the some ids and then display them all
   for (x = 0; x < LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU); x++)
   {
      LEADDICOMNet1.SetPresentationID(LEADDICOMNet1.hPDU, x, (short)id);
      id = id + 2;      //id must be odd number
   }
   Out = "";
   for (x = 0; x < LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU); x++)
   {
      Out = Out + LEADDICOMNet1.GetPresentationID(LEADDICOMNet1.hPDU, x);
      Out = Out + "\r";
   }
   MessageBox.Show(Out);
   //add a presentation context
   Out = "";
   LEADDICOMNet1.AddPresentation(LEADDICOMNet1.hPDU, 1, (short)LTDNCLib.AssociateAcceptConstants.PDU_ACCEPT_RESULT_SUCCESS, UID_CT_IMAGE_STORAGE);
   for (x = 0; x < LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU); x++)
   {
      Out = Out + LEADDICOMNet1.GetPresentationID(LEADDICOMNet1.hPDU, x);
      Out = Out + "\r";
   }
   MessageBox.Show(Out);
   //delete the one we added
   Out = "";
   LEADDICOMNet1.DeletePresentation(LEADDICOMNet1.hPDU, 1);
   for (x = 0; x < LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU); x++)
   {
      Out = Out + LEADDICOMNet1.GetPresentationID(LEADDICOMNet1.hPDU, x);
      Out = Out + "\r";
   }
   MessageBox.Show(Out);
   LEADDICOMNet1.FreeAssociate(LEADDICOMNet1.hPDU);
}