The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
How To return a Contact/Account name from ID
Posted: 06 Jun 06 8:29 AM
|
fiogf49gjkf0d I what to create a simple object/function that will return a Contact Name or Account Name, for example the function will be called;
'MyCallFunction(theID,TheTypeOfIDYouWant);
So for contact I would have MyCallFunction(Bind("ContactID"),'Contact'); and for account it would be MyCallFunction(Bind("AccountID"),'Account');
The function would contain a number of sql statements so for contact it would be select fullname from contact where contactid=@id My Function would then return the Contact Name
Does anyone know the best way to go about this? Or point me in the right direction; do I need to create a class?
Thanks for any help or advice. -- Duncan |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 06 Jun 06 4:12 PM
|
cialis controindicazioni cialis generico prezzo piu basso eteam.ou.edu fiogf49gjkf0d Why complicate it with having a single generic function for returning all/any names for passed id values? If it were me, I would just have a GetContactName(ContactID), GetAccountName(AccountID), etc to keep it simple.
However, if you really want a single function for it, then you'll need some way to map an entity to the fields that represent it's name.
ie:
protected string GetEntityName(string entityid, string entity) { string namefield; switch(entity.ToLower()) { "account": namefield = "account"; break; "contact": namefield = "firstname +' '+ lastname"; break; "opportunity": namefield = "description"; break; //etc... } string sql = string.Format("select {0} from {1} where {1}id = ?", namefield, entity); //... }
Know what I mean, but really, this really isn't that complicated of a route, but you don't want to get too carried away with what should be a simple task of just getting the name for an entity. |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 07 Jun 06 3:19 AM
|
cialis generico prezzo in farmacia cialis generico fiogf49gjkf0d Thanks Ryan, I'm still finding my feet with asp.net, so I'm not always sure what's best practice.
Can you tell, me why its better to have a separate function for each ID call, my initial thoughts were if I had one function, it would only give me one function to manage. I'm not 100% sure where I need to put this code so I can call it again; I'm guessing I need to create a class or a global application class, is this right?
Many Thanks Duncan
|
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 07 Jun 06 6:21 PM
|
fiogf49gjkf0d It's not that it is bad to use a single function. I just like to keep it simple and I like to keep my objects organized. It wouldn't be so bad to use bindable objects to represent the account, contact, etc. You could override ToString on each to return the name. Then you could just call that on each of them.
As far as where to put the code, it all depends on where you're using it and how your app is structured.
I'm guessing I need to create a class or a global application class, is this right? |
|
Not sure what you mean here, but I think you're overthinking it. You could just put it in the class behind your form if you wanted. |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 08 Jun 06 10:25 AM
|
potency of naloxone and naltrexone naloxone vs naltrexone fiogf49gjkf0d Ryan, you right I was over complicating this, I though it was much harder than it actually was. Creating the function was a piece of cake.
I'm using a Formview to display the data and if I put it a function with hard coded ids I'm fine as below;
<asp:TextBox ID="eveOrganiserID" CssClass="text" runat="server" Text='<%# GetEntityName("ABCD00000001", "account") %>' />
However if I try to pass the variable I need, I get an error "Name 'Bind' not declared"
<asp:TextBox ID="eveOrganiserID" CssClass="text" runat="server" Text='<%# GetEntityName(Bind("OrganiserID"),"account") %>' />
Any ideas where I'm going wrong? Many Thanks -- Duncan |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 08 Jun 06 11:48 AM
|
cheap abortion clinics in phoenix az cheap abortion pill kit online fiogf49gjkf0d What does your code look like? Is it .NET 1.1 or 2.0? Is this being called inside a bindable control, a datagrid, datarepeater, or some other bindable list? Where you're using sort of determines what the best answer to that is. So, let's see it. |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 08 Jun 06 12:25 PM
|
fiogf49gjkf0d I have add a little code in my previous post but Its not displaying correctly. I've look all around the site and can't see how I can show my code, are there special tags I need to use like <code></code> I also have more code I want to add to this post but don't want to until I can add it properly
Many Thanks! |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 08 Jun 06 1:04 PM
|
fiogf49gjkf0d You know, that is a great idea to add support for code blocks. The problem is your "<" and ">" for yor tags are likely being rejected (I do allow for some markup, but other markup is rejected).
I have a tool that I wrote for posting code on the web. You can use it if you'd like: http://files.farleyzone.com/downloads/CodeHighlighterSetup.msi
It just colorizes the code and puts it into an HTML format. Then just wrap it all in <pre></pre> tags (BTW, there's also a weird thing in my stylysheet that won't show a blank line in pre blocks unless there is a single space on the line -- it's on the fix list, just haven't gotten around to it quite yet) |
|
|
| |
| |
|
Re: How To return a Contact/Account name from ID
Posted: 08 Jun 06 1:31 PM
|
cialis 20mg cena cialis cena v lekarni fiogf49gjkf0d I'm running .net 2 using VB I'm using a SQLDataSource as below
<asp:SqlDataSource ID="SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SLXConnectionString %>" SelectCommand="<%$ appSettings:eventDetailRecordSQL %>" UpdateCommand="<%$ appSettings:eventDetailUpdateSQL %>"> <SelectParameters> <asp:QueryStringParameter Name="E1TB_EVENTSID" QueryStringField="id" Type="String" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="E1TB_EVENTSID" Type="String" /> <asp:Parameter Name="Event_Name" Type="String" /> <asp:Parameter Name="subName" Type="String" /> <asp:Parameter Name="Event_Type" Type="String" /> <asp:Parameter Name="Event_Subtype" Type="String" /> <asp:Parameter Name="CourseCode" Type="String" /> <asp:Parameter Name="Event_Status" Type="String" /> <asp:Parameter Name="Location" Type="String" /> <asp:Parameter Name="Location_Room" Type="String" /> <asp:Parameter Name="Department" Type="String" /> <asp:Parameter Name="Region" Type="String" /> <asp:Parameter Name="Subregion" Type="String" /> <asp:Parameter Name="Places_Maximum" Type="String" /> <asp:Parameter Name="Places_Minimum" Type="String" /> <asp:Parameter Name="isprivate" Type="String" /> <asp:Parameter Name="isWeb" Type="String" /> <asp:Parameter Name="isExternal" Type="String" /> <asp:Parameter Name="OrganiserID" Type="String" /> </UpdateParameters> </asp:SqlDataSource>
And I'm binding that to my Form view
<asp:FormView ID="FormView1" runat="server" Width="100%" DataKeyNames="E1TB_EVENTSID" DataSourceID="SqlDataSource" DefaultMode="Insert" OnItemInserting="FormView1_ItemInserting"> <EditItemTemplate> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top"> <table cellpadding="5" cellspacing="0" width="100%"> <tr> <td>Sub-Region:</td> <td><asp:TextBox ID="eveSubRegion" CssClass="text" runat="server" Text='<%# Bind("SubRegion") %>' onfocus="popPick('Event Subregion',this);" onkeyup="checkPick(this);" onblur="setPick(this);" style="width:100px"/> <input type=button class=multi id=Button5 value="..." onClick="document.all.FormView1_eveSubRegion.focus();" onfocus="picklistHide();"></td> </tr> <tr> <td>Organiser:</td> <td><asp:TextBox ID="eveOrganiserID" CssClass="text" style="display:;" runat="server" Text='<%# Bind("OrganiserID") %>' /> <asp:TextBox ID="eveOrganiserID_link" CssClass="text" runat="server" Text='<%# GetEntityName("abc", "account") %>' onfocus="popLookup('User',this);" style="width:200px"/> <img src="../common/images/buttons/lookup.gif" align="absmiddle" class="btn" id=Button7 onmousedown="document.all.FormView1_eveOrganiserID_link.focus();" onfocus="picklistHide();"></td> </tr> </table> </td> </tr> </table> </EditItemTemplate> </asp:FormView>
The function I'm calling is currently hard coded
Public Function GetEntityName(ByVal entityid As String, ByVal entity As String) As String Dim dbCon_e As New System.Data.OleDb.OleDbConnection(ConfigurationManager.AppSettings("ConnectionString")) dbCon_e.Open() Dim x As String Dim sql_e As String sql_e = "select username from userinfo where userid='Admin'" Dim oCommand_e As New System.Data.OleDb.OleDbCommand(sql_e, dbCon_e) Dim oReader_e As System.Data.OleDb.OleDbDataReader oReader_e = oCommand_e.ExecuteReader() oReader_e.Read() x = oReader_e.GetValue(0) oReader_e.Close() dbCon_e.Close() Return (x) End Function
if I call the code like this its fine
<asp:TextBox ID="eveOrganiserID" CssClass="text" runat="server" Text='<%# GetEntityName("ABCD00000001", "account") %>' />
But if I want pass the ID to the function as below I get the error "Name 'Bind' not declared"
<asp:TextBox ID="eveOrganiserID" CssClass="text" runat="server" Text='<%# GetEntityName(Bind("OrganiserID"),"account") %>' />
I think I've got a bit code happy! -- Thanks |
|
|
| |
|
Re: How To return a Contact/Account name from ID
Posted: 21 Jun 06 4:13 PM
|
citalopram side effects 20mg citalopram 20mg tablets fiogf49gjkf0d Ok for thoses that are interested, I created a class in the App_Code section called GetEntityName
Code is as follows
Imports Microsoft.VisualBasic
Public Class GetEntityName Private _entityType As String Property entityType() As String Get Return _entityType End Get Set(ByVal value As String) _entityType = value End Set End Property
Private _ID As String Property ID() As String Get Return _ID End Get Set(ByVal value As String) _ID = value End Set End Property
Public Function getValue() As String Dim returnVal As String
If _ID <> "" Then Dim dbCon_n As New System.Data.OleDb.OleDbConnection(ConfigurationManager.AppSettings("ConnectionString")) Dim sql_n As String Dim oReader_n As System.Data.OleDb.OleDbDataReader
sql_n = "" Select Case _entityType Case "Contact" sql_n = ConfigurationManager.AppSettings("contactNameSQL") Case "Account" sql_n = ConfigurationManager.AppSettings("accountNameSQL") Case "User" sql_n = ConfigurationManager.AppSettings("userNameSQL") End Select
sql_n = sql_n & "'" & _ID & "'"
Dim Com_n As New System.Data.OleDb.OleDbCommand(sql_n, dbCon_n) dbCon_n.Open() oReader_n = Com_n.ExecuteReader() oReader_n.Read() returnVal = oReader_n.GetValue(0) oReader_n.Close() dbCon_n.Close()
Else returnVal = "" End If
Return (returnVal)
End Function End Class
|
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 23 Jul 06 11:46 AM
|
fiogf49gjkf0d Interesting code, However I usually follow a more generic pattern for extracting entity types. Generally by using factory pattern inside the manager (code that has the getEntityByID call) it is possible to create well defined business objects.
Usually it is best to start off with a solid base class for all of your entitles and with a little reflection to handle the table to property mapping providing the sql in the app config is no longer needed. Extend it even more and add discovery to your business entitles and deployment and upgrade will be much easier. If you have access to, look that the SalesLogix mobile PPC client and architect, it uses this generic method where you can basically do ;
BaseBusinessObject account = MobileApp.App.Customizations.GetBusinessObject("Account"); BusinessHelper.LoadByPrimaryKey(account, accountID);
By also using a simple mapping layer child objects( Tables like address) can also be loaded within the context of the main business entity and working on them as a whole is much easier then loading the account and then the address and then some c_ table.
Now if you really want to extend youself, it is possible to create objects at runtime using Reflection.emit functionality.
Hope this helps,
Mark Dykun
|
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 23 Jul 06 1:58 PM
|
fiogf49gjkf0d Hi Mark thanks for the info. I'm not sure I completely follow. The reason for calling the SQL from the web.config file, is to allow me to integrate my application with multiple CRM system, i.e just use a different web.config file based on which DB I’m integrating with. I'm sure this is not best practice and I'm very much learning as I go.
Would using Business Objects allow me to work with different data structures?
It sounds like looking at the SalesLogix mobile PPC client and architect will give me a good insight of how it should be done, do you have any info on how I can get hold of this, or is this via sage?
Thanks for your help -- Duncan |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 24 Jul 06 9:19 AM
|
fiogf49gjkf0d Generally BusinessObjects are somewhat bound to schema and do not change their interface dynamically. Usually there needs to be an understanding of the underlying data definition when building a form/Web Page anyway and a business object is there to hide the implementation details, offer validation or support calculated fields. Now if you really need a dynamic object where between systems the account table is different it is always possible to wrap the table in a business object that is derived from HashTable or some collection object. therefore when the schema is changed the new fields can be retrieved using a more dynamic method. Storing the SQL externally is never recommended especially since the connection string is also visible. If you need to use dynamic sql at least host it within a assembly to offer some level of protection.
Mark |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 24 Jul 06 11:04 AM
|
fiogf49gjkf0d Thanks Mark,
Ryan’s also recommended using BusinessObjects to access data. It definitely seems to be the way to fly, I think I need to get my head round this first, and then I'll move on to some more complex stuff Thanks for your help and your suggestions. |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 24 Jul 06 12:35 PM
|
fiogf49gjkf0d Why not start with storing parameterized query information instead of entire SQL strings? You can also use the DbConnectionStringBuilders to store just bits of the connection string like username and pass without keeping the entire thing visible.
BOs can be a bit to wrap your head around and it'd probably be easier to start in iterative steps than to try to develop something Ryan has right off the bat.
Personally I'm a fan of hardcode once, twice, then refactor to figure out the common code I just copy/pasted for the most part into a common interface. Then I only have to worry about the differences between the 2 objects, not the entire copy. If you've done this for multiple CRM you could easily develop an abstract interface to store the common chunks and all you're left with is handling the difference. You would have to hook into the interface with each CRM but you could store more logic than simple SQL strings. It could even be a part of your Business Object model so it's not like you would have to abandon it when you've graduated the school of BO. |
|
|
|
Re: How To return a Contact/Account name from ID
Posted: 25 Jul 06 2:40 AM
|
fiogf49gjkf0d Putting the SQL in the web.config file was/is a temporary method, basically the only one I knew would work and I was planning to revisit this to find a better method.
I did look at adding parameters to the web.config file, but found if you did this it restarts the application, I also read it wasn't recommended. I use a similar working method to you; I'll basically get the code to work first then workout how I can improve/simplify the code.
At the moment I'm at the point of putting all the SQL I needs to change for each CRM system in the config file, once I have all the piece I'll then work out a better way of storing the SQL.
I would be interested in what people think would be the best way to store this, whether adding parameters to the web.config is OK if its done at the start or if its a big no no.
|
|
|
|