Friday, October 21, 2011

Finding a particular text in a stored procedure.

SELECT OBJECT_NAME(id)
    FROM syscomments
    WHERE [text] LIKE '%Decode%'
    AND OBJECTPROPERTY(id, 'IsProcedure') = 1
    GROUP BY OBJECT_NAME(id)

Wednesday, October 19, 2011

Check for Valid Email in Javascript.

function validate(str)
{
 var expression=/^([a-zA-Z0-9\-\._]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})$/;

 if(!(expression.test(str)) )
       return false;
 else
     return true;
}

Formatting a Date in Crystal Report.

ToText(Month ({PriceIncreaseOverRide.PriceIncreaseEffectiveDateTo}),0)
+ "/" +
ToText (Day ({PriceIncreaseOverRide.PriceIncreaseEffectiveDateTo}),0)
+ "/" +
ToText(Year ({PriceIncreaseOverRide.PriceIncreaseEffectiveDateTo}),"####")

or
ToText({PriceIncreaseOverRide.PriceIncreaseEffectiveDateTo},"MMM-dd-yyyy")

Export To Excel/Word using ASP.NET and VB.NET

Excel

        Dim tw As New StringWriter()
        Dim hw As New System.Web.UI.HtmlTextWriter(tw)
        Dim frm As HtmlForm = New HtmlForm()
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("content-disposition", "attachment;filename=Report_Listing.xls")
        Response.Charset = ""
        EnableViewState = False
        Controls.Add(frm)
        frm.Controls.Add(gvSearch)
        frm.RenderControl(hw)
        Response.Write(tw.ToString())
        Response.End()


Word

Private Sub ExportToPdf(ByVal rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal fileName As String)
        If fileName Is Nothing Then fileName = "DelinquencyReport"
        Dim cr As CrystalDecisions.CrystalReports.Engine.ReportDocument = rpt
        Dim reportName As String = "/" & fileName & ".pdf"
        Dim strFile As String = Server.MapPath(Global.REPORT_LOCATION) & reportName
        cr.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
        cr.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
        Dim dskOptions As New CrystalDecisions.Shared.DiskFileDestinationOptions
        dskOptions.DiskFileName = strFile
        cr.ExportOptions.DestinationOptions = dskOptions
        Try

            cr.Export()
            Page.RegisterStartupScript("ExportToPdf", "<script language=Javascript>window.open('" & Global.REPORT_LOCATION_REDIRECTION & reportName & "','_blank');</script>")

        Catch ex As Exception
            Throw ex
        Finally
            dskOptions = Nothing
            cr = Nothing
        End Try
    End Sub

----------
Try
            repDoc = VendorInvoice.GetVendorInvoiceInformation(InvoiceType, IsPosted, Query)
            ExportToPdf(repDoc, "VendorInvoiceReport")
            'Session(Global.REPORT_DOCUMENT_SESSION_OBJECT) = repDoc
            'Global.GotoControl(Page, Global.REPORT_VIEWER)
        Catch ex As Exception
            DisplayMessage(ex.Message)
        Finally
            repDoc = Nothing
            VendorInvoice = Nothing
        End Try
  

Export to PDF using Crystal Report.

Private Sub ExportToPdf(ByVal rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal fileName As String)

        If fileName Is Nothing Then fileName = "DelinquencyReport"
        Dim cr As CrystalDecisions.CrystalReports.Engine.ReportDocument = rpt
        Dim reportName As String = "/" & fileName & ".pdf"
        Dim strFile As String = Server.MapPath(Global.REPORT_LOCATION) & reportName
        cr.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
        cr.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
        Dim dskOptions As New CrystalDecisions.Shared.DiskFileDestinationOptions
        dskOptions.DiskFileName = strFile
        cr.ExportOptions.DestinationOptions = dskOptions

        Try
            cr.Export()
            Page.RegisterStartupScript("ExportToPdf", "<script language=Javascript>window.open('" & Global.REPORT_LOCATION_REDIRECTION & reportName & "','_blank');</script>")

        Catch ex As Exception
            Throw ex
        Finally
            dskOptions = Nothing
            cr = Nothing
        End Try
    End Sub

----------

Try
            repDoc = VendorInvoice.GetVendorInvoiceInformation(InvoiceType, IsPosted, Query)
            ExportToPdf(repDoc, "VendorInvoiceReport")
            'Session(Global.REPORT_DOCUMENT_SESSION_OBJECT) = repDoc
            'Global.GotoControl(Page, Global.REPORT_VIEWER)
        Catch ex As Exception
            DisplayMessage(ex.Message)
        Finally
            repDoc = Nothing
            VendorInvoice = Nothing
        End Try
  

Including flash in project.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"
     width="740" height="100" VIEWASTEXT>
     <param name="movie" value="swf/efficience1.swf" />
     <param name="quality" value="high" />
     <embed src="swf/efficience1.swf" quality="high" pluginspage="
http://www.macromedia.com/go/getflashplayer"
      type="application/x-shockwave-flash" width="743" height="100"></embed>
    </object>

Opening a word/pdf

Word File
------------
 Dim sResponseFile As String = Server.MapPath(".") & "/desktopmodules/career/resume/" & CType(e.Item.FindControl("lblresumepath"), Label).Text

        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/msword"
        Response.AddHeader("Content-Disposition", "attachment; filename=""" & Path.GetFileName(sResponseFile) & """")
 Response.ContentEncoding = System.Text.Encoding.UTF7
        Response.Charset = ""
        Response.WriteFile(sResponseFile)
        Response.End()


PDF File
---------

Page.RegisterStartupScript("ReportViewer_ExportToPdf", "<script language=Javascript>window.open('PDF/Test9.pdf','_blank');</script>")


     Dim strPath = _Global.EBOOK_PATH
            Dim strFileName As String
            Dim absPath As String
            Dim vPath As String
            If e.CommandName = "Select" Then

                strFileName = e.Item.Cells(0).Text
                absPath = Server.MapPath("..") & "\" & strPath & strFileName
                vPath = "../" & strPath & strFileName
                vPath = vPath.Replace("\", "/")


                If File.Exists(absPath) Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, Page.GetType(), "Ebooks", "window.open('" & vPath & "','_blank','menubar=0, location=0, resizable=1, status=1, scrollbars=1');", True)
                Else
                    _Global.ShowErrorMessage(Me.Page, "File not found")
                End If

            End If

Refreshing the page every 30 min

<meta http-equiv="refresh" content="300">

Using SelectAll checkbox in grid

<asp:TemplateColumn>
         <HeaderTemplate>
          <INPUT id="cbCheckAll" onclick="CheckItems();" type="checkbox" enabled="false">          
         </HeaderTemplate>
         <ItemTemplate>
           <INPUT type=checkbox value='<%# Container.dataitem("VendorCode") %>' name=cbdgVendorCode>
            </ItemTemplate>
        </asp:TemplateColumn>



function CheckItems() ////  Check & Uncheck the check boxes in the datagrid
{

 try
  {
   chkField = eval(document.getElementsByName("cbdgVendorCode"));

   if (document.getElementById("cbCheckAll").checked)
   val= true;
   else
   val=false;

   for (i = 0; i < chkField.length ; i++)
   {
   chkField[i].checked = val ;
   //alert(chkField[i].value);
   }
  
  }
 catch(e) {}
}

Friday, October 14, 2011

Panel DefaultEnter property not working for ValidationSummary.

After a more detailed study of the problem revealed that the construction
<Asp: Panel ID = "Panel1" runat = "server" DefaultButton = "btnFind">  becomes 

<div id="ctl00_cphMain_Panel1" onkeypress="javascript:return WebForm_FireDefaultButton(event,'ctl00_cphMain_btnFind')"> 

But unfortunately, JavaScript onkeypress event of input field overridden by validator that controlling this field. So when you enter the wrong information and pressing the Enter button it's triggered validator, which displays the text of the error and stops processing events. 

So that would overcome this "evil" enough to use a different event. In this case, it will keydown.It will look like this:

panel
.Attributes.Add ( "onkeydown", "javascript: return WebForm_FireDefaultButton (event, '" + btnFind.ClientID + "')");

Monday, October 10, 2011

Focus on textbox

    $(document).ready(function () {
         $("#cphPageContent_CtlAddandEditProject1_txtTitle").focus();
     });