Tuesday, 2 December 2014

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.

Wednesday, 28 September 2011

How to find a url of Active tab from Active Internet Explore Instance

First Add new class name as IEInstance.cs

The code for this class



using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections;
public delegate bool IECallBack(int hwnd, int lParam);
namespace IEToolbarEngine
{
    public class IEInstance//Form is a class in System.Windows.Forms namespace
    {
        [DllImport("user32.Dll")]
        public static extern int EnumWindows(IECallBack x, int y);
        [DllImport("User32.Dll")]
        public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount);
        [DllImport("User32.Dll")]
        public static extern void GetClassName(int h, StringBuilder s, int nMaxCount);
        [DllImport("User32.Dll")]
        public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);

        public static ListBox lbPublic;
     
     
        private ListBox listBox1; //ListBox is a class in System.Windows.Forms namespace
        static IntPtr listBoxHandle;// IntPtr is a class in System namespace
        static IntPtr windowHandle;
        static StringBuilder sb, sbc;
        static int i = 0;
        static ArrayList myAl;

        public IEInstance() //Constructor
        {
            InitializeComponent();
        }

        #region Windows Form Designer generated code
        private void InitializeComponent()
        {
           // this.GetIE = new System.Windows.Forms.Button();
            this.listBox1 = new System.Windows.Forms.ListBox();
            myAl = new ArrayList();
        }
        #endregion

        public void GetIEButton()
        {
            listBoxHandle = listBox1.Handle;
            EnumWindows(new IECallBack(IEInstance.EnumWindowCallBack), (int)listBoxHandle);
       
        }

        private  static bool EnumWindowCallBack(int hwnd, int lParam)
        {
            windowHandle = (IntPtr)hwnd;
            listBoxHandle = (IntPtr)lParam;
            lbPublic = (ListBox)ListBox.FromHandle(listBoxHandle);
            sb = new StringBuilder(1024);
            sbc = new StringBuilder(256);
            GetClassName(hwnd, sbc, sbc.Capacity);
            GetWindowText((int)windowHandle, sb, sb.Capacity);
            int ind = sb.ToString().IndexOf("- Microsoft");
                if (ind ==-1)
                    ind = sb.ToString().IndexOf("- Windows");
            String xMsg2 = string.Empty;
            if (ind != -1)
                xMsg2 = sb.ToString().Substring(0,ind - 0) + " " + windowHandle;
            else
                xMsg2 = sb + " " + windowHandle;
            String xMsg = windowHandle.ToString();
            if (sbc.Length > 0)
            {
                if (sbc.ToString().Equals("IEFrame"))
                {
                    myAl.Add(windowHandle);
                    i++;
                    if (lbPublic.Items.Count < 1)
                        lbPublic.Items.Add(xMsg2);
                }
            }
            return true;
        }

   
    }
}




------
I have inherited this class with form class .In "lbPublic"  .This is a ListBox type . After executing this class your lbPublic will fill the active tab title + handler of the tab. You will just add this whole code in your class file ,no need to extent more.

Now , for the sample Add a form in which you will call the above class method GetIEButton();
In a form include a COM component reference MICROSOFT HTML OBJECT LIBRARY.

After adding reference include Add the below line the using area
using mshtml;

Now in the form Load method



private void Form1_Load(object sender, EventArgs e)
        {
       
        //// Below is the IEInstance class object
           IEInstance ieButton = new IEInstance();
            ieButton.GetIEButton();


            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
            string filename = string.Empty; ;

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                mshtml.IHTMLDocument2 htmlDoc = ie.Document as mshtml.IHTMLDocument2;
                if (htmlDoc != null)
                {
                    string strIe = htmlDoc.title + "  " + ie.HWND.ToString();
                    //htmlDoc = (HTMLDocument)axWebBrowser1.Document;
                    if (filename.Equals("iexplore"))
                    {
                     
                            if (IEInstance.lbPublic.Items[0].ToString() == strIe)
                            {
                                filename = ie.LocationURL;

                                //  break;
                                goto NewLine;
                            }

                     
                    }
                }

                //Console.WriteLine( &quot;Web Site   : {0}", ie.LocationURL );

                if (filename.Equals("explorer&quot;"))
                    Console.WriteLine("Hard Drive : {0}", ie.LocationURL);
            }

        NewLine:
            int i2 = 0;
            MessageBox.Show(filename);

       }


This is in working state .now you will get thr url of active tab of active Internet Explorer .