Nitin Dhiman. Powered by Blogger.

Custom Validator in JQuery.Validate

No comments
$.validator.addMethod(
"regexName",
function(value, element) {
var check = false;
var re = new RegExp('^[a-zA-Z _0-9.]+$');
return this.optional(element) || re.test(value);
},
"No special characters allowed!"
);


rules: {
LoginName: {
required: true,
regexName:true
},

No comments :

Post a Comment

Open fancybox on Input Click

No comments
1)
$(document).ready(function()
{
$("#BTN").click(function()
{
$('test desc').fancybox().click();
});
});


2)

$("#buttontoclick").click(function() {
$('Friendly description').fancybox({
overlayShow: true
}).click();
});


3)

        function OpenPage(id) {
            $('dummy_anchor').fancybox({
                'frameWidth': 420, 'frameHeight': 413 // 'frameHeight': 232
            }).click();
        }

No comments :

Post a Comment

JS file with Server Side Variable

No comments
Javascript object and class concept

<_script_start>
var path = {
currentUrl: "",
getPath: function() {
return this.currentUrl;
},
TEST: function() {
alert(this.currentUrl);
}
}

script type="text/javascript">
path.currentUrl = '';
path.TEST();

No comments :

Post a Comment

authorized.net complete

No comments
after including previous four classes call this function on button click




private void DoPayment()
{
AuthorizeNetRequest objAuthorizeNetRequest = new AuthorizeNetRequest();

// This is the account information for merchant account given by Authorize.Net people in email
// I can see transaction history here.

objAuthorizeNetRequest.Login = LOGINID;
objAuthorizeNetRequest.Amount = Convert.ToDouble(txtAmount.Text);
objAuthorizeNetRequest.CardNumber = txtCreditCardNo.Text;
objAuthorizeNetRequest.CardExpirationDate = drpExpirationDate.SelectedValue + drpYear.SelectedValue.Substring(2);

objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.AUTH_CAPTURE;

///transaction types
///default is auth capture


//objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.AUTH_ONLY;
//objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.CREDIT;
//objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.VOID;

///we can use other types but will have to provide transaction id if we are going to
///PRIOR_AUTH_CAPTURE type as this will capture prior authorized transaction.

//objAuthorizeNetRequest.TransactionId = "";
//objAuthorizeNetRequest.TransactionType = AuthorizeNet.TransactionType.PRIOR_AUTH_CAPTURE;

objAuthorizeNetRequest.CcvNumber = txtCCV.Text;

// Below is the API created by me by registering for test account.
objAuthorizeNetRequest.TransactionKey = TRANSACTION_KEY;
AuthorizeNetFields allFields = new AuthorizeNetFields();

allFields.x_First_Name = txtCardName.Text;
allFields.x_Address = "";
allFields.x_City = "";
allFields.x_State = "";
allFields.x_Country = "U.S.A";
allFields.x_Phone = "";
allFields.x_Zip = "";
allFields.x_Tax = "";
allFields.x_Email = "";
allFields.x_Description = "";

allFields.x_Ship_to_first_name = txtCardName.Text;
allFields.x_Ship_to_address = "";
allFields.x_Ship_to_city = "";
allFields.x_Ship_to_state = "";
allFields.x_Ship_to_country = "U.S.A";
allFields.x_Ship_to_phone = "";
allFields.x_Ship_to_zip = "";

AuthorizeNetResponse objAuthorizeNetResponse = AuthorizeNet.CallAuthorizeNetMethod(objAuthorizeNetRequest, allFields);
if (objAuthorizeNetResponse.IsSuccess)
{
Response.Write(objAuthorizeNetResponse.SuccessMessage +" ID:"+ objAuthorizeNetResponse.TransactionId);
}
else
{
Response.Write("Error : " + objAuthorizeNetResponse.Errors);
}
}

No comments :

Post a Comment

part-3 AuthorizeNetRequest.cs

No comments
AuthorizeNet.cs
AuthorizeNetFields.cs
AuthorizeNetRequest.cs
AuthorizeNetResponse.cs






using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// 
/// Summary description for AuthorizeNetRequest
/// 


public class AuthorizeNetRequest
{
public AuthorizeNetRequest()
{
//
// TODO: Add constructor logic here
//
}

#region Private Member(s)
private string mstrLogin;
private double mdblAmount;
private string mstrTransactionKey;
private string mstrCardNumber;
private string mstrCcvNumber;
private string mstrCardExpirationDate;

private AuthorizeNet.TransactionType enmTransactionType;
private string mstrTransactionId;
#endregion

#region Public Propertie(s)
public string TransactionId
{
get { return mstrTransactionId; }
set { mstrTransactionId = value; }
}
public string CardNumber
{
get { return mstrCardNumber; }
set { mstrCardNumber = value; }
}

public string CcvNumber
{
get { return mstrCcvNumber; }
set { mstrCcvNumber = value; }
}
public double Amount
{
get { return mdblAmount; }
set { mdblAmount = value; }
}
public string Login
{
get { return mstrLogin; }
set { mstrLogin = value; }
}
public string CardExpirationDate
{
get { return mstrCardExpirationDate; }
set { mstrCardExpirationDate = value; }
}
public string TransactionKey
{
get { return mstrTransactionKey; }
set { mstrTransactionKey = value; }
}
public AuthorizeNet.TransactionType TransactionType
{
get { return enmTransactionType; }
set { enmTransactionType = value; }
}
#endregion
}

No comments :

Post a Comment

part-4 AuthorizeNetResponse.cs

No comments
AuthorizeNet.cs
AuthorizeNetFields.cs
AuthorizeNetRequest.cs
AuthorizeNetResponse.cs





using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
/// 
/// Summary description for AuthorizeNetResponse
/// 

public class AuthorizeNetResponse
{
public AuthorizeNetResponse()
{
//
// TODO: Add constructor logic here
//
}
private string mstrTransactionId;
private string mlstErrors;
private string mlstSuccessMessage;

public string SuccessMessage
{
get { return mlstSuccessMessage; }
set { mlstSuccessMessage = value; }
}
private bool mblnIsSuccess;
public bool IsSuccess
{
get { return mblnIsSuccess; }
set { mblnIsSuccess = value; }
}
public string Errors
{
get { return mlstErrors; }
set { mlstErrors = value; }
}
public string TransactionId
{
get { return mstrTransactionId; }
set { mstrTransactionId = value; }
}
}

No comments :

Post a Comment

part-2 AuthorizeNetFields.cs

No comments
AuthorizeNet.cs
AuthorizeNetFields.cs
AuthorizeNetRequest.cs
AuthorizeNetResponse.cs






using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// 
/// Summary description for AuthorizeNetFields
/// 

public class AuthorizeNetFields
{
public AuthorizeNetFields()
{
//
// TODO: Add constructor logic here
//
}
private string x_description = string.Empty;
public string x_Description
{
get { return x_description; }
set { x_description = value; }
}


private string x_first_name = string.Empty;
public string x_First_Name
{
get { return x_first_name; }
set { x_first_name = value; }
}
private string x_last_name = string.Empty;
public string x_Last_Name
{
get { return x_last_name; }
set { x_last_name = value; }
}


private string x_address = string.Empty;
public string x_Address
{
get { return x_address; }
set { x_address = value; }
}

private string x_city = string.Empty;
public string x_City
{
get { return x_city; }
set { x_city = value; }
}

private string x_state = string.Empty;

public string x_State
{
get { return x_state; }
set { x_state = value; }
}
private string x_zip = string.Empty;
public string x_Zip
{
get { return x_zip; }
set { x_zip = value; }
}

private string x_country = string.Empty;
public string x_Country
{
get { return x_country; }
set { x_country = value; }
}

private string x_phone = string.Empty;
public string x_Phone
{
get { return x_phone; }
set { x_phone = value; }
}

private string x_fax = string.Empty;
public string x_Fax
{
get { return x_fax; }
set { x_fax = value; }
}

private string x_email = string.Empty;
public string x_Email
{
get { return x_email; }
set { x_email = value; }
}



private string x_ship_to_first_name = string.Empty;
public string x_Ship_to_first_name
{
get { return x_ship_to_first_name; }
set { x_ship_to_first_name = value; }
}

private string x_ship_to_last_name = string.Empty;
public string x_Ship_to_last_name
{
get { return x_ship_to_last_name; }
set { x_ship_to_last_name = value; }
}

private string x_ship_to_company = string.Empty;
public string x_Ship_to_company
{
get { return x_ship_to_company; }
set { x_ship_to_company = value; }
}

private string x_ship_to_address = string.Empty;
public string x_Ship_to_address
{
get { return x_ship_to_address; }
set { x_ship_to_address = value; }
}

private string x_ship_to_city = string.Empty;
public string x_Ship_to_city
{
get { return x_ship_to_city; }
set { x_ship_to_city = value; }
}

private string x_ship_to_state = string.Empty;
public string x_Ship_to_state
{
get { return x_ship_to_state; }
set { x_ship_to_state = value; }
}

private string x_ship_to_zip = string.Empty;
public string x_Ship_to_zip
{
get { return x_ship_to_zip; }
set { x_ship_to_zip = value; }
}

private string x_ship_to_phone = string.Empty;
public string x_Ship_to_phone
{
get { return x_ship_to_phone; }
set { x_ship_to_phone = value; }
}
private string x_ship_to_country = string.Empty;
public string x_Ship_to_country
{
get { return x_ship_to_country; }
set { x_ship_to_country = value; }
}

private string x_tax = string.Empty;
public string x_Tax
{
get { return x_tax; }
set { x_tax = value; }
}
}

No comments :

Post a Comment

Part-I AuthorizeNet.cs

No comments
AuthorizeNet.cs
AuthorizeNetFields.cs
AuthorizeNetRequest.cs
AuthorizeNetResponse.cs

#region Namespaces

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Text;

using System.Net;

using System.IO;

using System.Collections;

using ClassLib.bl;

#endregion


public static class AuthorizeNet

{


#region Private Member(s)

private static string UNEXPECTED_ERROR = "Unexpected error";

private static string AUTHORIZENET_TEST_URL ="https://test.authorize.net/gateway/transact.dll";

private static string AUTHORIZENET_LIVE_URL ="https://secure.authorize.net/gateway/transact.dll";

#endregion


#region Transaction Type Enum(s)

public enum TransactionType

{

AUTH_CAPTURE = 0,

AUTH_ONLY,

PRIOR_AUTH_CAPTURE,

CREDIT,

VOID

}


public static string GetSringForEnum(TransactionType TransType)

{

switch (TransType)

{

case TransactionType.AUTH_CAPTURE:

return "AUTH_CAPTURE";

break;

case TransactionType.AUTH_ONLY:

return "AUTH_ONLY";

break;

case TransactionType.PRIOR_AUTH_CAPTURE:

return "PRIOR_AUTH_CAPTURE";

break;

case TransactionType.CREDIT:

return "CREDIT";

break;

case TransactionType.VOID:

return "VOID";

break;

default:

return string.Empty;

break;

}

}

#endregion

private static string GetRequestString(AuthorizeNetRequestobjAuthorizeNetRequest, AuthorizeNetFields allFields, TransactionTypeTransType)

{

Hashtable post_values = new Hashtable();

post_values.Add("x_login", objAuthorizeNetRequest.Login);

post_values.Add("x_tran_key", objAuthorizeNetRequest.TransactionKey);


post_values.Add("x_delim_data", "TRUE");

post_values.Add("x_delim_char", '|');

post_values.Add("x_relay_response", "FALSE");


post_values.Add("x_type", GetSringForEnum(TransType));

post_values.Add("x_method", "CC");

post_values.Add("x_card_num", objAuthorizeNetRequest.CardNumber);

post_values.Add("x_exp_date", objAuthorizeNetRequest.CardExpirationDate);

post_values.Add("x_Card_Code", objAuthorizeNetRequest.CcvNumber);


post_values.Add("x_amount", objAuthorizeNetRequest.Amount);

post_values.Add("x_description", allFields.x_Description);

post_values.Add("x_tax", allFields.x_Tax);


post_values.Add("x_first_name", allFields.x_First_Name);

post_values.Add("x_last_name", allFields.x_Last_Name);

post_values.Add("x_address", allFields.x_Address);

post_values.Add("x_city", allFields.x_City);

post_values.Add("x_zip", allFields.x_Zip);

post_values.Add("x_state", allFields.x_State);

post_values.Add("x_country", allFields.x_Country);

post_values.Add("x_phone", allFields.x_Phone);

post_values.Add("x_email", allFields.x_Email);


post_values.Add("x_ship_to_first_name", allFields.x_Ship_to_first_name);

post_values.Add("x_ship_to_last_name", allFields.x_Ship_to_last_name);

post_values.Add("x_ship_to_address", allFields.x_Ship_to_address);

post_values.Add("x_ship_to_city", allFields.x_Ship_to_city);

post_values.Add("x_ship_to_state", allFields.x_Ship_to_state);

post_values.Add("x_ship_to_zip", allFields.x_Ship_to_zip);

post_values.Add("x_ship_to_country",allFields.x_Ship_to_country);


if (TransType == TransactionType.CREDIT || TransType ==TransactionType.PRIOR_AUTH_CAPTURE || TransType == TransactionType.VOID)

{

post_values.Add("x_trans_id", objAuthorizeNetRequest.TransactionId);

}

String post_string = "";

foreach (DictionaryEntry field in post_values)

{

post_string += field.Key + "=" + field.Value + "&";

}

post_string = post_string.TrimEnd('&');


return post_string;

}


public static AuthorizeNetResponse CallAuthorizeNetMethod(AuthorizeNetRequestobjAuthorizeNetRequest, AuthorizeNetFields allFields)
{
HttpWebRequest objRequest = null;
if (ReadConfig.IsTestPayment)
{
objRequest = (HttpWebRequest)WebRequest.Create(AUTHORIZENET_TEST_URL);
}
else
{
objRequest = (HttpWebRequest)WebRequest.Create(AUTHORIZENET_LIVE_URL);
}
objRequest.Method = "POST";
string postData = GetRequestString(objAuthorizeNetRequest, allFields, objAuthorizeNetRequest.TransactionType);
ASCIIEncoding enco = new ASCIIEncoding();
byte[] byte1 = enco.GetBytes(postData);
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.ContentLength = byte1.Length;
Stream myWriter = objRequest.GetRequestStream();
myWriter.Write(byte1, 0, byte1.Length);
myWriter.Close();
String post_response;
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader responseStream = newStreamReader(objResponse.GetResponseStream()))
{
post_response = responseStream.ReadToEnd();
responseStream.Close();
}
Array response_array = post_response.Split('|');
AuthorizeNetResponse objAuthorizeNetResponse = new AuthorizeNetResponse();
HandleResponse(post_response, objAuthorizeNetResponse);
return objAuthorizeNetResponse;
}
private static void HandleError(AuthorizeNetResponse objAuthorizeNetResponse,string ErrorMessage)
{
objAuthorizeNetResponse.IsSuccess = false;
objAuthorizeNetResponse.Errors = ErrorMessage;
}
private static void HandleResponse(string strResponse, AuthorizeNetResponseobjAuthorizeNetResponse)
{
string[] strWebResponse = strResponse.Split(new char[] { '|' },StringSplitOptions.None);
if (strResponse != null)
{
if (strWebResponse[0] == "1")
{
objAuthorizeNetResponse.IsSuccess = true;
if (strWebResponse.Length > 3)
objAuthorizeNetResponse.SuccessMessage = strWebResponse[3];
if (strWebResponse.Length > 6)
objAuthorizeNetResponse.TransactionId = strWebResponse[6];
}
else
{
if (strWebResponse.Length > 3)
HandleError(objAuthorizeNetResponse, strWebResponse[3]);
else
HandleError(objAuthorizeNetResponse, UNEXPECTED_ERROR);
}
}
else
{
HandleError(objAuthorizeNetResponse, UNEXPECTED_ERROR);
}
}
}

No comments :

Post a Comment

Javascript function to set cookies

No comments
function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

No comments :

Post a Comment

Recursion in sql stored procedure

No comments
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[uspGetCardsByCatID] (@catId int)
as
BEGIN
/*Recursion*/
with RecursionCTE (iCategoryId_PK,iParentCategoryId_FK,sTitle, bIsActive)
as
(
select *
from vwCategory
where iParentCategoryId_FK = @catId and bIsActive = 1
union all
select R1.*
from vwCategory as R1
join RecursionCTE as R2 on R1.iParentCategoryId_FK = R2.iCategoryId_PK
)
/*End Recusion*/
Select * from dbo.vwCard where iCategoryId_FK = @catId or iCategoryId_FK in (select iCategoryId_PK from RecursionCTE) order by (iTotalCustomizeOrders + iTotalBlankOrders) DESC
END

No comments :

Post a Comment

javascript to change group name

No comments
change group name :
<script language="javascript" type="text/javascript">
function changeValidationGrop(){
var btn = document.getElementById("<%=Button1.ClientID %>");
//rfvUsername = document.getElementById("<% = rfvUsername.ClientID %>");
//rfvUsername.ValidationGroup = "Demo";
//alert(rfvUsername.ValidationGroup);
btn.onclick = function(){
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("Button1", "", true, "Customer", "", false, false));
}
}
<script>

No comments :

Post a Comment