1Private Shared _CurrentCustomerAs New CurrentCustomerThe Customer class has all of the code, and then CurrentCustomer inherits Customer and overrides one property to use a value from the QueryString instead of a value that is passed in. The problem I'm having is that I don't know how to get the CID value from the Customer property and use it in the Customer class. I've seen similar functionality used, most notably for in FindControl, where you can do something like FindControl(id).Enabled=false and it sets the control with the ID passed in the FindControl function to not enabled. How can I achieve this same effect? I'd like to be able to do Customer(customerID).CustomerName and have it return the CustomerName using the customerID value that I passed in.
2Private Shared _CustomerAs New Customer
34Public Shared ReadOnly Property CurrentCustomer()As CurrentCustomer
5Get
6 Return _CurrentCustomer
7End Get
8 End Property
910 Public Shared ReadOnly Property Customer(ByVal CIDAs Integer)As Customer
11Get
12 Return _Customer
13End Get
14 End Property
How are you using the Customer collection class? If it uses Collection, check the following link, to get you started.
http://professionalaspnet.com/archive/2006/11/05/How-to-Filter-a-Generic-List.aspx
It's not defined as a collection. It's just
1Public Class Customer2Public Overridable ReadOnly Property CID()As Integer3 Get4'Return passed value5End Get6 End Property78 Public ReadOnly Property TID()As Integer9 Get10'Return TID11End Get12 End Property1314 Public ReadOnly Property SID()As Integer15 Get16'Return SID17End Get18 End Property1920 Public ReadOnly Property CustomerName()As String21 Get22'Return CustomerName23End Get24 End Property25'Etc26End ClassI want that CID property to return the value that is passed in thru Customer(CID) so that I can use it in other functions.
Maybe I am not getting it correctly, but if you have already access to the correct Customer then can't you used the CustomerName property directly from that object.
If this is not (which probably is right) what you are looking, then can you please rephrase the question and explain a more about your situation, then maybe we would be able to give a solution.
Sorry for the confusing wording. What I basically want to do is be able to do Customer(1022).CustomerName, which will return the customer name for the customer with the ID 1022. I don't know how to retrieve that 1022 value from the Customer class. I guess another good analogy for that would be relating it to something like Rows or Items where you can pass in the exact row number or item number that you want to reference. I know that these are collections, so is it not possible to achieve what I want to do without using a collection? I don't think I really have a use for a collection; I just need to get that 1022 value into my SQL statement so that I can retrieve the correct customer name. I've got a diagram here that shows exactly what I'm trying to do, so if this still doesn't make sense let me know and I can PM it or e-mail it to you, since they won't allow image uploading here on the forums. Thanks.
Acutally, just uploaded the image to image shack...here's the link
http://img186.imageshack.us/my.php?image=diagramuw8.gif
In your Customers class you are returning a shared variable called _Customer. Can you tell us how/where do you initialize this variable? Normally, what I do is as follows:
Public Class Customer private _Id as integer = -1' and so on... public readonly property ID() asInteger get return _Id end get end property' Load the object public shared function GetCustomerByID(customerId) AS CustomerDim sql asString = _"SELECT * FROM Customers WHERE CustomerID = " & customerId' Connect to the db and get results ' I have used SqlDataReader ' cmd refers to SqlCommand object dim cus asNew Customer() using reader as SqlDataReader = cmd.ExecuteReader() if reader.read() then cus.ID = cint(reader("CustomerID"))' so on ... for other properties else cus.ID = -1 end if reader.close() end using return cus end functionEnd Class If you do like this, then you can reference the customername directly from the object. If it confuses, then reply to the post explaining your doubts.I got it working. I may be going about it the wrong way, so if so feel free to correct me, but this is what I have done:
1Public Class Customers2Private Shared _CustomerAs New Customer3Friend Shared _CIDAs Integer45 Public Shared ReadOnly Property Customer(ByVal CIDAs Integer)As Customer6Get7 _CID = CID8Return _Customer9End Get10 End Property11End Class1213Public Class Customer14Public Overridable ReadOnly Property CID()As Integer15 Get16 Return Customers._CID17End Get18 End Property19End ClassThat seems to do the trick. Does that make sense? Is that the way to do it?
If that works for you, then it is ok. Is this the way to do? - Well it all depends upon your needs and architecture. Good luck.
0 comments:
Post a Comment