Extended User Data again and again...

This post has 41 Replies | 4 Followers

Top 75 Contributor
Posts 294
Points 4,195

Well, right now, I'm hung up on the databind in the subform. I'm just not sure how to handle it. I had a subform that I was using for extended attributes, but I'm not sure how to modify it for all of these new attributes. Here is what I'm at so far:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 CommunityServer.Controls;
using CommunityServer.Components;

namespace CommunityServer.Controls

{

public class ExtendUserProfile : WrappedSubFormBase

{

// storage for the reference to the extended attributes
 RadioButtonList Gender;
TextBox Birthday;
TextBox StreetAddress;
TextBox City;
DropDownList State;
TextBox PostalCode;
DropDownList Country;

// this property will be used to allow the theme developer to provide the ID of the DropDownList containing Countrys
public string CountryID
{
get { return (string)(ViewState["CountryID"] ?? ""); }
set { ViewState["CountryID"] = value; }
}

public string BirthdayID
{
get { return (string)(ViewState["BirthdayID"] ?? ""); }
set { ViewState["BirthdayID"] = value; }
}

public string StreetAddressID
{
get { return (string)(ViewState["StreetAddressID"] ?? ""); }
set { ViewState["StreetAddressID"] = value; }
}

public string CityID
{
get { return (string)(ViewState["CityID"] ?? ""); }
set { ViewState["CityID"] = value; }
}

public string StateID
{
get { return (string)(ViewState["StateID"] ?? ""); }
set { ViewState["StateID"] = value; }
}

public string PostalCodeID
{
get { return (string)(ViewState["PostalCodeID"] ?? ""); }
set { ViewState["PostalCodeID"] = value; }
}
public string GenderID
{
get { return (string)(ViewState["GenderID"] ?? ""); }
set { ViewState["GenderID"] = value; }
}

 

public override bool IsEnabled()
{
// permissions can also be checked here.
return true;
}

protected override void AttachChildControls()
{
// find the DropDownList that will contain Countrys
this.Country = CSControlUtility.Instance().FindControl(this, this.CountryID) as DropDownList;
this.Birthday = CSControlUtility.Instance().FindControl(this, this.BirthdayID) as TextBox;
this.Gender = CSControlUtility.Instance().FindControl(this, this.GenderID) as RadioButtonList;
this.StreetAddress = CSControlUtility.Instance().FindControl(this, this.StreetAddressID) as TextBox;
this.City = CSControlUtility.Instance().FindControl(this, this.CityID) as TextBox;
this.State = CSControlUtility.Instance().FindControl(this, this.StateID) as DropDownList;
this.PostalCode = CSControlUtility.Instance().FindControl(this, this.PostalCodeID) as TextBox;
this.Country = CSControlUtility.Instance().FindControl(this, this.CountryID) as DropDownList;

// if the DropDownList couldn't be found, throw an exception
if (this.Country == null)
throw new InvalidOperationException("The CountryID must identify a valid DropDownList to render a ExtendedUserProfileForm");

if (this.Birthday == null)
throw new InvalidOperationException("The Birthday must identify a valid TextBox to render a ExtendedUserProfileForm");

if (this.Gender == null)
throw new InvalidOperationException("The Gender must identify a valid RadioButtonList to render a ExtendedUserProfileForm");

if (this.StreetAddress == null)
throw new InvalidOperationException("The StreetAddress must identify a valid TextBox to render a ExtendedUserProfileForm");

if (this.City == null)
throw new InvalidOperationException("The City must identify a valid TextBox to render a ExtendedUserProfileForm");

if (this.State == null)
throw new InvalidOperationException("The State must identify a valid DropDownList to render a ExtendedUserProfileForm");

if (this.PostalCode == null)
throw new InvalidOperationException("The PostalCode must identify a valid TextBox to render a ExtendedUserProfileForm");

// retrieve the current selected values
string selectedValueCountry = this.Country.SelectedValue;

 

// clear and (re)populate the Country DropDownList

this.Country.Items.Clear();
this.Country.Items.Add(new ListItem("United States", "United States"));
this.Country.Items.Add(new ListItem("Argentina", "Argentina"));
this.Country.Items.Add(new ListItem("Australia", "Australia"));
this.Country.Items.Add(new ListItem("Austria", "Austria"));
this.Country.Items.Add(new ListItem("Bahamas", "Bahamas"));
this.Country.Items.Add(new ListItem("Belgium", "Belgium"));
this.Country.Items.Add(new ListItem("Brazil", "Brazil"));
this.Country.Items.Add(new ListItem("Canada ", "Canada"));
this.Country.Items.Add(new ListItem("Chile", "Chile"));
this.Country.Items.Add(new ListItem("China", "China"));
this.Country.Items.Add(new ListItem("Cyprus", "Cyprus"));
this.Country.Items.Add(new ListItem("Denmark", "Denmark"));
this.Country.Items.Add(new ListItem("Finland", "Finland"));
this.Country.Items.Add(new ListItem("France", "France"));
this.Country.Items.Add(new ListItem("Germany", "Germany"));
this.Country.Items.Add(new ListItem("Greece", "Greece"));
this.Country.Items.Add(new ListItem("Hong Kong", "Hong Kong"));
this.Country.Items.Add(new ListItem("Hungary", "Hungary"));
this.Country.Items.Add(new ListItem("Iceland", "Iceland"));
this.Country.Items.Add(new ListItem("Ireland", "Ireland"));
this.Country.Items.Add(new ListItem("Israel", "Israel"));
this.Country.Items.Add(new ListItem("Italy", "Italy"));
this.Country.Items.Add(new ListItem("Jamaica", "Jamaica"));
this.Country.Items.Add(new ListItem("Japan", "Japan"));
this.Country.Items.Add(new ListItem("Malaysia", "Malaysia"));
this.Country.Items.Add(new ListItem("Mexico", "Mexico"));
this.Country.Items.Add(new ListItem("Netherlands", "Netherlands"));
this.Country.Items.Add(new ListItem("New Zealand", "New Zealand"));
this.Country.Items.Add(new ListItem("Norway", "Norway"));
this.Country.Items.Add(new ListItem("Poland", "Poland"));
this.Country.Items.Add(new ListItem("Portugal", "Portugal"));
this.Country.Items.Add(new ListItem("Russia", "Russia"));
this.Country.Items.Add(new ListItem("Singapore", "Singapore"));
this.Country.Items.Add(new ListItem("Spain", "Spain"));
this.Country.Items.Add(new ListItem("Sweden", "Sweden"));
this.Country.Items.Add(new ListItem("Switzerland", "Switzerland"));
this.Country.Items.Add(new ListItem("Taiwan", "Taiwan"));
this.Country.Items.Add(new ListItem("United Kingdom", "United Kingdom"));
this.Country.Items.Add(new ListItem("United States", "United States"));
this.Country.Items.Add(new ListItem("Other – Caribbean", "Other – Caribbean"));
this.Country.Items.Add(new ListItem("Other – South America", "Other – South America"));
this.Country.Items.Add(new ListItem("Other- Asia", "Other- Asia"));
this.Country.Items.Add(new ListItem("Other – Europe", "Other – Europe"));
this.Country.Items.Add(new ListItem("Other", "Other"));

string selectedValueState = this.State.SelectedValue;

this.State.Items.Clear();
this.State.Items.Add(new ListItem("Alabama", "Alabama"));
this.State.Items.Add(new ListItem("Alaska", "Alaska"));
this.State.Items.Add(new ListItem("Arizona", "Arizona"));
this.State.Items.Add(new ListItem("Arkansas","Arkansas"));
this.State.Items.Add(new ListItem("California", "California"));
this.State.Items.Add(new ListItem("Colorado", "Colorado"));
this.State.Items.Add(new ListItem("Connecticut", "Connecticut"));
this.State.Items.Add(new ListItem("Delaware", "Delaware"));
this.State.Items.Add(new ListItem("Florida", "Florida"));
this.State.Items.Add(new ListItem("Georgia", "Georgia"));
this.State.Items.Add(new ListItem("Hawaii", "Hawaii"));
this.State.Items.Add(new ListItem("Idaho", "Idaho"));
this.State.Items.Add(new ListItem("Illinois", "Illinois"));
this.State.Items.Add(new ListItem("Indiana", "Indiana"));
this.State.Items.Add(new ListItem("Iowa", "Iowa"));
this.State.Items.Add(new ListItem("Kansas", "Kansas"));
this.State.Items.Add(new ListItem("Kentucky", "Kentucky"));
this.State.Items.Add(new ListItem("Louisiana", "Louisiana"));
this.State.Items.Add(new ListItem("Maine", "Maine"));
this.State.Items.Add(new ListItem("Maryland", "Maryland"));
this.State.Items.Add(new ListItem("Massachusetts", "Massachusetts"));
this.State.Items.Add(new ListItem("Michigan", "Michigan"));
this.State.Items.Add(new ListItem("Minnesota", "Minnesota"));
this.State.Items.Add(new ListItem("Mississippi", "Mississippi"));
this.State.Items.Add(new ListItem("Missouri", "Missouri"));
this.State.Items.Add(new ListItem("Montana", "Montana"));
this.State.Items.Add(new ListItem("Nebraska", "Nebraska"));
this.State.Items.Add(new ListItem("Nevada", "Nevada"));
this.State.Items.Add(new ListItem("New Hampshire", "New Hampshire"));
this.State.Items.Add(new ListItem("New Jersey", "New Jersey"));
this.State.Items.Add(new ListItem("New Mexico", "New Mexico"));
this.State.Items.Add(new ListItem("New York", "New York"));
this.State.Items.Add(new ListItem("North Carolina", "North Carolina"));
this.State.Items.Add(new ListItem("North Dakota", "North Dakota"));
this.State.Items.Add(new ListItem("Ohio", "Ohio"));
this.State.Items.Add(new ListItem("Oklahoma", "Oklahoma"));
this.State.Items.Add(new ListItem("Oregon", "Oregon"));
this.State.Items.Add(new ListItem("Pennsylvania", "Pennsylvania"));
this.State.Items.Add(new ListItem("Rhode Island", "Rhode Island"));
this.State.Items.Add(new ListItem("South Carolina", "South Carolina"));
this.State.Items.Add(new ListItem("South Dakota", "South Dakota"));
this.State.Items.Add(new ListItem("Tennessee", "Tennessee"));
this.State.Items.Add(new ListItem("Texas", "Texas"));
this.State.Items.Add(new ListItem("Utah", "Utah"));
this.State.Items.Add(new ListItem("Vermont", "Vermont"));
this.State.Items.Add(new ListItem("Virginia", "Virginia"));
this.State.Items.Add(new ListItem("Washington", "Washington"));
this.State.Items.Add(new ListItem("West Virginia", "West Virginia"));
this.State.Items.Add(new ListItem("Wisconsin", "Wisconsin"));
this.State.Items.Add(new ListItem("Wyoming", "Wyoming"));

// attempt to re-set the selected value
if (this.Country.Items.FindByValue(selectedValueCountry) != null)
this.Country.SelectedValue = selectedValueCountry;if (this.State.Items.FindByValue(selectedValueState) != null)
this.State.SelectedValue = selectedValueState;

}

public override void DataBind()
{

// call the base DataBind method -- it enabled DisplayConditions and other Chameleon features

base.DataBind();

// the DataSource is automatically set to the host form's DataSource

// if it is a User object, load the user's existing brand selection

User user = this.DataSource as User;
if (user != null && !this.Page.IsPostBack)
{
this.Country.SelectedValue = user.GetExtendedAttribute("Country");

}

 

}

public override void ApplyChangesBeforeCommit(object activeObject)

{

// set the extended attribute "CountryName to the user's selected country

User user = activeObject as User;

if (user != null)

user.SetExtendedAttribute("Country", this.Country.SelectedValue);

// because these changes were made in ApplyChangesBeforeCommit, the host form will commit the changes

}

}

}

  • | Post Points: 20
Top 50 Contributor
Posts 319
Points 4,865
shakes replied on Sat, Dec 1 2007 4:25 PM

Can anyone throw out a little more info on what needs to be done to the database. What if i wanted to use seperate  tables?

peace shakes

Carolina Pulse

  • | Post Points: 20
Top 75 Contributor
Posts 294
Points 4,195

The following is a bit confusing to me. When you say that it's optional, does that mean that you can skip it completely?

"The next step is really optional depending on how you layout your data. My extended cs_UserProfile table contains ID’s that are foreign key references into other tables in my system. In my case I have an in memory cache that map these ID’s to friendly names. You could add another join to the “cs_vw_User_FullUser” view to get your friendly names from your own data if you so choose. Since I have this data in memory already, I updated the code in the file “Controls\User\UserProfileData.cs” in the method “GetPropertyValue”, to lookup the data for these ID’s from my in memory cache. This “GetPropertyValue” method is called from the Chameleon controls which I will use later in this post to show these new values on the UI. You’ll see references to “ProactiveLogic.WebFacade” which is an external project that manages my cached data. My new code is noted by the “new code” comments."

  • | Post Points: 20
Top 50 Contributor
Posts 319
Points 4,865
shakes replied on Wed, Feb 27 2008 2:07 AM

Hey northland did you ever get this figured out...i have done everything but the "this is optional part" and creating my own subform...im guessing the subform is a manditory addition...in my instance i just have some bool values that i need to pass using check boxes...i am hung up on how to set this up


Done so far

Added this to CommonDataProvider.cs

            // Carolina Pulse Restaurant Style
            user.RestaurantsPizza = Convert.ToBoolean(dr["RestaurantsPizza"]);

Added this to SqlCommonDataProvider.cs

                    //Carolina Pulse Restaurant Style
                    myCommand.Parameters.Add("@RestaurantsPizza", SqlDbType.SmallInt).Value = upm.CurrentUser.RestaurantsPizza;

Added this to user.cs

        bool restaurantsPizza = false;
        #endregion

        public bool RestaurantsPizza
        {
            get { return restaurantsPizza; }
            set { restaurantsPizza = value; }
        }

Added a check box to the edituser.aspx

        <asp:CheckBox ID="RestaurantsPizza" runat="server" />

Added a userdata control to the profile

            <CSControl:UserProfileData runat="server" Property="RestaurantsPizza">
            <ContentTemplate>
                <CSControl:ThemeImage runat="server" AlternateText="Pizza" ImageUrl="~/images/custom/icons/resturanttype/pizza.png" />
            </ContentTemplate>
            </CSControl:UserProfileData>

I also added all the database bits in there as well...but that is about as far as i have gotten....at this point clicking save does not update any values in the database and userprofiledata control displays the image no mater what....so im guessing that the subform is my missing link and i started a new project for it....my question to you is what is the proper way to go about this what calls and references do i need? This is what i have done so far...

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 CommunityServer.Controls;
using CommunityServer.Components;

namespace CarolinaPulseControls
{
    public class PulseExtendedUserData : WrappedSubFormBase
    {
        // storage for the reference to the extended user data
        private CheckBox RestaurantsPizza;

        // this property will be used to allow the theme
        // developer to provide the ID of the CheckBox containing Restaurant Style
        public bool RestaurantsPizza
        {
            get { return (bool)(ViewState["RestaurantsPizza"] ?? ""Wink; }
            set { ViewState["RestaurantsPizza"] = value; }
        }
    }

}


....any help would be great...

peace shakes

Carolina Pulse

  • | Post Points: 20
Top 75 Contributor
Posts 294
Points 4,195

 No. I haven't been able to get this done. I decided just wait a bit and move on to something else. Got tired of banging my head against the wall. You've gotten as far as I have.

  • | Post Points: 20
Top 50 Contributor
Posts 319
Points 4,865
shakes replied on Wed, Feb 27 2008 3:56 AM

darn...well if i get it to work ill post my findings...

peace shakes

Carolina Pulse

  • | Post Points: 20
Not Ranked
Posts 40
Points 635
klim replied on Wed, Feb 27 2008 12:28 PM

 Guys, I switched to DNN. No regret at all. I'm just sorry for trashing my time with CS. All what you've been trying to achieve here during last 3 month could  be done in DNN just with $30 for a module and about 15 minutes of configuration work w/o even a line of code. We can endlessly discuss which product is better, at the same time banging our heads against the wall.  Having experience with both products, I know now, which is better for me.

Всю ночь котов душили-душили... душили-душили!
  • | Post Points: 20
Top 75 Contributor
Posts 294
Points 4,195

 dnn is nice, and i'm currently building a site using dnn, but it doesn't have member rewards points. That's a big chunk of time in development if I wanted do it myself.

  • | Post Points: 5
Top 75 Contributor
Posts 294
Points 4,195

 Hey Shakes, thought you may be interested in this thread:

http://communityserver.org/forums/t/497398.aspx

  • | Post Points: 20
Top 50 Contributor
Posts 319
Points 4,865
shakes replied on Fri, Feb 29 2008 1:07 AM

thanks for the nod northland...im glad to see that the cs folks have their ears to the ground...

Kilm…I took a look a dnn a year ago and decided against if for some reason…I cant now recall why but I did…perhaps I will give it a second look…to be fair though I have not spent 3 months trying to get this one aspect accomplished…combined it has probably been less than a day…its just that I know so little about coding in C#/asp.net that simple tasks become daunting without a guide…that’s ok though I like a challenge…


peace shakes

Carolina Pulse

  • | Post Points: 20
Top 500 Contributor
Male
Posts 84
Points 1,360