--- AdminDialog.cpp 2006/08/30 21:57:57 9 +++ AdminDialog.cpp 2006/09/03 10:10:19 31 @@ -1,5 +1,6 @@ -// AdminDialog.cpp : implementation file -// +/* + * Developed by Torben H. Nielsen + */ #include "stdafx.h" #include "h6-udlånssystem.h" @@ -118,13 +119,11 @@ void AdminDialog::OnBnClickedRdusers() { - GetDlgItem(IDC_DELETE)->EnableWindow(true); LoadUsers(); } void AdminDialog::OnBnClickedRdequipment() { - GetDlgItem(IDC_DELETE)->EnableWindow(false); LoadEquipment(); } @@ -238,19 +237,29 @@ int sel = list->GetSelectionMark(); if (sel == -1) { - MessageBox("You must select an user to delete"); + MessageBox("You must select an user/equipment to delete"); return; } - CString inits = list->GetItemText(sel,0); - CString name = list->GetItemText(sel,1); + DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer(); + CString id = list->GetItemText(sel,0); + CString name = list->GetItemText(sel,1); CString question; - question.Format("Are you sure you want to delete %s : %s ?", inits,name); - if (MessageBox(question, "Delete",MB_YESNO) == IDYES) { - Person p = CommonStorage::Instance()->getDBLayer()->GetPerson(inits); - CommonStorage::Instance()->getDBLayer()->DeletePerson(p); - LoadUsers(); - } + question.Format("Are you sure you want to delete %s : %s ?", id,name); + if ( ((CButton*)GetDlgItem(IDC_RDUSERS))->GetCheck() ) { + if (MessageBox(question, "Delete user",MB_YESNO) == IDYES) { + Person p = CommonStorage::Instance()->getDBLayer()->GetPerson(id); + CommonStorage::Instance()->getDBLayer()->DeletePerson(p); + LoadUsers(); + } + } else { + if (MessageBox(question,"Delete equipment", MB_YESNO) == IDYES) { + Equipment e; + e.barcode = id; + dblayer->DeleteEquipment(e); + LoadEquipment(); + } + } }