//--------------------------------------------------------------------------- #include #pragma hdrstop #include "UID_Form.h" #include "MainForm.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TUID_Frm *UID_Frm; //--------------------------------------------------------------------------- __fastcall TUID_Frm::TUID_Frm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TUID_Frm::DisplayItem(void) { if(LEADDicom1->CurrentUID == 0) return; /* display the items information */ Edit_Code->Text = LEADDicom1->CurrentUID->Code; Edit_Name->Text = LEADDicom1->CurrentUID->Name; } void __fastcall TUID_Frm::FillList(void) { TListItem *ItemX; Cardinal nCount, x; /* get the UID Item count */ nCount = LEADDicom1->GetUIDCount(); if(nCount > 0) { /* get the first UID Item */ LEADDicom1->MoveFirstUID(); ListView1->Items->BeginUpdate(); for(x=1; x<=nCount; ++x) { /* add item to the ListView control */ ItemX = ListView1->Items->Add(); ItemX->Caption = LEADDicom1->CurrentUID->Code; ItemX->SubItems->Add(LEADDicom1->CurrentUID->Name); if(x < nCount) /* get next item */ LEADDicom1->MoveNextUID(); } ListView1->Items->EndUpdate(); } LEADDicom1->MoveFirstUID(); ListView1->Selected = ListView1->Items->Item[0]; ListView1->Selected->Focused = true; } void __fastcall TUID_Frm::Button_DefaultUIDClick(TObject *Sender) { Screen->Cursor = crHourGlass; ListView1->Items->Clear(); ListView1->Refresh(); LEADDicom1->DefaultUID(); FillList(); DisplayItem(); UpdateButtons(); Screen->Cursor = crDefault; } void __fastcall TUID_Frm::Button_ResetUIDClick(TObject *Sender) { ListView1->Items->Clear(); ListView1->Refresh(); /* Clear all items from the UID Table */ LEADDicom1->ResetUID(); UpdateButtons(); } void __fastcall TUID_Frm::Button_InsertClick(TObject *Sender) { int nRet; TListItem *ItemX; nRet = LEADDicom1->FindUID(Edit_Code->Text); if(nRet == SUCCESS) { ShowMessage("Already Exists!"); return; } nRet = LEADDicom1->InsertUID(Edit_Code->Text, Edit_Name->Text); if(nRet != SUCCESS) { ShowMessage("Error"); return; } /* add item to the ListView control */ ItemX = ListView1->Items->Add(); ItemX->Caption = LEADDicom1->CurrentUID->Code; ItemX->SubItems->Add(LEADDicom1->CurrentUID->Name); DisplayItem(); ListView1->Selected = ItemX; ListView1->Selected->Focused = true; ListView1->Refresh (); ListView1->SetFocus(); UpdateButtons(); } void __fastcall TUID_Frm::Button_DeleteClick(TObject *Sender) { int nIndex; if(ListView1->Selected == 0) return; /* move to the selected UID */ if(LEADDicom1->FindUID(ListView1->Selected->Caption) != SUCCESS) return; /* delete it */ LEADDicom1->DeleteUID(); /* remove it from the list view control */ nIndex = ListView1->Selected->Index; ListView1->Items->Delete(nIndex); --nIndex; UpdateButtons(); if(nIndex < 0) nIndex = 0; if(ListView1->Items->Count == 0) return; ListView1->Selected = ListView1->Items->Item[nIndex]; ListView1->Selected->Focused = true; DisplayItem(); ListView1->Refresh(); ListView1->SetFocus(); } void __fastcall TUID_Frm::Button_SetNameClick(TObject *Sender) { /* move to the selected UID */ if(LEADDicom1->FindUID(ListView1->Selected->Caption) == SUCCESS) LEADDicom1->SetUIDName(Edit_NewUIDName->Text); /* change the name */ /* update it in the list view control */ DisplayItem(); ListView1->Selected->SubItems->Strings[0] = LEADDicom1->CurrentUID->Name; ListView1->Refresh(); } void __fastcall TUID_Frm::UpdateList(void) { ListView1->Selected = ListView1->FindCaption(0, LEADDicom1->CurrentUID->Code, false, true, false); ListView1->Selected->Focused = true; ListView1->Selected->MakeVisible(false); ListView1->SetFocus(); } void __fastcall TUID_Frm::Button_FirstClick(TObject *Sender) { LEADDicom1->MoveFirstUID(); UpdateList(); DisplayItem(); } void __fastcall TUID_Frm::Button_LastClick(TObject *Sender) { LEADDicom1->MoveLastUID(); UpdateList(); DisplayItem(); } void __fastcall TUID_Frm::Button_NextClick(TObject *Sender) { LEADDicom1->MoveNextUID(); UpdateList(); DisplayItem(); } void __fastcall TUID_Frm::Button_PrevClick(TObject *Sender) { LEADDicom1->MovePrevUID(); UpdateList(); DisplayItem(); } void __fastcall TUID_Frm::ListView1Change(TObject *Sender, TListItem *Item, TItemChange Change) { if((Change == ctState) && Item->Selected) { LEADDicom1->FindUID(Item->Caption); DisplayItem(); } } void __fastcall TUID_Frm::FormCreate(TObject *Sender) { LEADDicom1 = MainFrm->LEADDicom1; LEADDicom1->EnableMethodErrors = false; FillList(); LEADDicom1->EnableMethodErrors = true; DisplayItem(); } void __fastcall TUID_Frm::UpdateButtons(void) { Boolean bListViewEmpty; if(ListView1->Items->Count == 0 ) { bListViewEmpty = true; Edit_Code->Text = ""; Edit_Name->Text = ""; } else bListViewEmpty = false; Button_First->Enabled = ! bListViewEmpty; Button_Next->Enabled = ! bListViewEmpty; Button_Last->Enabled = ! bListViewEmpty; Button_Prev->Enabled = ! bListViewEmpty; Button_SetName->Enabled = ! bListViewEmpty; Edit_NewUIDName->Enabled = ! bListViewEmpty; Label1->Enabled = ! bListViewEmpty; } //---------------------------------------------------------------------------