IMPORTANT CODINGS FRO DEVELOPERS

1)Get Date Function----

select day(GETDATE()-10)  Result -- 16
select month(GETDATE())   Result -- 12

select convert(varchar(11), getdate(),100)  Result -- Dec 26 2013
select convert(varchar(11), getdate(),110)  Result -- 12-26-2013
select convert(varchar(11), getdate(),120)  Result -- 2013-12-26
========================================================
2)Remove Special Character from any String----

 Function dbremovespecialcharachter(ByVal str As String) As String
        str = Replace(str, ".", Space(1))
        str = Replace(str, ",", Space(1))
        str = Replace(str, "'", Space(1))
        str = Replace(str, "&", "AND")
        str = Replace(str, " of ", Space(1))
        str = Replace(str, " Of ", Space(1))
        str = Replace(str, " OF ", Space(1))
        str = Replace(str, " AND ", Space(1))
        str = Replace(str, "And", Space(1))
        str = Replace(str, " FOR ", Space(1))
        str = Replace(str, " IN ", Space(1))
        str = Replace(str, Space(3), Space(1))
        str = Replace(str, Space(2), Space(1))
        dbremovespecialcharachter = str

    End Function

=================================
3)Abrivate of any String using VB.NET---

Function colldbabrivatename(ByVal sstring As String) As String
        Dim abribiatedata() = Split(Replace(Trim(sstring), Space(2), Space(1)), Space(1))
        If UBound(abribiatedata) > 0 Then
            Dim abribiateform As String = ""
            For i = LBound(abribiatedata) To UBound(abribiatedata)
                If abribiatedata(i).Substring(0, "1") = "[" Or abribiatedata(i).Substring(0, "1") = "(" Then Exit For
                If Len(abribiatedata(i)) > 1 Then
                    If abribiateform = "" Then
                        abribiateform = abribiatedata(i).Substring(0, 1)
                        abribiateform1 = abribiatedata(i).Substring(0, 1)
                    Else
                        abribiateform = abribiateform & "" & abribiatedata(i).Substring(0, 1)
                        abribiateform1 = abribiateform1 & "." & abribiatedata(i).Substring(0, 1)
                    End If
                Else
                    If abribiateform = "" Then
                        abribiateform = abribiatedata(i)
                        abribiateform1 = abribiatedata(i)
                    Else
                        abribiateform = abribiateform & "" & abribiatedata(i)
                        abribiateform1 = abribiateform1 & "." & abribiatedata(i)
                    End If
                End If
            Next
            sstring = abribiateform
        End If
        colldbabrivatename = sstring
    End Function
======================================
4)Remove special character in long address or any string-----

Function removeaddressspecialchar(ByVal value As String) As String
        value = Replace(value, "`", Space(1))
        value = Replace(value, ",,", ",")
        value = Replace(value, "'", ",")
        value = Replace(value, "..", ".")
        value = Replace(value, ".,", ",")
        value = Replace(value, ",.", ",")
        value = Replace(value, ".:", "-")
        value = Replace(value, ":.", "-")
        value = Replace(value, ":,", "-")
        value = Replace(value, ",:", "-")
        value = Replace(value, "-:", "-")
        value = Replace(value, ":-", "-")
        value = Replace(value, ": -", "-")
        value = Replace(value, "- :", "-")
        value = Replace(value, ":", "-")
        value = Replace(value, " :", "-")
        value = Replace(value, ": ", "-")
        While value.Substring(0, 1) = "," Or value.Substring(0, "1") = "'" Or value.Substring(0, "1") = "`"
            value = value.Substring(0, Len(value) - 1)
            If value = "" Then Exit While
        End While
        value = Replace(value, "DIST", "DIST-")
        If value <> "" Then
            While value(value.Length - 1) = "." Or value(value.Length - 1) = "," Or value(value.Length - 1) = ":" Or value(value.Length - 1) = "'" Or value(value.Length - 1) = ":" Or value(value.Length - 1) = "" Or value(value.Length - 1) = ",," Or value(value.Length - 1) = ", ,"
                value = Trim(value).Substring(0, Len(value) - 1)
                If value = "" Then Exit While
            End While
        End If
        value = Replace(value, Space(2), Space(1))
        removeaddressspecialchar = value
    End Function
=======================================
5)Match any string based on key matching and phone matching or abrivate matching---

 If MsgAgrid.Rows.Count = 0 Then Exit Sub
        If MsgAgrid.Rows(0).Cells("COLLEGE NAME").Value = "" Then Exit Sub
        Application.DoEvents()
        Me.Cursor = Cursors.WaitCursor
        Dim greencount As Integer = 0
        txtcollegename.Text = ""
        For i = 0 To msgDivgrid.Rows.Count - 1
            msgDivgrid.Rows(i).Cells(2).Style.BackColor = Color.White
            msgDivgrid.Rows(i).Cells("Phone1").Value = ""
            msgDivgrid.Rows(i).Cells("Select").Value = ""
            msgDivgrid.Rows(i).Cells("option").Value = ""
            msgDivgrid.Rows(i).Cells("sort").Value = ""
        Next
        Dim mykeys() As String
        ReDim mykeys(Grid1.Rows.Count - 1)
        'newcolegeprin(0) = ""
        'Dim mycond As String = ""
        Dim newdata() As String = Split(MsgAgrid.Rows(Text2.Text).Cells("College Phone1").Value, ",")
        Dim k As Integer = 0
        Dim j As Integer
        For i = 0 To Grid1.Rows.Count - 1
            If Grid1.Rows(i).Cells("SELECT").Value = "P" And Len(Grid1.Rows(i).Cells("college_name_keyword").Value) > 2 Then
                ''abrivate name match-cyne
                If i = 0 Then
                    For j = 0 To msgDivgrid.Rows.Count - 1
                        If Trim(UCase(msgDivgrid.Rows(j).Cells("Abrivate Name").Value)) = Grid1.Rows(i).Cells("College_Name_Keyword").Value Then
                            msgDivgrid.Rows(j).Cells("COLLEGE NAME").Style.BackColor = Color.Cyan
                            msgDivgrid.Rows(j).Cells("sort").Value = "1"
                            mykeys(i) = Grid1.Rows(i).Cells("college_name_keyword").Value
                            Exit For
                        End If
                    Next
                Else
                    For j = 0 To msgDivgrid.Rows.Count - 1
                        If Trim(UCase(msgDivgrid.Rows(j).Cells("COLLEGE NAME").Value)).Contains(Grid1.Rows(i).Cells("College_Name_Keyword").Value) = True Then
                            msgDivgrid.Rows(j).Cells("COLLEGE NAME").Style.BackColor = Color.Cyan
                            msgDivgrid.Rows(j).Cells("sort").Value = "1"
                            mykeys(i) = Grid1.Rows(i).Cells("college_name_keyword").Value
                        End If
                    Next
                End If
            End If
        Next
        Dim mstph() As String
        For j = 0 To msgDivgrid.Rows.Count - 1
            If msgDivgrid.Rows(j).Cells("Phone").Value.trim <> "" Then
                mstph = msgDivgrid.Rows(j).Cells("Phone").Value.ToString.Split(",")
                For acnt As Integer = 0 To newdata.Length - 1
                    For mcnt = 0 To mstph.Length - 1
                        If Trim(newdata(acnt)).Contains(mstph(mcnt)) Then
                            msgDivgrid.Rows(j).Cells("Phone").Style.BackColor = Color.OrangeRed
                            msgDivgrid.Rows(j).Cells("sort").Value = "1"
                        End If
                    Next

                Next
            End If
        Next
        msgDivgrid.Sort(msgDivgrid.Columns("sort"), System.ComponentModel.ListSortDirection.Descending)

        For j = 0 To msgDivgrid.Rows.Count - 1
            If msgDivgrid.Rows(j).Cells("sort").Value = "1" Then
                If mykeys.Length <= 7 Then
                    If Trim(msgDivgrid.Rows(j).Cells(3).Value).ToUpper = mykeys(0) Then
                        If mykeys(1) <> Nothing Then
                            If Trim(msgDivgrid.Rows(j).Cells(2).Value).ToUpper.Contains(mykeys(1)) Then
                                If mykeys(2) <> Nothing Then
                                    If Trim(msgDivgrid.Rows(j).Cells(2).Value).ToUpper.Contains(mykeys(2)) Then
                                        msgDivgrid.Rows(j).Cells("COLLEGE NAME").Style.BackColor = Color.Pink
                                        msgDivgrid.Rows(j).Cells("sort").Value = "2"
                                    End If
                                Else
                                    msgDivgrid.Rows(j).Cells("COLLEGE NAME").Style.BackColor = Color.Pink
                                    msgDivgrid.Rows(j).Cells("sort").Value = "2"
                                End If
                            End If
                        Else
                            msgDivgrid.Rows(j).Cells("COLLEGE NAME").Style.BackColor = Color.Pink
                            msgDivgrid.Rows(j).Cells("sort").Value = "2"
                        End If
                    End If
                End If
            End If
        Next
        msgDivgrid.Sort(msgDivgrid.Columns("sort"), System.ComponentModel.ListSortDirection.Descending)
     
        For j = 0 To msgDivgrid.Rows.Count - 1
            If msgDivgrid.Rows(j).Cells("sort").Value = "1" Then
                If msgDivgrid.Rows(j).Cells("COLLEGE NAME").Style.BackColor = Color.Cyan And msgDivgrid.Rows(j).Cells("phone").Style.BackColor = Color.OrangeRed Then
                    msgDivgrid.Rows(j).Cells("sort").Value = "3"
                End If
            End If
        Next
        msgDivgrid.Sort(msgDivgrid.Columns("sort"), System.ComponentModel.ListSortDirection.Descending)
        Me.Cursor = Cursors.Default
===========================================================
6)Select only one value from gridview using vb.net---

 If e.ColumnIndex = 9 And e.RowIndex <> -1 Then
            If msgDivgrid.Rows(e.RowIndex).Cells("Select").Value = "P" Then
                msgDivgrid.Rows(e.RowIndex).Cells("Select").Value = ""
                Exit Sub
            End If
            For i = 0 To msgDivgrid.Rows.Count - 1
                msgDivgrid.Rows(i).Cells("Select").Value = ""
            Next
            msgDivgrid.Rows(e.RowIndex).Cells("Select").Style.Font = New Font("Wingdings 2", 8, FontStyle.Bold)
            msgDivgrid.Rows(e.RowIndex).Cells("Select").Value = "P"
        End If
=====================================================
7)Null value ----if true or not
 dt1.Rows(i).Item("hoifax") = IIf(IsDBNull(dt1.Rows(i).Item("hoifax")), "", dt1.Rows(i).Item("hoifax"))
==========================
8)To remove particular  index value in gridview using vb.net--
  MsgAgrid.Rows.RemoveAt(Text2.Text)
========================================================

No comments:

Post a Comment

Followers