MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

How to extend EventModule web part?  (Mono Support )

Viewed 6616 time(s), 5 post(s) 4/13/2012 12:45:36 PMby Jeremy
Jeremy

Jeremy

4/13/2012 12:59:32 PM
I would like to extend the EventModule web part and have tried using the following code. I have added the path to my files in the web.config with <add key="ModuleGalleryPath" value="/MonoX/ModuleGallery, /Cabin/ModuleGallery"/>. The extended web part appears in the Main part catalog correctly, but when I drop it into a page I get the error attached.

Could someone let me know what I am doing wrong?

EventModuleExt.aspx

<%@ Control Language="C#"
AutoEventWireup="true"
CodeBehind="EventModuleExt.ascx.cs"
Inherits="MonoSoftwareCustom.Cabin.ModuleGallery.EventModuleExt" %>

EventModuleExt.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MonoSoftware.MonoX.ModuleGallery;

namespace MonoSoftwareCustom.Cabin.ModuleGallery
{
public partial class EventModuleExt : EventModule
{
public EventModuleExt() : base()
{
AdvancedModeDefaultView = AdvancedModeView.MonthView; //Gets or sets advanced mode default view.
CalendarId = new System.Guid("8454BDA2-58B4-43FB-8F27-A02D00B827F3"); //Gets or sets calendar to display.
CalendarName = "CabinBookings"; //Gets or sets initial calendar to use.
FirstDayOfWeek = DayOfWeek.Sunday; //Gets or sets first day of the week.
IsCalendarEditable = true; //Gets or sets if calendar should be editable.
Mode = EventModuleMode.Advanced; //Gets or sets event module mode.
}

}
}

I am using MonoX v4.5.3206.40 [11/11/2011], DB v4.5.3103

[Edit] I just fixed the attached gif file as the first one cut off the top half of the error message.
This content has not been rated yet. 
322 Reputation 36 Total posts
shawndg

shawndg

4/13/2012 1:11:10 PM
I am not sure exactly by your error but here is what I can offer..

The event module is a two part system, I dont know for sure if you need to extend both in order for it to work..
I know my code is outdated because there a table change in a newer version of MonoX that breaks the code but thats a minor fix..
There is a post on the forum somewhere about how to fix this.. not had a chance to add that just yet.. but i am posting the old code below of both parts which may help you.

The MonoX guys helped me a lot with this..
I was trying to change the sort order of the event module.

EventModuleExt.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MonoSoftware.MonoX.Utilities;
using MonoSoftware.MonoX.ModuleGallery;
using MonoSoftware.MonoX;
 
namespace WebParts.EventModuleExt
{
 
        [WebPartCatalogCategory("CustomExt")]
        public partial class EventModuleExt : MonoSoftware.MonoX.ModuleGallery.EventModule
        {
 
            private DateTime _selectedDay = DateTime.Now;
            /// <summary>
            /// Gets or sets selected day so you can easily change day you want to show
            /// </summary>
            public DateTime SelectedDay
            {
                get { return _selectedDay; }
                set
                {
                    _selectedDay = value;
                }
            }
 
 
            protected override void OnInit(EventArgs e)
            {
                this.Title = "Event Module - Ascending";
 
                base.OnInit(e);
     
                // We can switch mode to simple as we're not interested in advanced mode in this case
                 Mode = MonoSoftware.MonoX.ModuleGallery.EventModuleMode.Simple;
                // No point in showing the filter
                ctlSimpleView.ShowFilter = false;
            }
 
            public override void DataBind()
            {
                // Before we bind data we need to set day we want to show
                ((EventSimpleViewExt)ctlSimpleView).SelectedDay = this.SelectedDay;
 
                base.DataBind();
            }
 
 
        }
 
    }

EventSimpleViewExt.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MonoSoftware.MonoX.ModuleGallery;
using MonoSoftware.MonoX.Controls;
using SD.LLBLGen.Pro.ORMSupportClasses;
using MonoSoftware.MonoX.DAL.HelperClasses;
using MonoSoftware.MonoX.DAL.EntityClasses;
using MonoSoftware.MonoX.Repositories;
using MonoSoftware.MonoX.Utilities;
 
namespace WebParts.EventModuleExt
{
 
        public partial class EventSimpleViewExt : MonoSoftware.MonoX.ModuleGallery.EventSimpleView
        {
 
            //prevent bug... remove next version..
            protected override void OnLoad(EventArgs e)
            {
                // TODO: Uncomment this line when MonoX is upgraded
                  base.OnLoad(e);
            }
 
            /// <summary>
            /// Gets or sets day to display
            /// </summary>
            public DateTime SelectedDay { get; set; }
 
 
            public override void DataBind()
            {
                // Fetch filter, we can ignore module filter in this case as we have full control over fetching
                IRelationPredicateBucket filter = new RelationPredicateBucket();
 
                filter.PredicateExpression.Add(CalendarEventFields.Id == this.CalendarId);
 
               // filter.PredicateExpression.Add(CalendarEventFields.CalendarId == this.CalendarId);
              //  filter.PredicateExpression.Add(CalendarEventFields.StartTime >= this.SelectedDay.Date);
             //  filter.PredicateExpression.Add(CalendarEventFields.StartTime < this.SelectedDay.Date.AddDays(1));
 
                // Set sorter, here you'll change sort direction by changing SortOperator
                ISortExpression sorter = new SortExpression(new SortClause(CalendarEventFields.StartTime, null, SortOperator.Ascending));
 
                EntityCollection<CalendarEventEntity> items = new EntityCollection<CalendarEventEntity>();
                BaseMonoXRepository.GetInstance().FetchEntityCollection(items, filter, 0, sorter, null, pager.CurrentPageIndex + 1, pager.PageSize);
                int recordCount = BaseMonoXRepository.GetInstance().GetDbCount(items, filter);
 
                PagerUtility.BindPager(pager, DataBind, lvItems, items, recordCount);
            }
 
        }
    }

This content has not been rated yet. 
1871 Reputation 252 Total posts
Jeremy

Jeremy

4/13/2012 2:14:00 PM
Thank you for your suggestion but it doesn't really apply to my situation because I am setting:
Mode = EventModuleMode.Advanced

Therefore I do not think the EventSimpleView needs to be extended.

I have looked for an EventAdvancedView to extend, but it doesn't seem to exist in the documentation available. Perhaps I need to extend EventModuleHandler instead but there is very little documentation available to point me in the right direction.

I also want to thank you for clearing up two other things for me: how to change the web part catalog category by using an attribute and setting the title:
[WebPartCatalogCategory("CustomExt")]

Title = "New Title"
This content has not been rated yet. 
322 Reputation 36 Total posts
Jeremy

Jeremy

4/15/2012 4:27:51 AM
I have worked out how to extend the EventModule web part now. This was my first attempt at extending a web part so I was a bit lost at first.

The error I was getting was caused by not including controls referenced in the code behind file for the base EventModule. Specifically, the base.OnInit() function expected to be able to set properties and call methods on controls that did not exist. I am not sure which controls were specifically needed. To get it working I copied the code from EventModule.ascx into EventModuleExt.ascx. I left in the original versions of SimpleEventView and Eventeditor. I do not have a need to extend them yet.

One thing I discovered was that if you update the title in the OnInit() method then the title will be automatically set when you add your extended web part to a page. If you update the title in the constructor then the name of the web part catalog part also gets updated.
This content has not been rated yet. 
322 Reputation 36 Total posts
khorvat

khorvat

4/16/2012 6:40:41 AM
Hi,

if you want to extend existing WebPart you will need to copy the mark-up code to you extended WebPart as it is required by the base WebPart you are extending. There are few tutorials in our Blog that describe the techniques used in extending WebParts so please take a look at one of them.

Regards
This content has not been rated yet. 
15993 Reputation 2214 Total posts