Tuesday, 2 December 2014

Add Events for form field on web event handler

Blackbaud CRM 

I have made a web event handler, in this web event handler, i need to grab the event of any field. For instance if use “Enhance Event Handler” . In this event handler, I want to change any field value or want to do any sort of change whether to select data from database, anything I want then the first question arises in my mind how I can handle the vent handler. See below lines taken from web event handler

Private Sub BatchCommitmentUpdateHandler_AfterLoad(sender As Object, e As EventArgs) Handles Me.AfterLoad
        With Me.FieldChangedHandlers
            '' If Commitment lookup id is selected then it will get the commitment details from the DATAFORMID_COMMITMETINFO
            ''form and load all single values along with the collection values
            If FieldIsDefined("CONSTITUENTID") Then
                .Add("PRIMARYRECORDID", AddressOf GetConstituentExtensionData)
            End If
        End With
    End Sub

Private Sub GetConstituentExtensionData (ByVal e As FieldEventArgBase)
‘ Implement the custom logic here
End Sub

Now if you debug the batch event handler whenever you change any constituent, it will push the implementation into the “GetConstituentExtensionData” method. And in this method you can do anything you want.
There is another event “CellChanged” event in web event handler, using this event, you can also accomplish this thing but according to it will cause extra overhead on implementation because this event will trigger when user will change any event and check for every field. So the best way to define the event in webevent handler is the above one.


Enable or visible any field or get dynamic data on page level based on expression view



Blackbaud CRM 

I have a scenario, for instance, we need any action on page needs to enable or set its visibility or sometime we need some dynamic data in on page level,whether there would be a condition that on any Action, we need to set a dynamic caption . So in this case, we want expression view form to be included on page level.If you see below lines which was taken from OOB Event page

<PageDefinitionSpec
    ID="9988b807-97b2-434c-8be1-bbee6b944b2c"
    Name="Event Page"
    Description="Displays information about an event."
    Author="Blackbaud Product Development"
    ExpressionDataFormID="03e8fbdc-7e2c-496d-8322-405fcff75854"
    ContextRecordType="Event"
    AutoGenerateKpiActions="true"
    xmlns="bb_appfx_pagedefinition"
    >



So if you see in above Page definition, expressiondataformid has mentioned . This is OOB expression view form. I have now copied a single action from OOB Event page and paste this one, please see below lines

 <Action ID="b16c5a1a-cb3f-404b-bfa4-2248c254f56b" Caption="Delete" ImageKey="RES:Delete" Visible="=(Fields!ID = Page.Fields!EVENTID.ToString()) AndAlso (Products.ProductIsInstalled(InstalledProducts.FriendsAskingFriends) And Not Products.ProductIsInstalled(InstalledProducts.Enterprise))" Enabled="=CBool(Fields!USERHASSITEACCESS)" CaptionResourceKey="$$delete">
            <ExecuteRecordOperation RecordOperationID="c822c9bb-a7df-4a92-a1b5-54d2dfeeb2b8" xmlns="bb_appfx_commontypes">
              <ActionContext>
                <SectionField>ID</SectionField>
              </ActionContext>
              <PostActionEvent>
                <GoToPage>
                  <FunctionalArea FunctionalAreaID="69df5ab2-b48b-4da2-8d25-c053eb6ac6f2" />
                </GoToPage>
              </PostActionEvent>
            </ExecuteRecordOperation>
            <HelpKey>EVDeleteEvents.html</HelpKey>
          </Action>



You can see above Action code yellow highlighted area, It uses viewdataform expression field to set the visibility of any action.

Now if you have a requirement that any custom action needs to be added into the Event Page and its visibility will control dynamically based on some dynamic field which was not previously included in OOB expression view form then we need to make a new viewdataform and this new viewdataform would use as an extension of OOB view dataform .This will work but the important thing is to add this expression view data form into the page level, see below screen shot


 



 If you see in above image, there are multiple expression view form added on single page. In this way we can get the dynamic data based on this we will set any field dynamic on page level .We can get the page level fields with "Page.Field!" prefix .

Add a Link button on Viewdataform

Blackbaud CRM 

If i have a Event page and in the top of the page, we have summary view form. In this View form, i need to add a link which will redirect to the selected event . See below image for some help














Now if you see i have added a Linkbutton which is not included in OOB .And the scenario is to add this linkbutton into child event not in main event . If you will search for any event then if that event is Main event then this link button and its label would be visible off else it will show in child event .

First of all, i added a Viewdataformspec and in this spec, i used below Stored Procedure

<SPDataForm SPName="USR_USP_DATAFORMTEMPLATE_VIEW_EVENTSUMMARYEXT">
    <common:CreateProcedureSQL>
      <![CDATA[
create procedure dbo.USR_USP_DATAFORMTEMPLATE_VIEW_EVENTSUMMARYEXT
(
@ID uniqueidentifier,
@DATALOADED bit = 0 output,
@PARENTEVENTID uniqueidentifier = null output,
  @PARENTEVENTNAME nvarchar(255) = null output
)
as
set nocount on;

-- be sure to set this, in case the select returns no rows
set @DATALOADED = 0;

-- populate the output parameters, which correspond to fields on the form.  Note that
-- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system
-- will display a "no data loaded" message.
select
     @DATALOADED = 1,
     @PARENTEVENTID = E.MAINEVENTID,
     @PARENTEVENTNAME = ME.NAME
from dbo.EVENT as E
  left join dbo.EVENT ME on ME.ID = E.MAINEVENTID
where E.ID = @ID

return 0;
]]>
    </common:CreateProcedureSQL>


And in form field i just include both the PARENTEVENTID and PARENTEVENTNAME. I have also added UI Action, see below lines for UI Action

 <common:UIActions>
      <common:UIAction ActionID="GOTOPARENTEVENTNAME" Caption="Parent Event">
      </common:UIAction>
    </common:UIActions>

In the bottom of the page to extend the existing summary view form, i have added a standard code,

<common:DataFormExtension DataFormInstanceID="060f714a-8bf4-4bcc-90a3-a192bb9b28de"  RenderStyle="AfterParent" TabCaption="Parent Information" />

Now after this, UI model generated . In HTML pafe generated in UI Model, i have made some alteration. see below HTML code. I am just pasting the main table entry from HTML page

 <table>
        <tr id="#MAP#PARENTEVENTNAME_container">
            <td>
                <span id="#MAP#PARENTEVENTNAME_caption" class="bbui-forms-captionlight"> </span>
            </td>
            <td>

                <a id="#MAP#GOTOPARENTEVENTNAME_action"></a>
            </td>
        </tr>
        <tr style="display:none">
            <td></td>
            <td>

                <!--<button id="#MAP#GOTOPARENTEVENTNAME_action"></button>-->
            </td>
        </tr>
    </table>

If you see in above HTML, i have commented out the button tag and take the UI Action button Id and replace with PARENTEVENT and also replace the SPAN tag with the Anchor tag. See red highlighted text area in above HTML.

After that i have made some changes in VB class .Please see the below mentioned lines

 Private Sub EventSummaryExtViewCustomDataFormUIModel_Loaded(ByVal sender As Object, ByVal e As Blackbaud.AppFx.UIModeling.Core.LoadedEventArgs) Handles Me.Loaded
        If _parenteventid.Value <> Guid.Empty Then
            _gotoparenteventname.Caption = _parenteventname.Value
        Else
            _gotoparenteventname.Visible = False
            _parenteventname.Visible = False
        End If


    End Sub

    Private Sub _gotoparenteventname_InvokeAction(sender As Object, e As InvokeActionEventArgs) Handles _gotoparenteventname.InvokeAction
        'Navigate to Event page with parameter parent event id
        NavigateToPage(Guid.Parse("9988b807-97b2-434c-8be1-bbee6b944b2c"), Me._parenteventid.Value.ToString())
    End Sub


There are 2 events above, first one is load event in which i decided whether the event is main event or child event and based on condition it will decides its visibility . In second event which is UI Action button event handler. I have used "NavigateToPage" method which takes the page Id and Context Id to take the user into the selected page.


Thursday, 29 May 2014

c # using linq to group by multiple columns in a datatable also using order by



   var objectTable = new DataTable();
            objectTable.Columns.Add("resource_name", typeof(string));
            objectTable.Columns.Add("day_date", typeof(DateTime));
            objectTable.Columns.Add("actual_hrs", typeof(decimal));
            objectTable.Rows.Add(1, DateTime.Today, 1);
            objectTable.Rows.Add(2, DateTime.Today, 2);

            var newSort = from row in objectTable.AsEnumerable()
                          where row.Field<string>("resource_name") == "1"
                          orderby row.Field<string>("resource_name") descending
                          group row by new { ID = row.Field<string>("resource_name"), time1 =             row.Field<DateTime>("day_date") } into grp
                          select new
                          {
                              resource_name1 = grp.Key.ID,
                              day_date1 = grp.Key.time1,
                              Sum = grp.Sum(r => r.Field<Decimal>("actual_hrs"))
                          };
            //newSort.Dump();


            foreach (var array in newSort)
            {
                // newDataTable.Rows.Add(array);
            }

Friday, 27 January 2012

SQL SERVER – Simple Example of Recursive CTE

Table name is WorkFlow :
 In the above table every workflow step contains its next step Id .So i want to get the record in which sequence starts from initial state and iterates to final step. For this Recursive CTE is the best solution in SQL SERVER

Query tro fetch the sequence is


WITH Emp_CTE AS (
SELECT WorkFlowId ,Name ,NextSteps, 0 As Level1
FROM WorkFlow
WHERE NextSteps IS NULL


UNION ALL
SELECT e.WorkFlowId ,e.Name ,e.NextSteps,ecte.Level1 + 1
FROM WorkFlow e
INNER JOIN Emp_CTE ecte ON ecte.WorkFlowId = e.NextSteps
)
SELECT *
FROM Emp_CTE
order by level1 desc
GO


Result set given below

Thursday, 22 December 2011

Joins in LINQ to SQL

The following post shows how to write different types of joins in LINQ to SQL. I am using the My Sample database and LINQ to SQL for these examples


SampleDbDataContext dataContext = new SampleDbDataContext();



Inner Join :-
var q1 = from b in dataContext.Blogs
join c in dataContext.Comments on b.BlogId equals c.BlogId
select new
{
b.BlogId,
b.BlogTitle,
b.BlogDescription,
c.CommentsId,
c.CommentDescription
};
Above LINQ In SQL
SELECT [b].[BlogId], [b].[BlogTitle], [b].[BlogDescription], [c].[CommentsId],[c].[CommentsDescription]
FROM [dbo].[Blogs] AS [b]
INNER JOIN [dbo].[Comments] AS [c] ON [b].[BlogId] = [c].[BlogId]

Left Join :-
var q2 = from b in dataContext.Blogs
join c in dataContext.Comments on b.BlogId equals c.BlogId into g
from s in g.DefaultIfEmpty()
select new
{
b.BlogId,
b.BlogTitle,
b.BlogDescription,
s.CommentsId,
s.CommentDescription
};
Above LINQ In SQL
SELECT [b].[BlogId], [b].[BlogTitle], [b].[BlogDescription], [c].[CommentsId],[c].[CommentsDescription]
FROM [dbo].[Blogs] AS [b]
LEFT OUTER JOIN [dbo].[Comments] AS [c] ON [b].[BlogId] = [c].[BlogId]

Wednesday, 21 December 2011

LinkedIn button on profile page

Something you may want to do, if you have a LinkedIn account (it's free!) is to add a button in your webpage or blog to make it easier for people to see your LinkedIn profile.

Here's how to find the button and code to paste into your site.

1. Go to your Profile page in LinkedIn
2. Click "My Profile"
3. Click on "Edit Public Profile Settings" (on the top right of the page)
4. Click "Promote your profile with customized buttons"
5. Pick a button, copy the code

or easier yet: http://www.linkedin.com/profile?promoteProfile=

Also, make sure your profile is not set to Private. Make it viewable to the world.

For users of Blogger, where to place the button.

In Blogger, you have to go to the Layout tab, click on "Add a Gadget" and add an "HTML/JavaScript" section where you paste the code. Title section is not mandatory.