New features of VS 2010

Posted: April 22, 2010 in 1

For more info on VS 2010 check out this link:

VS 2010 Features

Query to find the list of Triggers in the database categorized with Trigger Type

SELECT S2.[name] TableName, S1.[name] TriggerName,
CASE
WHEN S1.deltrig > 0 THEN ‘Delete’
WHEN S1.instrig > 0 THEN ‘Insert’
WHEN S1.updtrig > 0 THEN ‘Update’
END ‘TriggerType’
FROM sysobjects S1 JOIN sysobjects S2
ON S1.parent_obj = S2.[id]
WHERE S1.xtype=’TR’

Advertisement

Following code can be used to validate a credit card number and to get the card brand
by card number:

///
/// Enum for card type.
///
public enum CardType
{
MasterCard = 1,
BankCard = 2,
Visa = 3,
AmericanExpress = 4,
Discover = 5,
DinersClub = 6,
JCB = 7,
unKnown = 8
}

///
/// It Will ensure that the card is a valid length for the card type. If the
/// card type isn’t recognised it will return false by default.
///
/// The ValidateCreditCard method also includes a CardTypes property that determines
/// what card types should be accepted. If the card isn’t recognised, and the Unknown card
/// type is in the AcceptedCardTypes property then the DefaultLengthTest value will be
/// returned.
///
public bool ValidateCreditCard(string cardNumber)
{
try
{// AMEX — 34 or 37 — 15 length
if ((Regex.IsMatch(cardNumber, “^(34|37)”)) && cardNumber.Length == 15)
{
CardBrand = CardType.AmericanExpress;
return true;
}
// MasterCard — 51 through 55 — 16 length
else if ((Regex.IsMatch(cardNumber, “^(51|52|53|54|55)”)) && 16 == cardNumber.Length)
{
CardBrand = CardType.MasterCard;
return true;
} // VISA — 4 — 13 and 16 length
else if ((Regex.IsMatch(cardNumber, “^(4)”)) && (13 == cardNumber.Length || 16 == cardNumber.Length))
{
CardBrand = CardType.Visa;
return true;
}
// Diners Club — 300-305, 36 or 38 — 14 length
else if ((Regex.IsMatch(cardNumber, “^(300|301|302|303|304|305|36|38)”)) && 14 == cardNumber.Length)
{
CardBrand = CardType.DinersClub;
return true;
}

// // enRoute — 2014,2149 — 15 length
// else if ((Regex.IsMatch(cardNumber, “^(2014|2149)”)) && 15 == cardNumber.Length)
// {
// CardBrand = CardType = “enROUTE”;
// return true;
// }
// Discover — 6011 — 16 length
else if ((Regex.IsMatch(cardNumber, “^(6011)”)) && 16 == cardNumber.Length)
{
CardBrand = CardType.Discover;
return true;
}
// JCB — 3 — 16 length
else if ((Regex.IsMatch(cardNumber, “^(3)”)) && 16 == cardNumber.Length)
{
CardBrand = CardType.JCB;
return true;

} // JCB — 2131, 1800 — 15 length
else if ((Regex.IsMatch(cardNumber, “^(2131|1800)”)) && 15 == cardNumber.Length)
{
CardBrand = CardType.JCB;
return true;
}
else
{
CardBrand = CardType.unKnown;
return false; //unknown card
}
}
catch (Exception ex)
{
throw ex;
}
}

_________________________________________________

Validating CARD VERIFICATION VALUE CODE

public bool ValidateCVVCode()
{
try
{
var digits = 0;
switch (CardBrand)
{
case CardType.MasterCard:
case CardType.BankCard:
case CardType.Visa:
case CardType.Discover:
case CardType.DinersClub:
case CardType.JCB:
digits = 3;
break;
case CardType.AmericanExpress:
digits = 4;
break;
default:
break;
}

Regex regEx = new Regex(“[0-9]{” + digits + “}”);
return (this.CVV == digits.ToString() && regEx.Match(this.CVV).Success);
}
catch (Exception ex)
{
throw ex;
}
}

Sql Caching in asp.net

Posted: February 8, 2010 in asp.net

VS command prompt

>aspnet_regsql -S streamline -U gamepoint1979 -P gamepoint1979 ed -d gamepoint2

>aspnet_regsql -S streamline -U gamepoint1979 -P gamepoint1979 -d gamepoint2 -et -t Teams

>aspnet_regsql -S streamline -U gamepoint1979 -P gamepoint1979 -d gamepoint2 -et -t MatchSetups

>aspnet_regsql -S streamline -U gamepoint1979 -P gamepoint1979 -d gamepoint2 -et -t MatchResults

WebConfig

Change the name of database from Gamepoint2 to the new database

Change the ‘connectionStringName‘ from Local to the connection being used

Some Common Date Routines in Sql Server

Posted: September 25, 2009 in 1
Tags:

declare @ThisDate datetime;
set @ThisDate = getdate();

select dateadd(dd, datediff(dd, 0, @ThisDate), 0) — Beginning of this day
select dateadd(dd, datediff(dd, 0, @ThisDate) + 1, 0) — Beginning of next day
select dateadd(dd, datediff(dd, 0, @ThisDate) – 1, 0) — Beginning of previous day
select dateadd(wk, datediff(wk, 0, @ThisDate), 0) — Beginning of this week (Monday)
select dateadd(wk, datediff(wk, 0, @ThisDate) + 1, 0) — Beginning of next week (Monday)
select dateadd(wk, datediff(wk, 0, @ThisDate) – 1, 0) — Beginning of previous week (Monday)
select dateadd(mm, datediff(mm, 0, @ThisDate), 0) — Beginning of this month
select dateadd(mm, datediff(mm, 0, @ThisDate) + 1, 0) — Beginning of next month
select dateadd(mm, datediff(mm, 0, @ThisDate) – 1, 0) — Beginning of previous month
select dateadd(qq, datediff(qq, 0, @ThisDate), 0) — Beginning of this quarter (Calendar)
select dateadd(qq, datediff(qq, 0, @ThisDate) + 1, 0) — Beginning of next quarter (Calendar)
select dateadd(qq, datediff(qq, 0, @ThisDate) – 1, 0) — Beginning of previous quarter (Calendar)
select dateadd(yy, datediff(yy, 0, @ThisDate), 0) — Beginning of this year
select dateadd(yy, datediff(yy, 0, @ThisDate) + 1, 0) — Beginning of next year
select dateadd(yy, datediff(yy, 0, @ThisDate) – 1, 0) — Beginning of previous year

Happy T-SQL

ASP.NET AJAX

Posted: May 5, 2009 in ajax, asp.net

Microsoft ASP.NET AJAX enables you to call ASP.NET Web services (.asmx files) from the browser by using client script. This enhances the user experience for the Web application. The page can call server-based methods without a postback and without refreshing the whole page, because only data is transferred between the browser and the Web server.

Assign the webservice that needs to be exposed to the script manager.When the script manager receives any service references it will create the javascript needed to access that webservice’s public methods

The following example shows these attributes in Web service code

[System.Web.Script.Services.ScriptService]
public class TournamentMonitor : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld(int x)
{
return “Hello World”;
}
}

In order for a Web service to be accessed from script, it must be an .asmx Web service whose Web service class is qualified with the ScriptServiceAttribute attribute. Individual methods to be called from script must be qualified with the WebMethodAttribute attribute.
You can also call an WCF file through this method

Javascript Method to access the webservice method
GamePoint.WebApp.WebServices.TournamentMonitor.HelloWorld(param1,onDataAvailable,onFailure,Context)

here you are calling the webservices method HelloWorld() directly from the javascript call

param1-paramenter the method access
onDataAvailable-Callback method .This is the function which will be raised when the call from the webservice returns
onFailure-Function raised if any error occurs
Context-Any javascript object that you need to access in the Callback method(onDataAvailable)

Callback method
function onDataAvailable(result,context,methodName)
{
result-result in the form of JSON returned from the webservice
context- javascript object that was passed from the calling function
methodName -name of the method which raised the callback function
}

For further information
http://www.asp.net/ajax/documentation/l … orial.aspx

Microsoft AJAX Library

Posted: May 5, 2009 in ajax, asp.net

To know the core concepts of Microsoft AJAX Library and how to add OOPS functionality on Javascript please review the attached ppt..

microsoft-ajax-library

MVC Introduction

Posted: May 5, 2009 in asp.net, Blogroll
Tags:

Here’s quick and short presentation that tells What exactly is MVC Architectural Pattern..

Going forward I will Post more articles/presentations on it which are simple and easily understandable by the reader.

mvcintro

Handling radiobutton events inside gridview

Posted: November 24, 2007 in ajax

 protected void rdRegularChecked(Object sender, EventArgs e)
    {
        RadioButton rdRegular= (RadioButton)sender ;
        GridViewRow gvr = (GridViewRow)rdRegular.NamingContainer;
        Int32 rowIndex = gvr.RowIndex;
        Label lblregular = (Label)Grid_Available.Rows[rowIndex].FindControl(“lbltarrif”);
        lblregular.Text = “regular”;      
    }

creating jcrousel

Posted: October 6, 2007 in ajax, asp.net

<!–jQuery library–><script type=”text/javascript” src=”lib/jquery-1.1.2.pack.js”></script><!–jCarousel library–><script type=”text/javascript” src=”lib/jquery.jcarousel.pack.js”></script><!–jCarousel core stylesheet–><link rel=”stylesheet” type=”text/css” href=”lib/jquery.jcarousel.css” /><!–jCarousel skin stylesheet–><link rel=”stylesheet” type=”text/css” href=”skins/ie7/skin.css” /><script type=”text/javascript”>function mycarousel_itemLoadCallback(carousel, state){// Since we get all URLs in one file, we simply add all items// at once and set the size accordingly.if (state != ‘init’)return;

// else// carousel.options.visible=2;jQuery.get(‘files/dynamic_ajax.txt’, function(data) {mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);});};function mycarousel_itemAddCallback(carousel, first, last, data){// Simply add all items at once and set the size accordingly.var items = data.split(‘|’);for (i = 0; i < items.length; i++) {carousel.add(i+1, mycarousel_getItemHTML(items[i]));}carousel.size(items.length);};

/*** Item html creation helper.*/function mycarousel_getItemHTML(url,alt){return url;};jQuery(document).ready(function() {jQuery(‘#mycarousel’).jcarousel({itemLoadCallback: mycarousel_itemLoadCallback});});</script><tr><td><div id=”mycarousel” class=”jcarousel-skin-ie7″><ul>

<!– The content will be dynamically loaded in here –></ul> </div></td></tr><!– Download skins and libarary files of jcrousal from the link given below –>http://sorgalla.com/jcarousel/

//code to write to text file

protected void generateData(){

SqlConnection con = new SqlConnection();con.ConnectionString = ConfigurationManager.ConnectionStrings[“cn”].ConnectionString;try

{

if (con.State == ConnectionState.Closed){

con.Open();

}

SqlDataAdapter dap = new SqlDataAdapter(“SELECT top 25 modelid,thumb1,modfname FROM tbl_model where enabled=1 ORDER BY NEWID()”, con);DataTable dt = new DataTable();dap.Fill(dt);

StreamWriter write = new StreamWriter(MapPath(“files/dynamic_ajax.txt”));

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

if (i == dt.Rows.Count – 1){

write.WriteLine(“<a href=’modelDetails.aspx?id=” + dt.Rows[i][0].ToString() + “‘><img src='” + dt.Rows[i][1].ToString() + “‘ alt='” + dt.Rows[i][2].ToString()+“‘ /></a>”);}

else

{

write.WriteLine(“<a href=’modelDetails.aspx?id=” + dt.Rows[i][0].ToString() + “‘><img src='” + dt.Rows[i][1].ToString() + “‘ alt='” + dt.Rows[i][2].ToString()+“‘ /></a>|”);}

}

write.Dispose();

}

catch (Exception ex){

}

}