Friday 13 December 2013

Generating pdf document from C#

       Document pdfDoc = new Document(PageSize.A4, 30, 30, 40, 25);
        System.IO.MemoryStream mStream = new System.IO.MemoryStream();
        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream);
        int cols = 4;
        int rows = GvTicketHistory.Rows.Count;
        pdfDoc.Open();

      // create the table to add in pdf





        objCustomerHistoryViewBAL = new CustomerHistoryViewBAL();
        string refno = Convert.ToString(Request.QueryString["refno"]);
        DataTable dt = objCustomerHistoryViewBAL.getpatientdetails(refno);

        float[] anchoDeColumnas = new float[] { 15f,25f, 12f, 28f,10f,10f };

        string imagepath = ConfigurationManager.AppSettings["CRMFilesLocation"];

        iTextSharp.text.Table pdfTable = new iTextSharp.text.Table(cols, rows);
        iTextSharp.text.Table pdfTable1 = new iTextSharp.text.Table(cols, rows);

        //pdfTable1.BorderWidth = 0;
       // pdfTable1.Padding = 0;
       // pdfTable1.Spacing = 0;
        pdfTable1.Width = 100f;

        pdfTable.BorderWidth = 0;    
        pdfTable.Padding = 0;
        pdfTable.Spacing = 0;
        pdfTable.Width = 100f;
        pdfTable.Cellpadding = 1f;
      

        string filepath = Server.MapPath("~/Images_V2/PreAuth_V2/");

        iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(filepath + "logo.gif");
        gif.Alignment = Element.ALIGN_RIGHT;
        pdfDoc.Add(gif);

        Font contentfont = FontFactory.GetFont("Times New Roman", 10,Font.BOLD | Font.UNDERLINE,Color.RED);
     

        //Paragraph p = new Paragraph("REMEDINET TECHNOLOGIES PVT.LTD.", contentfont);
        //p.IndentationLeft = 180f;
        //pdfDoc.Add(p);

        Font lblb = FontFactory.GetFont("Times New Roman", 7,Font.BOLD);
        Font lblv= FontFactory.GetFont("Times New Roman", 7);

        PdfPTable table = new PdfPTable(6);
        table.SetWidths(anchoDeColumnas);
        PdfPCell cell = new PdfPCell(new Phrase("REMEDINET TECHNOLOGIES PVT. LTD.",      contentfont));
        cell.BorderWidth = 0;
        cell.Colspan =6;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell);


        PdfPCell cell1 = new PdfPCell(new Phrase("Patient Name:", lblb));
        cell1.BorderWidth = 0;
        table.AddCell(cell1);
        PdfPCell cell2 = new PdfPCell(new Phrase(dt.Rows[0]["PR_NAME"].ToString(), lblv));
        cell2.BorderWidth = 0;
        table.AddCell(cell2);
        PdfPCell cell3 = new PdfPCell(new Phrase("Age:", lblb));
        cell3.BorderWidth = 0;
        table.AddCell(cell3);
        PdfPCell cell4 = new PdfPCell(new Phrase(dt.Rows[0]["PR_AGE"].ToString(), lblv));
        cell4.BorderWidth = 0;
        table.AddCell(cell4);
        PdfPCell cell5 = new PdfPCell(new Phrase("Gender:", lblb));
        cell5.BorderWidth = 0;
        table.AddCell(cell5);
        PdfPCell cell6 = new PdfPCell(new Phrase(dt.Rows[0]["PR_SEX"].ToString(), lblv));
        cell6.BorderWidth = 0;
        table.AddCell(cell6);

        PdfPCell cell7 = new PdfPCell(new Phrase("Member ID:", lblb));
        cell7.BorderWidth = 0;
        table.AddCell(cell7);
        PdfPCell cell8 = new PdfPCell(new Phrase(dt.Rows[0]["PR_TPAID"].ToString(), lblv));
        cell8.BorderWidth = 0;
        table.AddCell(cell8);
        PdfPCell cell9 = new PdfPCell(new Phrase("Policy No", lblb));
        cell9.BorderWidth = 0;
        table.AddCell(cell9);
        PdfPCell cell10 = new PdfPCell(new Phrase(dt.Rows[0]["PR_POLNO"].ToString(), lblv));
        cell10.BorderWidth = 0;
        table.AddCell(cell10);
        PdfPCell cell11 = new PdfPCell(new Phrase("", lblb));
        cell11.BorderWidth = 0;
        table.AddCell(cell11);
        PdfPCell cell12 = new PdfPCell(new Phrase("", lblb));
        cell12.BorderWidth = 0;
        table.AddCell(cell12);


        PdfPCell cell13 = new PdfPCell(new Phrase("Corporate:", lblb));
        cell13.BorderWidth = 0;
        table.AddCell(cell13);
        PdfPCell cell14 = new PdfPCell(new Phrase(dt.Rows[0]["PR_CORP"].ToString(), lblv));
        cell14.BorderWidth = 0;
        table.AddCell(cell14);
        PdfPCell cell15 = new PdfPCell(new Phrase("Employee ID:", lblb));
        cell15.BorderWidth = 0;
        table.AddCell(cell15);
        PdfPCell cell16 = new PdfPCell(new Phrase(dt.Rows[0]["PR_CORPID"].ToString(), lblv));
        cell16.BorderWidth = 0;
        table.AddCell(cell16);
        PdfPCell cell17 = new PdfPCell(new Phrase("", lblb));
        cell17.BorderWidth = 0;
        table.AddCell(cell17);
        PdfPCell cell18 = new PdfPCell(new Phrase("", lblb));
        cell18.BorderWidth = 0;
        table.AddCell(cell18);


        PdfPCell cell19 = new PdfPCell(new Phrase("Case Reference ID:", lblb));
        cell19.BorderWidth = 0;
        table.AddCell(cell19);
        PdfPCell cell20 = new PdfPCell(new Phrase(dt.Rows[0]["REFNO"].ToString(), lblv));
        cell20.BorderWidth = 0;
        table.AddCell(cell20);
        PdfPCell cell21 = new PdfPCell(new Phrase("Provider Name:", lblb));
        cell21.BorderWidth = 0;
        table.AddCell(cell21);
        PdfPCell cell22 = new PdfPCell(new Phrase(dt.Rows[0]["HOSPNAME"].ToString(), lblv));
        cell22.BorderWidth = 0;
        table.AddCell(cell22);
        PdfPCell cell23 = new PdfPCell(new Phrase("", lblb));
        cell23.BorderWidth = 0;
        table.AddCell(cell23);
        PdfPCell cell24 = new PdfPCell(new Phrase("", lblb));
        cell24.BorderWidth = 0;
        table.AddCell(cell24);    
        table.WidthPercentage = 100;
    
  //      add the table here

       pdfDoc.Add(table);
        pdfDoc.Close();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment; filename=Report.pdf");
        Response.Clear();
        Response.BinaryWrite(mStream.ToArray());
        Response.End();

swapping/changing image of image button in javascript on ClientClick

//// set value = "expand" in your image button tag, get this value to swap image randomly.

function swapimagesrc()
    {
      if(document.getElementById("imgbuttonExpand").value =="expand")
      {
         document.getElementById("imgbuttonExpand").src = '../CRMImages/close_view.fw.png';
         document.getElementById("imgbuttonExpand").value = "close";
      }
      else if(document.getElementById("imgbuttonExpand").value =="close")
      {
          document.getElementById("imgbuttonExpand").src = '../CRMImages/expand_view.fw.png';
            document.getElementById("imgbuttonExpand").value = "expand";
      }
    }

Validating file uploader in Javascript

function ValidateFile()
    {
      var validFilesTypes=["bmp","gif","png","jpg","jpeg","doc","xls"];
      var file = document.getElementById("<%=fileupload.ClientID%>");
      var path = file.value;
      var ext=path.substring(path.lastIndexOf(".")+1,path.length).toLowerCase();
      var isValidFile = false;
      for (var i=0; i<validFilesTypes.length; i++)
      {
        if (ext==validFilesTypes[i])
        {
            isValidFile=true;
            return true;
        }
      }
      if (!isValidFile)
      {
         alert('File Format is invalid.["bmp","gif","png","jpg","jpeg"] are allowed.');
         return false;
      }
    
     }   

Getting Querystring values from javascript

function ShowGridDivsonload(objID)
    {
        var qsarr = new Array();
        var qs = location.search.substring(1);
        var singleqs = new Array();
        var str ="";
        qsarr = qs.split('&');
        for( i=0; i<qsarr.length; i++)
        {
            singleqs = qsarr[i].split('=');
            str = singleqs[1]  ;
        }
           if( str == "HS")
           {
             $("#"+objID+" div").show();
             $("#"+objID+" a[Anchor] ").text("-");
             document.getElementById("imgbuttonExpand").src = '../CRMImages/close_view.fw.png';
             document.getElementById("imgbuttonExpand").value = "close";
           }
    }
   

Tuesday 17 September 2013

Sorting Of The Gridview column without using Datasource

 protected void GVinsurance_onSorting(object sender, GridViewSortEventArgs e)
        {

            DataTable dt1 = (DataTable)ViewState["DT"];//GVProvider.DataSource as DataTable;
            if (dt1 != null)
            {

                if (dt1 != null)
                {
                    DataView dvSortedView = new DataView(dt1);

                    dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);

                    GVInsurance.DataSource = dvSortedView;
                    GVInsurance.DataBind();
                }

            }
        }

----------------------------------------



 private string getSortDirectionString(SortDirection sortDirection)
        {
            string newSortDirection = String.Empty;

            if (Convert.ToString(ViewState["newSortDirection"]) == "DESC")
            {
                ViewState["newSortDirection"] = "ASC";
            }
            else
                ViewState["newSortDirection"] = "DESC";

            return newSortDirection = Convert.ToString(ViewState["newSortDirection"]);
        }


Wednesday 17 July 2013

Validating number of characters before and after decimal point using javascript

  function validatemaxAmt(sender, evt)
{
              var splitValue = sender.value.split(".", 2);

        
                  if(splitValue[0] != null)
                 {
                    if(splitValue[0].length < 7)
                    {
                       // alert("Correct format.");
                        return true; // allow postback (if applicable)
                    }
                    else
                    {
                        alert("Incorrect number of decimal digits.");
                        sender.value="0";
                        sender.focus();
                        return false; // disallow postback (if applicable)
              
                    }
                }
}

Wednesday 26 June 2013

Handling the radio button list with yes or no confirmation message in C#


rdbbilltype.Attributes.Add("onclick", "if(!confirm('Are you sure to change the bill type? ')) return false;");



Looks simple but it will allow only when the OK button is clicked, Or else it wont change the selection.

Awesome...!!!

Monday 17 June 2013

Javascript validation for special characters in ASP.NET/ C#

function validatespecailchars()
{

     var txtbox = document.getElementById('<%=txtsearch.ClientID %>').value;
   
      var str="<";
        var str1=">";
        var str2="--";
        var str3=";";
        var str4="'";

    if((txtbox.indexOf(str)>=0)||(txtbox.indexOf(str1)>=0)||(txtbox.indexOf(str2)>=0)||      (txtbox.indexOf(str3)>=0)||(txtbox.indexOf(str4)>=0))
    {
         alert('Special Characters are not Allowed.');
        // you can focus here that particular control
     }
}

Wednesday 17 April 2013

Generating the Graphs in Asp.net

In desing page

// put one literal 

<asp:Literal ID="TATLiteral1" runat="server"></asp:Literal>


In Code Behind


        string sql = "", sql1 = "", sql2 = "", sql3="";
        string condition = "";
        string strXML, strCategories1 ;
        DataTable fdt = null;
        DataTable fdt1 = null;
        DataTable fdt3 = null;
        OracleCommand cmd = null;
        OracleDataAdapter da = null;


       /// genarate the data for your graph

            sql = " Your Query to get data";
            fdt1 = new DataTable();
            cmd = new OracleCommand(sql, conn);
            da = new OracleDataAdapter(cmd);
            da.Fill(fdt1);


     // after getting data put it in the XML format as below

  //  header tag for graph
   
         strXML1 = "<graph  rotateNames='0' animation='1'  numdivlines='4'  baseFont='Arial' baseFontSize='10' baseFontColor='000000' useRoundEdges='1' showLegend='0' bgColor='ffffff' borderColor='ffffff' showYAxisValues='0'>";


   // categories

  strCategories1 = "<categories> <category name='0-2 Hrs' /> <category name='>2 Hrs' /></categories>";

                strXML1 += strCategories1;
// dataset you are providing

                strXML1 += " <dataset seriesName='"+fdt3.Rows[0]["HOSPNAME"]+"' color='8B0000'   showValues='1'>";
                strXML1 += "<set   value='" + fdt1.Rows[0]["Total"].ToString() + "' />";
                strXML1 += "<set   value='" + fdt1.Rows[1]["Total"].ToString() + "' />";
                strXML1 += " </dataset>";

                strXML1 += " <dataset seriesName='"+fdt3.Rows[1]["HOSPNAME"]+"' color='2F4F4F' showValues='1'>";
                strXML1 += "<set   value='" + fdt1.Rows[2]["Total"].ToString() + "' />";
                strXML1 += "<set   value='" + fdt1.Rows[3]["Total"].ToString() + "' />";
                strXML1 += " </dataset>";


                strXML1 += " <dataset seriesName='" + fdt3.Rows[2]["HOSPNAME"] + "' color='20B2AA' showValues='1'>";
                strXML1 += "<set  value='" + fdt1.Rows[4]["Total"].ToString() + "' />";
                strXML1 += "<set  value='" + fdt1.Rows[5]["Total"].ToString() + "' />";
                strXML1 += " </dataset>";
               

                strXML1 += "</graph>";

// binding to literal 

                TATLiteral1.Text = FusionCharts.RenderChartHTML("../ChartsLicense/MSColumn2D.swf", "", strXML1, "Preauthinfo", "350", "170", false);




NOTE : Graph is also depends on the swf files which we provide  like BAR, COLUMN , LINE , STACKED (here m using Multi series column graph)  So download all the swf files from  fusioncharts.com ( refer it for more info for graphs)



Calling the loading images using javascript (processing image)


In head  

//Use this javascript

  <script type="text/javascript">

  function hideLoading()
        {
              document.getElementById('divLoading').style.display = "none";
              document.getElementById('divFrameHolder').style.display = "block";
              document.getElementById('div4').style.display = "none";
              document.getElementById('div2').style.display = "block";
              document.getElementById('div5').style.display = "none";
              document.getElementById('div3').style.display = "block";
        }
     </script>


In form

// call javascript function in iframe tag


 <table style="width:830px;height:480px;font-family:Arial;" bgcolor="white" align="center">
                <tr style="height:8px">
                <td align="center" style="font-weight:bold;font-size:12px;">
                <asp:Label ID="chart4" runat="server" ></asp:Label>
                </td>
                <td align="center" style="font-weight:bold;font-size:12px;">
                <asp:Label ID="chart5" runat="server" ></asp:Label>
                </td>
                </tr>
                <tr style="height:200px">
                <td colspan="2" valign="top" align="center">
                  <div id="divLoading" style="align:center;">
                    <img src="../images/loading45.gif" alt="" width="150px" height="150px" />
                  </div> 
                  <div id="divFrameHolder" style="display:none">  
                <iframe src="smartmisframeaging.aspx" onload="hideLoading()" frameborder="0" scrolling="no" width="100%" height="230"></iframe>
                 </div> 
                </td>
                </tr>
                <tr style="height: 8px">
                <td align="center" style="font-weight:bold;font-size:12px;">
                 <asp:Label ID="chrt1" runat="server"></asp:Label>
                </td>
                <td align="left" style="font-weight:bold;font-size:12px;padding-left:40px;">
                  <asp:Label ID="chrt2" runat="server"></asp:Label>
                  <asp:Label ID="chrt3" runat="server"></asp:Label>
                </td>

                </tr>
                <tr align="left">
                <td  style="width:215px;padding-left:0px;" valign="top" align="center">
                 <div id="div4" style="align:center;">
                    <img src="../images/loading45.gif" alt="" width="150px" height="150px" />
                 </div> 
                <div id="div2" style="display:none">  
                 <iframe id="preauth" src="smartmisframepreauth.aspx"  onload="hideLoading()"      frameborder="0" scrolling="no" width="100%" height="300px"></iframe>
                </div>
                </td>
                <td valign="top" align="center">
                 <div id="div5" style="align:center;">
                    <img src="../images/loading45.gif" alt="" width="150px" height="150px" />
                  </div> 
                 <div id="div3" style="display:none">  
                  <iframe src="smartMISframehrs.aspx"  onload="hideLoading()" frameborder="0" scrolling="no" width="100%" height="300px" marginwidth="0"></iframe>
                 </div> 
                </td>
                </tr>
                </table>






Friday 8 February 2013

Getting the nested gridview values when it is inside the content placeholder in javascript


function  Rdbtn(index)
{
   var gridView1 = document.getElementById('ctl00_ContentPlaceHolder1_GVBenefit');
 
   var billamt=0;
   var billamt_tot=0; 
   var input4 =  gridView1.rows[index - 1].getElementsByTagName('input')[6]; 
   var idExt=index;  
    for (var i = 1; i < gridView1.rows.length; i++)
    {
          if(parseInt(idExt,10) <= 9)
          {
           idExt = "0" + idExt;                     
          }  

            var VExtGrid = "ctl00_ContentPlaceHolder1_GVBenefit_ctl"+idExt;              
            var gridView = document.getElementById(VExtGrid+"_GvSubBenfits");       
             for (var j = 1; j < gridView.rows.length; j++)
             {  
                   var inputs1 = gridView.rows[j].getElementsByTagName('input')[0];
                   var inputs2 = gridView.rows[j].getElementsByTagName('input')[1];
                   var txtAdm = gridView.rows[j].getElementsByTagName('input')[2];

                   if( inputs1.checked==true )
                   {
                    txtAdm.setAttribute("disabled", false);       
                   }
                    if( inputs2.checked==true )
                   {
                    txtAdm.setAttribute("disabled", true);       
                   }
                 
                   if (txtAdm.value.length<1)
                   {
                     billamt=0;
                   }
                   else
                   {
                     billamt =parseFloat(txtAdm.value);
                   }
             
                billamt_tot = billamt_tot + billamt;
              
                input4.value = billamt_tot;
             }
             GetAppAmt();
      }   
  
}