SiteFinity and Custom Modules - Final

by Jesse 15. May 2008 05:49

It works, I see data, it comes, it goes.  It all works.  This'll be my last posting about this for a while but ...Marathon post, GO!

From part 2 of the sitefinity adventure, we left off with controlpanel.cs, I'll continue from there.

webcontrols/admin/<controlName>Editor.cs - where you edit/change/modify your content for your control.  This is another complicated class on the surface yet very similiar in operation to controlPanel.cs.  This also contains a Methods section with CreateChildControls which is important (don't forget to wire events in this method too).  Additionally, update/save/delete methods will be added in here as private methods.   Templates is also important section yet again because you have to line up your event commands to match what your handler understands.

I<controlName>.cs I eliminated completely.  No need for it since subsonic handles the class generation.

<controlName>.cs I also elimated -- again, subsonic handles this.

<controlName>Manager.cs - module name is defined in here, along with some other minor lightweight labeling.  I removed all get/update/delete/etc calls from here, subsonic's controller class handles this.

<controlName>Module.cs - simliar to manager, lightweight and mostly a labeler.

<controlName>Provider.cs - this pulls the info you define in the web.config for your custom control.  Pay close attention to the names (string values) that grab this info, otherwise expect some nasty "I can't find this!" errors.

A quick recap on the classes.  Well, the important/involved ones.  Admin/<controlName>Editor.cs and Admin/ControlPanel.cs require a lot of focus.  The override method "CreateChildControls()" needs to have all things necessary for that on-the-fly usercontrol to operate including events for button clicks and the like.  The Template section defines what shows up where via the container region with what names of what controls when childControls does its magic.  The rest on a really high level view is labeling and correct text pointing to the new control.

So onto the fun stuff, how do you make subsonic work with sitefinity?  It's not nearly as hard as you'd think, thanks to the <Table>Controller.  This ties right up to an ObjectDataSource real easy like.  First you find your objectdatasource that looks something like this from the contacts example...

ObjectDataSource dataSource = new ObjectDataSource();
dataSource.ID =
"ContactsDataSource";
dataSource.TypeName =
"Sample.Contacts.ContactsManager";
dataSource.SelectMethod = "GetContacts";
dataSource.DeleteMethod =
"DeleteContact";
dataSource.DeleteParameters.Add(
"id", Guid.Empty.ToString());
this.container.Controls.Add(dataSource);

and switch it out to something like this...

ObjectDataSource datasource = new ObjectDataSource();
datasource.ID =
"SubsonicDataSource";
datasource.TypeName =
"MyNamespace.Data.MyTableObjectController";
datasource.SelectMethod =
"FetchAll";
datasource.DeleteMethod =
"Delete";
datasource.DeleteParameters.Add(
"id", Guid.Empty.ToString());
this.Controls.Add(datasource);

And thats it, it's good to go.  You can find these methods within the controller object and if you've used subsonic at all, you know these already without looking.  From there, some wiring needs done for the save events and things of that nature...here's an update example pulled from the <controlName>Editor.cs, in this case, my example is a "SalesStat" ....

private void Button_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{

case "Cancel":

this.OnCanceled(EventArgs.Empty);
base.ChildControlsCreated = false;
break;

case "Save":

if (this.salesStatId == Guid.Empty)
{

CreateNewSalesStat();
this.OnSaved(EventArgs.Empty);
base.ChildControlsCreated = false;

}
else
{

this.UpdateSalesStat();
this.OnSaved(EventArgs.Empty);
base.ChildControlsCreated = false;

}
break;

}

private void CreateNewSalesStat()
{

salesStatData = new QSalesStat();
salesStatData.SalesStat =
this.container.SaleDollarAmount.Text;
salesStatData.Save();

}

Very easy to do.  I'm becoming a huge fan of subsonic :-)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Like the description says, at my core, I'm a scientist and engineer.  I came from humble beginnings on a 486DX2 Packard Hell playing doom2 on IPX to in a small time retail shop and got into hardware (ISO layers FTW!) and it was all downhill from there.  I'm infinitely curious about almost everything and always wanting to know.

Some of the stuff I'm currently into/researching...

Sitefinity

Ninject

Subsonic

Java

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's, their brother nor their dog's view in anyway.  At all.  Ever.

© Copyright 2007-2008