Sunday, November 18, 2012

Convert Column names to Captions

I wanted to convert a column name from the database to a caption.
E.g:
DBType  to "DB Type"
ApplicationURL to "Application URL"
This is what i did for it.
C# code

public static string ReturnColumnCaption(String f)
        {
            string s = "";
            char o = '\0';
            for (int i = 0; i <= f.Trim().Length - 1; i++)
            {
                char c = f.Substring(i, 1)[0];
                if (char.IsUpper(c))
                {
                    if (char.IsUpper(o))
                    {
                        if (i + 1 < f.Trim().Length)
                        {
                            char t = f.Substring(i + 1, 1)[0];
                            if (char.IsUpper(t))
                            {
                                s += c;
                            }
                            else
                            {
                                s += " " + c;
                            }
                        }
                        else
                        {
                            s += c;
                        }
                    }
                    else
                    {
                        s += " " + c;
                    }

                }
                else
                {
                    s += c;
                }
                o = c;
            }
            return s.Trim();
        }

VB.NET
Private Function ReturnColumnCaption(ByVal f As String) As String

        Dim s As String = ""
        Dim o As String = ""
        For i As Integer = 0 To f.Trim.Length - 1
            Dim c As Char = f.Substring(i, 1)
            If Char.IsUpper(c) Then
                If Char.IsUpper(o) Then
                    If i + 1 < f.Trim.Length Then
                        Dim t As Char = f.Substring(i + 1, 1)
                        If Char.IsUpper(t) Then
                            s += c
                        Else
                            s += " " + c
                        End If
                    Else
                        s += c
                    End If
                Else
                    s += " " + c
                End If

            Else
                s += c
            End If
            o = c
        Next
        Return s.Trim()
    End Function

Tuesday, July 17, 2012

Delete duplicate records Query

Found this query to delete duplicate records from a table. Very small query, but if table is big then it will take some time. But works

[code]


DELETE FROM [Table1
WHERE  Table1ID NOT IN SELECT MAX( Table1ID)  
FROM [ Table1GROUP BY [Col1] ,[ Col2] ,[ Col3)


[/code]

Enjoy IT!

Wednesday, May 16, 2012

Gadget Style WPF Application

I just made this from a Channel 9 Training Video.

XAML:
Type Here

Code Behind:
Class Window1

Private Sub Window1_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
Me.DragMove()
End Sub

Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
Me.Close()
End Sub
End Class

Delete entire SharePoint List Items (VB.NET)


A small problem that i faced, was to delete an entire SPList Items.
Here is the solution.

'Get Context
Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
'Open Web
Dim wb As SPWeb = siteCollection.OpenWeb()
'Get List
Dim spl As SPList = wb.GetList(wb.Url.ToString + "/Lists/YourListNameToDeleteItems")
spl.AllowDeletion = True
Try
    While spl.Items.Count > 0
        spl.Items(0).Delete()
    End While
    spl.Update()
'"Update Delete for list items"
Catch ex As Exception
End Try

Best Smartphones/tech of 2019

So I was looking for the best tech of 2019. Here it goes: New Pixel 3 XL Google - Pixel 3 XL with 64GB Memory Cell Phone (Unlocked) - ...