bramu

Hi All,

I am trying to add OrganizationProfile so, that I can pull the list of organizations into the register.aspx and distplay in a dropdownlist.

for this I had created the following code. But, whend call "ReadOnlyCollection <OrganizationProfile> ss = OrganizationProfile.GetAll();" it give me an exception "Expecting a valid class or view name. Class or view name not found." But, "ReadOnlyCollection<CurrencyProfile> ss = CurrencyProfile.GetAll();" works fine. (this is just a test. I need to write some code to display the organization in DDL)

Code "OrganizationProfile.cs" in App_code\Profiles. Please let me know where I am going wrong.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using System.Collections.ObjectModel;

using System.Data.OleDb;
using System.Globalization;
using System.Runtime.InteropServices;
using ADODB;
using CommerceComponents;
using Microsoft.CommerceServer.Runtime;
using CommerceProfile = Microsoft.CommerceServer.Runtime.Profiles.Profile;


namespace CommerceSite.Profiles
{
public static class OrganizationProfilePropertyNames
{
#region Profile Name

public const string ProfileName = "OrganizationObject";

#endregion

#region General Information

public const string OrganizationID = "GeneralInfo.org_id";
public const string Name = "GeneralInfo.name";
public const string TradingPartnerNumber = "GeneralInfo.trading_partner_number";
public const string AdministrativeContact = "GeneralInfo.user_id_admin_contact";
public const string Receiver = "GeneralInfo.user_id_receiver";
public const string PreferredAddress = "GeneralInfo.preferred_address";
public const string AddressList = "GeneralInfo.address_list";
public const string OrganizationCatalogSet = "GeneralInfo.org_catalog_set";
public const string PurchasingGroup = "GeneralInfo.purchasing";

#endregion

#region Profile System

public const string ChangedBy = "ProfileSystem.user_id_changed_by";
public const string DateLastChanged = "ProfileSystem.date_last_changed";
public const string DateCreated = "ProfileSystem.date_created";
//public const string ChangedBy = "ProfileSystem.changed_by";
public const string AdapterDateLastChanged = "ProfileSystem.csadapter_date_last_changed";

#endregion
}

/// <summary>
/// Summary description for OrganizationProfile
/// </summary>
public class OrganizationProfile
{
#region Data Members

private CommerceProfile profile;

#endregion

#region Construction
public OrganizationProfile(CommerceProfile profile)
{
if (profile == null)
{
throw new ArgumentNullException("profile");
}
this.profile = profile;
}
#endregion

#region Static Members
public static OrganizationProfile Get(string organizationID)
{
if (!string.IsNullOrEmpty(organizationID))
{
CommerceProfile profile =
CommerceContext.Current.ProfileSystem.GetProfile(
organizationID, OrganizationProfilePropertyNames.ProfileName);
if (profile != null)
{
return new OrganizationProfile(profile);
}
}

return null;
}

public static ReadOnlyCollection<string> GetAllOrganizationIDs()
{
object recordsAffected;
int options = 0;

string cmdText =
string.Format(
CultureInfo.InvariantCulture,
"SELECT {0} FROM {1}",
OrganizationProfilePropertyNames.OrganizationID,
OrganizationProfilePropertyNames.ProfileName);

Connection csoledb = CommerceContext.Current.ProfileSystem.CommerceOleDbProvider;
Recordset queryResults = csoledb.Execute(cmdText, out recordsAffected, options);
try
{
using (OleDbDataAdapter adapter = new OleDbDataAdapter())
using (DataSet ds = new DataSet())
{
ds.Locale = CultureInfo.CurrentCulture;
adapter.Fill(ds, queryResults, "table");

List<string> currencyCodeList = new List<string>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
currencyCodeList.Add((string)dr[0]);
}

return currencyCodeList.AsReadOnly();
}
}
finally
{
Marshal.ReleaseComObject(queryResults);
}
}

public static ReadOnlyCollection<OrganizationProfile> GetAll()
{
ReadOnlyCollection<string> organizationIDList = GetAllOrganizationIDs();
List<OrganizationProfile> profileList = new List<OrganizationProfile>(organizationIDList.Count);
foreach (string organizationID in organizationIDList)
{
profileList.Add(Get(organizationID));
}
return profileList.AsReadOnly();
}

#endregion

#region Public Members

public string OrganizationID
{
get
{
return this.profile[OrganizationProfilePropertyNames.OrganizationID].Value as string;
}
}

public string OrganizationName
{
get
{
return this.profile[OrganizationProfilePropertyNames.Name].Value as string;
}
}



public override string ToString()
{
return this.OrganizationID;
}

public override bool Equals(object obj)
{
OrganizationProfile organizationProfile = obj as OrganizationProfile;
return organizationProfile != null && organizationProfile.OrganizationID == this.OrganizationID;
}

public override int GetHashCode()
{
return
this.OrganizationID.GetHashCode() ^ this.OrganizationName.GetHashCode();

}

#endregion
}
}


Please guide me.

-Ram.



Re: Commerce Server 2007 Customised Organization Profile exception. - Expecting a valid class or view name. Class or view name not found.

J-P Soulieres - Cactus Commerce

Hi Ram

The name of the Organization is wrong (assuming you did not renamed it)

Your code:

public const string ProfileName = "OrganizationObject";

Should be: (should be the same name you see in the Profile Definition, Commerce Server Manager)

public const string ProfileName = "Organization";

Just tried changing that (in a blank site from the CSharpSite pup ), and your code worked fine :-)

J-P