|
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections.Generic;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Query;
using System.Data.DLinq;
using DashboardDataAccess;
namespace DashboardBusiness.Activities
{
public partial class CreateDeafultWidgetsOnPageActivity : System.Workflow.ComponentModel.Activity
{
public CreateDeafultWidgetsOnPageActivity()
{
InitializeComponent();
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
var db = DatabaseHelper.GetDashboardData();
var defaultWidgets = db.Widgets.Where( w => w.IsDefault == true ).ToList();
var widgetsPerColumn = (int)Math.Ceiling((float)defaultWidgets.Count/3.0);
var row = 0;
var col = 0;
foreach( Widget w in defaultWidgets )
{
var newWidget = new WidgetInstance();
newWidget.PageId= this.PageId;
newWidget.ColumnNo = col;
newWidget.OrderNo = row;
newWidget.CreatedDate = newWidget.LastUpdate = DateTime.Now;
newWidget.Expanded = true;
newWidget.State = string.Empty;
newWidget.Title = w.Name;
newWidget.VersionNo = 1;
newWidget.WidgetId = w.ID;
newWidget.State = w.DefaultState;
db.WidgetInstances.Add(newWidget);
row ++;
if( row >= widgetsPerColumn )
{
row = 0;
col ++;
}
}
db.SubmitChanges();
return ActivityExecutionStatus.Closed;
}
public static DependencyProperty PageIdProperty = DependencyProperty.Register("PageId", typeof(System.Int32), typeof(DashboardBusiness.Activities.CreateDeafultWidgetsOnPageActivity));
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[BrowsableAttribute(true)]
[CategoryAttribute("Misc")]
public Int32 PageId
{
get
{
return ((int)(base.GetValue(DashboardBusiness.Activities.CreateDeafultWidgetsOnPageActivity.PageIdProperty)));
}
set
{
base.SetValue(DashboardBusiness.Activities.CreateDeafultWidgetsOnPageActivity.PageIdProperty, value);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.