Share Blog

Saturday, July 28, 2018

Remove comma and add comma in string in c#


//remove comman and add comma
string department = "Support, Integration, Developer";
string dptment = "";
string[] dpt = department.Split(',');
for (int i = 0; i <= dpt.Length - 1; i++)
{
if (i == dpt.Length - 1)
{
dptment = dptment + dpt[i];
}
else
{
dptment = dptment + dpt[i] + ", ";
}
}
Console.WriteLine(dptment);
//remove comma and add without comman in list
List<string> lsttype = new List<string>();
string[] extracttype = department.Split(',');
for (int i = 0; i <= extracttype.Length - 1; i++)
{
lsttype.Add(extracttype[i]);
}
Console.WriteLine(lsttype.ToList());

Thursday, July 19, 2018

How to Generate OTP and Random Number in C#


private static string GenerateOTP()
{
Random generator = new Random();
String r = generator.Next(0, 1000000).ToString("D6");
if (r.Distinct().Count() == 1)
{
r = GenerateOTP();
}
return r;
}

Friday, July 06, 2018

How to find the days a login password was last changed in SQL Server


How to find the days a login password was last changed in SQL Server?

declare @days int
SELECT @days=DATEDIFF(day, Max(entrydate),GETDATE()) from users where id='1'
select @days as days

Compare date in c#,Asp.net

How to  compare Current system date to Input date?


Function Call

bool resp = CompareDate("06-07-2017");

Function Method

static bool CompareDate(string strDateTime)
{
DateTime dtFinaldate; string sDateTime;
try
{
dtFinaldate = Convert.ToDateTime(strDateTime);
if (dtFinaldate.Year > DateTime.Now.Year)
{
return true;

}
else if (dtFinaldate.Year == DateTime.Now.Year)
{
if (dtFinaldate.Month > DateTime.Now.Month)
{
return true;

}
else if (dtFinaldate.Month == DateTime.Now.Month)
{
if (dtFinaldate.Day >= DateTime.Now.Day)
{
return true;
}
}
}
return false;
}
catch (Exception e)
{
string[] sDate = strDateTime.Split('/');
sDateTime = sDate[1] + '/' + sDate[0] + '/' + sDate[2];
dtFinaldate = Convert.ToDateTime(sDateTime);
if (dtFinaldate.Year > DateTime.Now.Year)
{
return true;

}
else if (dtFinaldate.Year == DateTime.Now.Year)
{
if (dtFinaldate.Month > DateTime.Now.Month)
{
return true;

}
else if (dtFinaldate.Month == DateTime.Now.Month)
{
if (dtFinaldate.Day >= DateTime.Now.Day)
{
return true;
}
}
}
return false;
}
}

Wednesday, July 04, 2018

Creating a Countdown Timer in Java Script


<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
text-align: center;
font-size: 60px;
margin-top:0px;
}
</style>
</head>
<body>

<p id="demo"></p>

<script>
// Set the date we're counting down to
var seconds = 25;
interval = setInterval(function () {
seconds = seconds - 1;
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = seconds;
// If the count down is over, write some text
if (seconds < 0) {
clearInterval(interval);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>

</body>
</html>

Saturday, June 30, 2018

Allow only numeric (0-9) Or Numeric With Decimal in HTML inputbox using jQuery


How to allow only numeric (0-9) Or Numeric With Decimal in HTML inputbox using jQuery?


I am creating a web page where I have an input text field in which I want to allow only numeric characters like (0,1,2,3,4,5...9) 0-9.


<script>
$(document).ready(function () {
//Allow Number Only in Textbox
$(".allownumber").on("keypress keyup blur", function (event) {
$(this).val($(this).val().replace(/[^\d].+/, ""));
if ((event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
//Allow Number Only in Textbox

//Allow Number With decimal Only in Textbox
$(".allownumberwithdecimal").on("keypress keyup blur", function (event) {
//this.value = this.value.replace(/[^0-9\.]/g,'');
$(this).val($(this).val().replace(/[^0-9\.]/g, ''));
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
//Allow Number With decimal Only in Textbox
});
</script>



<span>Float</span>
<input type="text" name="numeric" class='allownumberwithdecimal'>
<div>Numeric values only allowed (With Decimal Point) </div>
<br/> <br/> <br/>
<span>Int</span>
<input type="text" name="numeric" class='allownumber'>
<div>Numeric values only allowed (Without Decimal Point) </div>



Disable Browser Back Button after LogOut in ASP.Net using JavaScript


How to disable Back button in Browser after Logout using JavaScript.

Browser Back button cannot be disabled and hence in order to prevent User navigating to previous page, the User is redirected back to the Current page forcefully using JavaScript.

Disable Browser Back Button Script
The following JavaScript code snippet must be placed in the HEAD section of the Page where the User must be prevented from going back.
<script type = "text/javascript" >
   function preventBack(){window.history.forward();}
    setTimeout("preventBack()", 0);
    window.onunload=function(){null};
</script>

Home Page

The HTML Markup of Home page consists of an HTML Anchor link to the Logout page.
The Disable Browser Back Button Script is placed in the HEAD section so that User cannot access the Home page using Browser Back button from Logout page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home</title>
<script type="text/javascript">
function preventBack() { window.history.forward(); }
setTimeout("preventBack()", 0);
window.onunload = function () { null };
</script>
</head>
<body>
<h3>Home</h3>
<hr />
<a href="Logout.aspx">Logout</a>
</body>
</html>


Logout Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="logout.aspx.cs" Inherits="Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Logout</title>
</head>
<body>
<h3>Logout</h3>
</body>
</html>