Monday, September 15, 2014

Kendo UI - Hide Loading Spinner and Fade Animation

<style>
  #myGrid .k-loading-image {
    /*Hide loading spinner on grid refresh*/
    background-image: none!important;
  }
  #myGrid .k-loading-mask {
    /*Hide fadein() animation on grid refresh*/
    display:none!important;
    visibility:hidden!important;
    background-color: transparent!important;
    opacity: 0.0!important;
    height: 0px!important;
    overflow: hidden!important;
  }
</style>

Wednesday, September 3, 2014

Twitter and Facebook Links to Share URLs from an email

Twitter Share This Link:
Text or Image tag
Replace [[Twitter URL]] with the following:
http://www.twitter.com/share?url=[[My URL]]

Facebook Share This Link:
Text or Image tag
Replace [[Facebook URL]] with the following:
http://www.facebook.com/share.php?u=[[My URL]]


Replace [[My URL]] with the URL you wish to share.
Make sure you Character Encode your [[My URL]] text:
http://meyerweb.com/eric/tools/dencoder/

Monday, September 1, 2014

Setup an MVC 5 Razor Site with WebAPI in 3 Minutes

The purpose of this tutorial is to provide a quick walkthrough on how to setup a single project which will house both an MVC 5 site and a JSON WebAPI.  For more information on this scaffolding, look for tutorials on One ASP.NET.

Using Visual Studio 2013:

Select: New Project --> Visual C# --> Web --> ASP.NET MVC 5 Web Application

Give your Project a Friendly Name.
Browse to a good location for your Local Workspace.
Click Create.

Your MVC 5 application will scaffold and load into Visual Studio.
Click RUN.

Your project should compile and you should see a Sample Website in your browser.
Click STOP.

Right Click on your Project in Solution Explorer.
Select: Add --> Folder.
Name the folder Controllers.API (this important step will create a namespace container for your API controllers).
Right-click the Controllers.API folder.
Select: Add --> New Scaffolded Item.
Select: Common --> MVC --> WebAPI --> Web API 2 Controller......
    (NOTE:  If you do not have the WebAPI option, you will need to install a NuGet package for Microsoft ASP.NET Web API 2.2)
Click ADD.

Open App_Start/WebApiConfig.cs.
Paste the following into the Register() method:

            //Use JSON instead of XML
            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

***Please refer to other tutorials on how to build out an MVC 5 app, WebAPI, Entity Framework, or Repository Layer.










Monday, August 18, 2014

Override WinForms Scaling for High DPI Screens, VB.NET

    Public Shared Sub ScaleForm(WindowsForm As System.Windows.Forms.Form)
        Using g As System.Drawing.Graphics = WindowsForm.CreateGraphics
            Dim sngScaleFactor As Single = 1
            Dim sngFontFactor As Single = 1
            If g.DpiX > 96 Then
                sngScaleFactor = g.DpiX / 96
                'sngFontFactor = 96 / g.DpiY
            End If
            If WindowsForm.AutoScaleDimensions = WindowsForm.CurrentAutoScaleDimensions Then
                'ucWindowsFormHost.ScaleControl(WindowsForm, sngFontFactor)
                WindowsForm.Scale(sngScaleFactor)
            End If
        End Using
    End Sub

Friday, April 25, 2014

SQL Server - Recursively Find all Parents and Children in a Table with Parent Child Relationships

The first of the two SQL scripts, below, will return a list of all Parent rows for any table with a Parent/Child relationship.  The second will return a list of Child rows.



--Get Parent Row IDs (example: Table=WebMenu, ID=MenuID, ParentID=ParentMenuID)

DECLARE @MenuItemID INT;
SET @MenuItemID = 1001;

WITH MenuParentList AS (

    SELECT MenuID, ParentMenuID
    FROM WebMenu
    WHERE MenuID = @MenuItemID

    UNION ALL
   
    SELECT e1.MenuID, e1.ParentMenuID
    FROM WebMenu e1
    INNER JOIN MenuParentList e2 ON e2.ParentMenuID = e1.MenuID
)

SELECT *
FROM MenuParentList OPTION (MAXRECURSION 25)
GO

--Get Child Row IDs (example: Table=WebMenu, ID=MenuID, ParentID=ParentMenuID)

DECLARE @MenuItemID INT;
SET @MenuItemID = 1001;

WITH MenuChildList AS (

    SELECT MenuID, ParentMenuID
    FROM WebMenu
    WHERE MenuID = @MenuItemID

    UNION ALL
  
    SELECT e1.MenuID, e1.ParentMenuID
    FROM WebMenu e1
    INNER JOIN MenuChildList e2 ON e2.MenuID = e1.ParentMenuID
)

SELECT *
FROM MenuChildList  OPTION (MAXRECURSION 25)
GO



Saturday, January 25, 2014

Fix AutoScale In Windows Forms

System.Windows.Forms.AutoScaleMode.None
System.Windows.Forms.AutoScaleMode.Dpi
System.Windows.Forms.AutoScaleMode.Font
System.Windows.Forms.AutoScaleMode.Inherit

Some pieces of your Windows.Forms application may scale differently than other pieces.  Here are some simple tricks to force Windows.Forms to scale the way you want them to.

1.  Put your form elements inside a TableLogoutPanel.  Controls inside this panel will inherit better scaling than controls on their own.

2.  Use the same AutoScaleMode on all parts of your application.

3.  When AutoScale does not work the way you want it to, create your own scaler.
  • Set all your Windows.Forms to System.Windows.Forms.AutoScaleMode.None
  • Use the following to scale your Forms:
    Private Sub LoadedInitally(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.LoadedInitally
        If mobj_WindowsForm IsNot Nothing Then

            Using g As System.Drawing.Graphics = mobj_WindowsForm.CreateGraphics
                Dim sngScaleFactor As Single = 1
                If g.DpiX > 96 Then
                    sngScaleFactor = g.DpiX / 96
                End If
                If mobj_WindowsForm.AutoScaleDimensions = mobj_WindowsForm.CurrentAutoScaleDimensions Then
                    mobj_WindowsForm.Scale(sngScaleFactor)
                End If
            End Using

        End If
    End Sub

Tuesday, January 14, 2014

Get All Methods in a Class (VB)

Public Shared Function GetMethodInfoList(ByRef objClass As Type) As List(Of System.Reflection.MethodInfo)
'get the methods of the object.
Dim objList As New List(Of System.Reflection.MethodInfo)

Dim objClassProperties() As System.Reflection.MethodInfo 'array of methodinfo.
objClassProperties = objClass.GetMethods()

Dim objMethodItem As System.Reflection.MethodInfo

For Each mi_MethodItem In objClassProperties
GetMethodParameters(objMethodItem)
Next

Return objList
End Function

Private Shared Function GetMethodParameters(ByRef objMethodInfo As System.Reflection.MethodInfo) As List(Of MyModels.NameValue)
Dim objList As New List(Of MyModels.NameValue)

Dim objParams() As System.Reflection.ParameterInfo
objParams = objMethodInfo.GetParameters()

For Each ParamItem In objParams
Dim objNameValue As New MyModels.NameValue
objNameValue.Name = ParamItem.Name
objNameValue.Value = ParamItem.ParameterType.ToString
objList.Add(objNameValue)
Next

Return objList
End Function