Wednesday, August 28, 2013

Refresh The Parent Window




This is how you can refresh the Parent Window after its closed.

Page.RegisterClientScriptBlock("Refresh",
"");


Page.RegisterClientScriptBlock("check", "");


Regards,
Sheryar Nizar

Time in TextBox (From - To)

Time in TextBox (From - To)
This I made for one of my clients. Hope its useful for you

First Add the Following Javascript int he head of your ASPX


function doTxt(txt)
    {  
      t=document.getElementById(txt);
     
      if(t.value.length !=0)
      {
        if(t.value.indexOf(':') == -1)
        {
          t.value=t.value+':00';
        }
        var firstOne = t.value.substring(0,1);
         
        if(document.getElementById(txt).value.toUpperCase().indexOf('AM') == -1 && document.getElementById(txt).value.toUpperCase().indexOf('PM') == -1 )
        {
        
          var firstTwo = t.value.substring(0,2);
         
          if(firstTwo.indexOf(':') == -1)
          {        
            if(parseInt(firstTwo) <=12)
            {           
              t.value=t.value+' PM';
            }   
             

          }
          else
          {      
            if(parseInt(firstTwo) <=12)
            {           
              t.value=t.value+' PM';
            }             
          }
        }
      }
    }
   
   
    function doTxtFrom(txt)
    {  
      t=document.getElementById(txt);
     
      if(t.value.length !=0)
      {
        if(t.value.indexOf(':') == -1)
        {
          t.value=t.value+':00';
        }
        var firstOne = t.value.substring(0,1);
         
        if(document.getElementById(txt).value.toUpperCase().indexOf('AM') == -1 && document.getElementById(txt).value.toUpperCase().indexOf('PM') == -1 )
        {
        
          var firstTwo = t.value.substring(0,2);
         
          if(firstTwo.indexOf(':') == -1)
          {         
            if(parseInt(firstOne) ==6 || parseInt(firstOne) ==7 ||parseInt(firstOne) ==8 || parseInt(firstOne) ==9 || parseInt(firstTwo) ==10 || parseInt(firstTwo) ==11)
            {
              t.value=t.value+' AM';
            }
            else if(parseInt(firstTwo) <=12)
            {           
              t.value=t.value+' PM';
            }            
          }
          else
          {
        
            if(parseInt(firstOne) ==6 || parseInt(firstOne) ==7 || parseInt(firstOne) ==8 || parseInt(firstOne) ==9 || parseInt(firstTwo) ==10 || parseInt(firstTwo) ==11)
            {
              t.value=t.value+' AM';
            }
            else if(parseInt(firstTwo) <=12)
            {           
              t.value=t.value+' PM';
            }           
          }
        }
      }
    }


2. Add the following Code in your CS

txtTimeFrom.Attributes.Add("onblur", "doTxtFrom('" + txtTimeFrom.ClientID + "');");


txtTimeTo.Attributes.Add("onblur", "doTxt('" + txtTimeTo.ClientID + "');");

Search Text in Stored Procedure (SQL)

Search Text in Stored Procedure (SQL)


set nocount on
  declare @ProcName nvarchar(100)

declare @ProcSortOrder int

declare @MyCursor CURSOR  
declare @MyCursor2 CURSOR  
declare @ProcUser varchar(100)
declare @ProcedureCode varchar(8000)
declare @ScriptText varchar(8000)
  select @ProcUser = 'my user'
   declare @Script TABLE
   (
     Script Text
   )
   declare @StoredProcs TABLE
   (
     SortOrder int,
     ProcedureName varchar(100),
     ProcedureCode varchar(7500)
   )

Insert Into @StoredProcs (SortOrder,ProcedureName,ProcedureCode)
SELECT TOP 100 0, upper(OBJECT_NAME(id)) , Text
FROM syscomments
WHERE
upper([text]) LIKE '%AssociateDiscountChart%'     
AND OBJECTPROPERTY(id, 'IsProcedure') = 1
GROUP BY OBJECT_NAME(id),Text

set nocount off

SET @MyCursor = CURSOR FAST_FORWARD
FOR

-- QUERY to SELECT SP


select ProcedureName,
        SortOrder =  (select count(*)
                        from @StoredProcs B
                        WHERE (A.ProcedureName <> B.ProcedureName)
                          and (REPLACE(UPPER(B.ProcedureCode),B.ProcedureName,'')
                               LIKE '%' + upper(A.ProcedureName) + '%')
                      ), ProcedureCode
    from @StoredProcs A
    order by SortOrder Desc
    OPEN @MyCursor
FETCH NEXT FROM @MyCursor
INTO @ProcName,@ProcSortOrder ,@ProcedureCode

   WHILE @@FETCH_STATUS = 0

   BEGIN
                    
               INSERT INTO @Script
               SELECT CONVERT(TEXT, '--========================================== BEGIN =============================================')
                      INSERT INTO @Script
               EXEC sp_helptext @ProcName       
                        INSERT INTO @Script
                SELECT CONVERT(TEXT, 'GO')

                        INSERT INTO @Script
                SELECT CONVERT(TEXT, '--========================================== END =============================================')

        FETCH NEXT FROM @MyCursor
      INTO @ProcName,@ProcSortOrder ,@ProcedureCode
   END

 CLOSE @MyCursor
DEALLOCATE @MyCursor        


SELECT  * From  @Script



Regards,
Sheryar Nizar

CSV to INT

CSV to INT

this is how you can convert a CVS to Int

CREATE function [dbo].[FN_CsvToInt] (@id varchar(5000))      
returns @table table (wd_code int identity(1,1), [id] int)     
as     
begin     
     
 declare @separator char(1)     
 set @separator = ','     
     
 declare @separator_position int      
 declare @array_value varchar(5000)      
      
 set @id = @id + ','     
      
 while patindex('%,%' , @id) <> 0      
 begin     
      
   select @separator_position =  patindex('%,%' , @id)     
   select @array_value = left(@id, @separator_position - 1)     
      
 if(@array_value = 'null')     
  insert @table ([id])     
  values (null)     
     
 else     
  insert @table ([id])     
  values (cast(@array_value as int))     
     
   select @id = stuff(@id, 1, @separator_position, '')     
 end     
     
 return     
end


Regards,
Sheryar Nizar

TreeView in DropDown


TreeView in DropDown


Private Sub RecursiveFillTree(ByVal dtParent As DataTable, ByVal parentID As Integer)
    level += 1
    Dim appender As StringBuilder = New System.Text.StringBuilder()
    For i = 0 To level
        appender.Append(" ")
    Next
    If level > 0 Then
        appender.Append("• ")
    End If
    Dim dv As DataView = New DataView(dtParent)
    dv.RowFilter = String.Format("ParentID = {0}", parentID)
    Dim j = 0
    If dv.Count > 0 Then
        While j < dv.Count
            ddlMTDetail.Items.Add(New ListItem(Server.HtmlDecode(appender.ToString() + dv(j)("MTDetailDesc").ToString()), dv(j)("MTDetailId").ToString()))
            RecursiveFillTree(dtParent, Convert.ToInt32(dv(j)("MTDetailId").ToString()))
            j += 1
        End While
    End If
    level -= 1
End Sub

Private Sub ShowTreeNodes()
    ddlMTDetail.Items.Clear()

    Dim sErrMsg = String.Empty
    Dim dtNodes As DataTable = objMaintenanceDb.FM_MaintenanceDetail_SelectTable()

    RecursiveFillTree(dtNodes, 0)

    ddlMTDetail.Items.Insert(0, New ListItem("- Select -", "0"))
    ddlMTDetail.SelectedIndex = 0

End Sub