NetReceiveNGetRequest Example for C#

//This example uses the predefined variable “TreeView1” of type “TreeView” from “.NET Framework”.
//LEADDICOMNet1 is a predefined LEADDicomNet object
//LEADDICOM1 is a DICOM Dataset defined outside this method
//LEADDICOM2 is a DICOM Dataset defined outside this method
private void LEADDICOMNet1_NetReceiveNGetRequest(int hNet, short nPresentationID, short nMessageID, string pszClass, string pszInstance)
{
   short nRet = 0;
   System.Windows.Forms.TreeNode NewNode = null;
   string szReply = null;
   string szName = null;
   NewNode = new System.Windows.Forms.TreeNode("Command Set - " + "N-GET-REQUEST");
   TreeView1.Nodes.Add(NewNode);
   NewNode.EnsureVisible();
   NewNode.Nodes.Add("Presentation ID: " + System.Convert.ToString(nPresentationID));
   NewNode.Nodes.Add("Message ID: " + System.Convert.ToString(nMessageID));
   nRet = LEADDICOM1.FindUID(pszClass);
   if (nRet == 0)
   {
      szName = LEADDICOM1.get_CurrentUID().Name;
      NewNode.Nodes.Add("Affected SOP Class: " + szName + " - " + pszClass);
   }
   else
      NewNode.Nodes.Add("Affected SOP Class: " + pszClass);
   NewNode.Nodes.Add("Affected SOP Instance: " + pszInstance);
   //this function will fill the values the data set elements in
   LEADDICOM2.hDicomDS nRet = PerformNGETCommand(pszClass, pszInstance);
   if (nRet != (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
      nRet = (short)LTDNCLib.DicomCommandStatusConstants.COMMAND_STATUS_NO_SUCH_OBJECT_INSTANCE;
   //send a response
   LEADDICOMNet1.SendNGetResponse(hNet, nPresentationID, nMessageID, pszClass, pszInstance, nRet, LEADDICOM2.hDicomDS);
}

//LEADDICOMNet1 is a predefined LEADDicomNet object
//LEADDICOM1 is a DICOM Dataset defined outside this method
//LEADDICOM2 is a DICOM Dataset defined outside this method
private short PerformNGETCommand(string pszClass, string pszInstance)
{
   short nRet = 0;
   int nTag = 0;
   int x = 0;
   short nVR = 0;
   //this sample simply loads a fixed data set
   //here, a server should check the class and instance against
   //all SOP classes it manages, and then fill out hDS from the
   //correctly matching instance, if one is found
   nRet = LEADDICOM1.LoadDS("e:\\images\\dicom16.dic", 0);
   LEADDICOM2.InitDS((int)LTDICLib.DicomClassConstants.DICOM_CLASS_UNKNOWN, 0);
   LEADDICOM2.ResetDS();
   if (nRet == 0)
      LEADDICOM1.MoveFirstElement(false);
   else return nRet;
      for (x = 0; x < LEADDICOMNet1.RequestAttributeCount; x++)
      {
         //get each element
         nTag = LEADDICOMNet1.get_RequestAttributes(x);
         LEADDICOM1.FindTag(nTag);
         nVR = LEADDICOM1.get_CurrentTag().VR;
         nRet = LEADDICOM1.FindFirstElement(nTag, false);
         //in this sample, if we don't find the requested tag, we
         //do not return an empty element!
         if (nRet == 0)
         {
            //copy the element value LEADDICOM1.GetConvertValueInsertElement();
            LEADDICOM2.InsertElement(false, nTag, nVR, false, 0);
            LEADDICOM2.StringValueCount = 1;
            LEADDICOM2.set_StringValues(0, LEADDICOM1.get_StringValues(0));
            LEADDICOM2.SetConvertValue();
         }
      }
   return (short) LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS;
}