Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generics Help Please

Status
Not open for further replies.

kss444

Programmer
Sep 19, 2006
306
US
I am using VS 2005.
The code I have to modify is using generics .ConvertAll<>
I do not know what I might be doing wrong.
I have documenttypes (0,1,3,4)
This is what is used in the codes case statement 0,1,4 is one case
and 3 is another.

Now I am needing to have another documenttype of ALL made this case 5.
If you select an individual documentType the following code works great, but if you want to return all I get results returned but I think it's failing in the generics .ConvertAll call and not showing my results in my grid. I have also added try catch to catch any errors but there are none.

I have the following snippet of code:

public static List<IDocument> SelectIDocuments(string webUserID, int documentTypeID, string routeID,
string customerID, string documentIDPrefix, string regionID, string districtID, DateTime startDate,
DateTime endDate, bool dexCustomersOnly, string returnReasons, string sortExpression, int maximumRows, int startRowIndex)
{
switch (documentTypeID)
{
case 0: case 1: case 4:
List<DocumentHistory> documentHistoryList = SelectDocumentHistory(webUserID, documentTypeID, routeID,
customerID, documentIDPrefix, regionID, districtID, startDate, endDate, dexCustomersOnly, returnReasons, sortExpression,
maximumRows, startRowIndex);
return documentHistoryList.ConvertAll<IDocument>(delegate(DocumentHistory d) { return (IDocument)d; });


case 3:
List<Collection> collList = SelectCollectionHistory(webUserID, documentTypeID, routeID,
customerID, documentIDPrefix, regionID, districtID, startDate, endDate, dexCustomersOnly, sortExpression,
maximumRows, startRowIndex);
return collList.ConvertAll<IDocument>(delegate(Collection c) { return (IDocument)c; });

//KS 5/24/2011
case 5:
List<DocumentHistory> documentHistoryListA = SelectDocumentHistory(webUserID, documentTypeID, routeID,
customerID, documentIDPrefix, regionID, districtID, startDate, endDate, dexCustomersOnly, returnReasons, sortExpression,
maximumRows, startRowIndex);
return documentHistoryListA.ConvertAll<IDocument>(delegate(DocumentHistory d) { return (IDocument)d; });


}

return new List<IDocument>();
}

*** the following are my objects
The DocumentHistory and Collection are identical except for 2 additional fields.
public class DocumentHistory : VelSol.Data.DataContainer, IDocument
{
#region Fields

private Guid documentHistoryID;
private string documentID;
private string documentTypeDescription;
private string routeID;
private string routeDescription;
private string customerName;
private DateTime docDT;
private DateTime startDT;
private DateTime endDT;
private string customerID;
private decimal amount;
private string receipt;
//KS added 5/5/2011
private string terms;
private string arbalance;
private string dotvehicleID;
private string taxAmount;
private string taxRate;
private string ponumber;
private string stopNumber;


#endregion

#region Constructors

public DocumentHistory()
{
this.DocumentID = "";
this.DocumentTypeDescription = "";
this.RouteID = "";
this.RouteDescription = "";
this.CustomerName = "";
this.CustomerID = "";
//KS added 5/5/2011
this.Terms = "";
this.ARBalance = "";
this.DOTVehicleID = "";
this.TaxAmount = "";
this.TaxRate = "";
this.PONumber = "";
this.StopNumber = "";



}
#endregion

#region Properties

public Guid DocumentHistoryID
{
get { return this.documentHistoryID; }
set { this.documentHistoryID = value; }
}

public string DocumentID
{
get { return this.documentID; }
set { this.documentID = value; }
}

public string DocumentTypeDescription
{
get { return this.documentTypeDescription; }
set { this.documentTypeDescription = value; }
}

public string RouteID
{
get { return this.routeID; }
set { this.routeID = value; }
}

public string RouteDescription
{
get { return this.routeDescription; }
set { this.routeDescription = value; }
}

public string CustomerName
{
get { return this.customerName; }
set { this.customerName = value; }
}

public DateTime DocDT
{
get { return this.docDT; }
set { this.docDT = value; }
}

public DateTime StartDT
{
get { return this.startDT; }
set { this.startDT = value; }
}

public DateTime EndDT
{
get { return this.endDT; }
set { this.endDT = value; }
}

public string CustomerID
{
get { return this.customerID; }
set { this.customerID = value; }
}

public decimal Amount
{
get { return this.amount; }
set { this.amount = value; }
}

public string Receipt
{
get { return this.receipt; }
set { this.receipt = value; }
}

public string Terms
{
get { return this.terms; }
set { this.terms = value; }
}

public string ARBalance
{
get { return this.arbalance; }
set { this.arbalance = value; }
}

public string DOTVehicleID
{
get { return this.dotvehicleID; }
set { this.dotvehicleID = value; }
}

public string TaxAmount
{
get { return this.taxAmount; }
set { this.taxAmount = value; }
}

public string TaxRate
{
get { return this.taxRate; }
set { this.taxRate = value; }
}

public string PONumber
{
get { return this.ponumber; }
set { this.ponumber = value; }
}

public string StopNumber
{
get { return this.stopNumber; }
set { this.stopNumber = value; }
}


#endregion

#region IDocument Members

public string ID
{
get { return this.DocumentHistoryID.ToString(); }
}

public string Number
{
get { return this.DocumentID; }
}

public DateTime DocDate
{
get { return this.DocDT; }
}

public DateTime StartDate
{
get { return this.StartDT; }
}

public DateTime EndDate
{
get { return this.EndDT; }
}

public string TypeDescription
{
get { return this.DocumentTypeDescription; }
}

#endregion
}

public interface IDocument
{
string ID { get; }

string Number { get; }

string TypeDescription { get; }

string CustomerName { get; }

string RouteID { get; }

string RouteDescription { get; }

decimal Amount { get; }

string Receipt { get; }

string CustomerID { get; }

DateTime DocDate { get; }

}

I think my issue is with interface IDocument
but I don't know.

Thanks for the help in advance.
KS.

Ordinary Programmer
 
the problem is most likely the inheritance tree, or your understand of inheritance. if the concrete type implements the interface there is not need for explicit casting. that's the point of OOP.




Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Got it. I added some fields from DocumentHistory object into the Document object.

But I think the main fix was later in the code, after this ConvertAll.

But funny thing it just all of a sudden broke in this later code, and that helped to pin point the fix.

Thanks,
KS.

Ordinary Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top