Thursday, 21 June 2012

Return a comma seperated string in sql ?

create function funcationCommaSeparete(@myID int)
returns varchar(8000) as
begin
declare ps cursor for select columnName from TableName where columnName = @myID
declare @comma varchar(1),@res varchar(8000), @colvalue varchar(100)
set @res=''
set @comma=''
open ps
fetch next from ps into @colvalue
while @@fetch_status=0 begin
  set @res=@res+@comma+@colvalue
  set @comma=','
  fetch next from ps into @colvalue
end
close ps
deallocate ps
return @res
end

------------------- Using
select dbofuncationCommaSeparete(1)

Monday, 18 June 2012

Selecting distinct value from DataTable in C#

DataTable dtMain = new DataTable();

dtMain.Columns.Add("ID");
dtMain.Columns.Add("Name");
dtMain.Rows.Add(1, "AA");
dtMain.Rows.Add(1, "AA");
dtMain.Rows.Add(2, "CC");
dtMain.Rows.Add(3, "DD");
dtMain.Rows.Add(4, "EE");
dtMain.Rows.Add(5, "BB");
dtMain.Rows.Add(6, "AA");
dtMain.Rows.Add(5, "BB");
dtMain.Rows.Add(7, "FF");
dtMain.Rows.Add(1, "AA");

DataTable dtDistinct = dtMain.DefaultView.ToTable(true, "ID", "Name");

Wednesday, 13 June 2012

Disable cut, copy & paste using Javascript and Jquery

Javascript  
<script language="javascript" type="text/javascript">
function DisableCopyPaste (e) 
{
 // Message to display
 var message = "Cntrl key/ Right Click Option disabled";
 // check mouse right click or Ctrl key press
 if (e.keyCode == 17 || e.button == 2)
 {
 alert(message);
 return false;
 }
}
</script>
<asp:TextBox ID="TextBox1" runat="server" onKeyDown="return 
  DisableCopyPaste(event)"onMouseDown="return DisableCopyPaste
 (event)"></asp:TextBox> 
 
JQuery 
<script type="text/javascript">
$(document).ready(function() {
 $('#TextBox1').bind('copy paste cut',function(e) { 
 e.preventDefault(); //disable cut,copy,paste
 alert('cut,copy & paste options are disabled !!');
 });
});
</script>
 <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>  

Disable cut, copy & paste in textbox in asp.net without scripting

<asp:TextBox ID="TextBox1" runat="server" oncopy="return false" 
onpaste="return false" oncut="return false"></asp:TextBox> 

Wednesday, 6 June 2012

Date compare in javascript ?

var returnDate = "";
        function convertMonthText(DTime) {
            var monthtext = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
            var DateFormat = DTime.getDate();           
            if (DateFormat < 10) {
                returnDate = "0" + DTime.getDate() + "/" + monthtext[DTime.getMonth()] + "/" + DTime.getYear();
            }
            else {
                returnDate = DTime.getDate() + "/" + monthtext[DTime.getMonth()] + "/" + DTime.getYear();
            }           
        }

        function CompareDateToToday() {
            var dateChoosed = document.getElementById('TextBox1').value;
            var someDate = new Date();
            var numberOfDaysToAdd = 7;
            someDate.setDate(someDate.getDate() + numberOfDaysToAdd);

            convertMonthText(someDate);
            if (dateChoosed < returnDate) {
                alert('The date for responses should be at least a week after start date.')
                document.getElementById('TextBox1').value = "";
            }
        }

//---------- Support all browse below code

function convertMonthTextToNumeric(DTime) {
            var ReturnDateFormatedValue = "";
            var _Array = DTime.split('/');
            if (_Array.length > 2) {
                var _Month = "";
                if (_Array[1] == "Jan")
                    _Month = "01";
                else if (_Array[1] == "Feb")
                    _Month = "02";
                else if (_Array[1] == "Mar")
                    _Month = "03";
                else if (_Array[1] == "Apr")
                    _Month = "04";
                else if (_Array[1] == "May")
                    _Month = "05";
                else if (_Array[1] == "Jun")
                    _Month = "06";
                else if (_Array[1] == "Jul")
                    _Month = "07";
                else if (_Array[1] == "Aug")
                    _Month = "08";
                else if (_Array[1] == "Sep")
                    _Month = "09";
                else if (_Array[1] == "Oct")
                    _Month = "10";
                else if (_Array[1] == "Nov")
                    _Month = "11";
                else if (_Array[1] == "Dec")
                    _Month = "12";
                else
                    _Month = "01";

                ReturnDateFormatedValue = _Array[2] + "/" + _Month + "/" + _Array[0];
            }
            return ReturnDateFormatedValue;
        }



        function CheckDateValidation() {
            var getStartDateFormated = "";
            var getEndtDateFormated = "";
            getStartDateFormated = convertMonthTextToNumeric(document.getElementById('txtStartDate').value);
            getEndtDateFormated = convertMonthTextToNumeric(document.getElementById('txtEndDate').value);

            getStartDateFormated = new Date(getStartDateFormated);
            getEndtDateFormated = new Date(getEndtDateFormated);

            var numberOfDaysToAdd = 7;
            getStartDateFormated.setDate(getStartDateFormated.getDate() + numberOfDaysToAdd);

            if (getEndtDateFormated < getStartDateFormated) {
                alert('The date for responses should be at least a week after start date.')
                document.getElementById('txtEndDate').value = "";
            }
        }