Thursday, 23 June 2011

Save and update Multiple records

  StringBuilder builder = new StringBuilder();
            builder.Append("<Root>");

            for (int i = 0; i < grdPermission.Rows.Count; i++)
            {
                string ActivityName = string.Empty;
                string ActivityID = string.Empty;
                string view = string.Empty;
                string edit = string.Empty;
                string delete = string.Empty;

                ActivityID = ((Label)grdPermission.Rows[i].Cells[1].FindControl("lblActivityID")).Text.Trim();
                ActivityName = ((Label)grdPermission.Rows[i].Cells[1].FindControl("lblActivityName")).Text.Trim();
                string rdBtnListAction = ((RadioButtonList)grdPermission.Rows[i].Cells[2].FindControl("rdBtnListAction")).SelectedValue.ToString();

                builder.Append("<Activities ActivityID='" + ActivityID + "' RoleID = '" + ddl_AllRoles.SelectedValue.ToString() + "' Permission ='" + rdBtnListAction + "'></Activities>");

            }
            builder.Append("</Root>");
            builder.ToString();
            objAdminSecurityBL = new AdminSecurityBL();           
            objAdminSecurityBL.PermissiontoActivities( builder.ToString());
            objAdminSecurityBL = null;



   

     
Alter Procedure [sp_insertUsersExcel]     
 (       
  @XmlString xml = null 

         
 )     
AS     
     
Begin     
   
     
  declare @VerseSize  nvarchar(100) 
  declare @CompanyCardID  nvarchar(100) 
  declare @PTextSize nvarchar(100)
  DECLARE @idoc int  
Declare @abcdas int=0
         declare @abc varchar(max) =''
         declare @abc1 varchar(max) =''
         
       
   exec sp_xml_preparedocument @idoc output, @xmlString     
   
   DECLARE pCursor CURSOR FOR     
   select xCompanyCardID,xVerseSize,xPTextSize from openxml(@idoc,'/root/XML_FIRM',1)     
   with(xCompanyCardID nvarchar(100),xVerseSize nvarchar(100),xPTextSize nvarchar(100))      
         
   OPEN pCursor     
   
   FETCH NEXT FROM pCursor into @CompanyCardID,@VerseSize,@PTextSize
    WHILE @@FETCH_STATUS = 0   
       
    BEGIN 
        
     
   if exists(select * from  tbl_Cards  where CompanyCardID=@CompanyCardID)
   begin
      update tbl_Cards set VerseSize=@VerseSize,PTextSize=@PTextSize where CompanyCardID=@CompanyCardID 
      --update tbl_Cards set VerseSize='',PTextSize='' where CompanyCardID=@CompanyCardID 
   end
   else
       begin
       if(LEN(@abc) < 7980)
       begin
      set  @abcdas=@abcdas+1
      
        set @abc= @abc + @CompanyCardID  +'<br/>'
        end
       
        else
        begin
        set @abcdas=@abcdas+1
        set @abc1= @abc1 + @CompanyCardID + '<br/>'
        end
   
       end
        
      FETCH NEXT FROM pCursor into @CompanyCardID,@VerseSize,@PTextSize 
    End      
     CLOSE pCursor     
     DEALLOCATE pCursor        
             
  EXEC sp_xml_removedocument @iDoc     
  
     print @abc
      print @abc1

   
  
End     
    






Autocomplete using jquery ashx extension file

$("#ContentPlaceHolder2_txtLeftInsuranceName").autocomplete('../AutoComplete/AutoCompInsuranceName.ashx', { matchContains: false, minChars: 1, autoFill: false, mustMatch: true, width: 300, cacheLength: 10, max: 10 }).bind("click");



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using PatientEstimator.BusinessLogic;
using PatientEstimator.Common;

namespace PatientEstimator.Web.AutoComplete
{
    /// <summary>
    /// Summary description for AutoCompInsuranceName
    /// </summary>
    public class AutoCompInsuranceName : IHttpHandler
    {


        public void ProcessRequest(HttpContext context)
        {
            PatientSearchBO objPatientSearchBO = new PatientSearchBO();
            PatientSearchBL objPatientSearchBL = new PatientSearchBL();

            string prefixText = context.Request.QueryString["q"];
            objPatientSearchBO.insname = prefixText;

            List<PatientSearchBO> ProviderCodeList = objPatientSearchBL.GETInsurance(objPatientSearchBO);
            StringBuilder sbProviderCodeList = new StringBuilder();

            for (int i = 0; i < ProviderCodeList.Count; i++)
            {

                sbProviderCodeList.Append(ProviderCodeList[i].insname)
                               .Append(Environment.NewLine);
            }

            context.Response.Write(sbProviderCodeList.ToString());

        }






        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

only take two digits after decimal

 function ValidateFloat(var1) {
            var re = new RegExp("^\\s*-?(\\d+(\\.\\d{1,2})?|\\.\\d{1,2})\\s*$", "g");
            if (var1.val() != 0) {
                if (!re.test(var1.val())) {
                    return false;
                }
            }
            return true;
        }

Pop up at center of the screen

function centerPopup() {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var top = jQuery("#Content3").position().top; 
    //alert(top);  
    var popupHeight = jQuery("#popupContact").height();
    var popupWidth = jQuery("#popupContact").width();
    jQuery("#popupContact").css({
        "position": "absolute",
        "top": top - 100,
        //"top": 500,
        "left": windowWidth / 2 - popupWidth / 2
    });
    $("#backgroundPopup").css({
        "height": windowHeight
    });
}

Hide/show table row on ckeck/unhcheck the checkboxes

 $('#btnFilterApply').click(function () {

                    $("#filterDivInner input[type=checkbox]").each(function() {
           
                       if ($(this).is(':checked'))
                       {
                       
                        var crow = $(this).attr("name");
                        $('#tableresult tr:contains("'+ crow +'")').show();
                       
                       }
                       else
                       {
                         var urow = $(this).attr("name");   
                                             
                         if(urow == '' || urow == ' ')
                         {
                          
                         $('#tableresult tr:contains("'+ urow +'")').hide();
                          //$('#tableresult tr:contains('+ urow +')').style.display='none';                         
                         
                        
                         }
                         else
                         {
                          $('#tableresult tr:contains("'+ urow +'")').hide();
                         }
                        
                         $('#tableresult tr:first').show();
                       }
           
                    }); // end $("#filterDivInner input[type=checkbox]").each(function()

                
         $('#filterDivOuter').hide();



   }); // btn close Apply function

Filter the table using pop up div

function imagefilerClick()
 {
       $('#tableresult th div img.filter').click(function (e) {  
        $("#filterDivOuter").show();
        cellNo = $("#tableresult th").index($(this).parents('th'));
       
        var filterlistItems = "";
        var vals = new Array();
        var i=0;
        var options='';
       
        $('#tableresult td:nth-child(' + (cellNo + 1) + ')').each(function(){
           var t=$(this).html();
           if(t==" ")
            t="" 
                                           
           if($.inArray(t, vals) < 0)
           {
               vals[i]=t;
               i++;
           }
        });
       
        for(var j=0;j<i;j++)
        {    
            var chkbxName = vals[j];//.replace(/\s/g,"");
                       
            filterlistItems = filterlistItems + "<input class='allCheckConatiner' type='checkbox' value= '" + cellNo + "'  checked='checked'  name = '" + chkbxName + "' /> <label>" + vals[j] + "</label><br />";
        
        }                                            
       
        $('#filterDivInner').html(filterlistItems);
         
        filterlistItems ="";
       
       
            var x = e.pageX;         
            x = x- 100;
            var y = e.pageY;
            y = y - 90;
           
            if(x > $(window).width()-190)
                x = x -  39;
            if(x<0)
                x = 5;
               
               
           
           
           
            jQuery("#filterDivOuter").css({
                "position": "absolute", "display": "block",
                "top": y,
                "left": x
            });
         
             
          $("#filterDivInner input[type=checkbox]").each(function() {
         
   
             var crow = $(this).attr("name");            

                var condition="";
                if(crow!=null)
                {
                if (crow  =='' || crow  == ' ' )
                    condition = $('#tableresult tr:last:contains("' + crow + '")').css('display') == "none" ;                    
                else
                    condition = $('#tableresult tr:contains("'+ crow +'")').css('display') == "none" ;
               
                }
               
                 
                 
                 
                   if(condition)              
                   {
                        $(this).attr("checked", false);
                   }
                   else
                   {
                       
                        $(this).attr("checked", true);                  
                   }
            
        
          }); // end $("#filterDivInner input[type=checkbox]").each(function()
                 
    

    }); // $('#tableresult th div img.filter').click on click open popup

click outside the Pop Div then Pop Div close

  var mouse_is_inside = false;

 $('#filterDivOuter').hover(function(){
        mouse_is_inside=true;
    }, function(){
        mouse_is_inside=false;
    });

    $("body").mouseup(function(){
        if(! mouse_is_inside) $('#filterDivOuter').hide();
    });

Using Jquery CheckAll and UncheckAll

    // check and uncheck all checkboxes

    $('#chkall').click(function () {
        $("#filterDivInner :checkbox").attr('checked', $(this).attr('checked'));
    }); 

How to split a string

string abc = "D1.23:ManojThakur";

 sring xyz = abc.Split('.')[0]  //D1

string z= abc.split(':')[1] // 23:ManojThakur