I'm trying to list a number of strings according to the text that the user entered in txtDepartment.Text. But it is displaying all the items that I have not only of type BOOK. DEPARTMENT is enumeration and it has values of type BOOK, NEWSPAPER and DIGITAL. Anyone know how I can display only of type BOOK not all the items in resourceslists? Below is the code I have so far.
string searchdep = txtDepartment.Text;
foreach(Resource res in resourceslist)
{
if(searchdep==DEPARTMENT.BOOK)
{
lbResult.Items.Add(res);
}
}
This is my class Resouce
namespace OOP_V1._3
{
public enum DEPARTMENT
{
BOOK,
NEWSPAPER,
DIGITAL
}
public enum STATUS
{
AVALIABLE,
BORROWED,
RESERVED
}
[Serializable]
public abstract class Resource : IComparable
{
public string title;
public string refno;
public DEPARTMENT department;
public STATUS status;
public string searchdep { get; set; }
public string getTitle()
{
return title;
}
public void setTitle(string iTitle)
{
this.title = iTitle;
}
public string getRefno()
{
return refno;
}
public void setRefno(string iRefno)
{
this.refno = iRefno;
}
public DEPARTMENT getDepartment()
{
return department;
}
public void setDepartment(DEPARTMENT iDepartment)
{
this.department = iDepartment;
}
public STATUS getStatus()
{
return status;
}
public void setStatus(STATUS iStatus)
{
this.status = iStatus;
}
public override string ToString() //display the books in the form of a string
{
return String.Format("Ref No: {0}, Title: {1}, Department: {2}, Status: {3}", refno, title, department, status);
}
public Resource(string refno, string title, string status)
{
this.refno = refno;
this.title = title;
if (status == "Available")
{
this.status = STATUS.AVALIABLE;
}
else if (status == "Borrowed")
{
this.status = STATUS.BORROWED;
}
else if (status == "Reserved")
{
this.status = STATUS.RESERVED;
}
}
public int CompareTo(Object obj)
{
Resource other = (Resource)obj;
int c = string.Compare(this.getTitle(), other.getTitle()); //comparing the title inputted by the user with a title from the list
return c; //returning the answer
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…