Monday, July 25, 2011
Payment Gateway with paypal in asp.net with c#
System;
using System.Data;
using System.Configuration;
using System.Collections;
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 com.paypal.sdk.profiles;
using com.paypal.sdk.services;
using com.paypal.sdk.services;
using log4net;
public partial class PaypalPayment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CallerServices caller = new CallerServices();
IAPIProfile profile = ProfileFactory.CreateAPIProfile();
profile.APIUsername ="nitin._1214308341_biz_api1.gmail.com";//
"sdk-seller_api1.sdk.com";
profile.APIPassword ="1214308348";// "12345678";
profile.Environment ="sandbox";
profile.Subject ="";
profile.APISignature ="A5GwH2U8prt9wuPnGmlizZVpeMthAn39AxoXc.I0NyrkrNlL8dUfnjII";
caller.APIProfile = profile;
com.paypal.soap.api.DoDirectPaymentRequestDetailsType directPaymentDetails =
new com.paypal.soap.api.DoDirectPaymentRequestDetailsType();
//Set Credit Card
com.paypal.soap.api.CreditCardDetailsType cc = new
com.paypal.soap.api.CreditCardDetailsType();
cc.CreditCardType = com.paypal.soap.api.CreditCardTypeType.Visa;
cc.CreditCardNumber ="4111111111111111";
cc.ExpMonth=10;
cc.ExpYear = 2009;
cc.CVV2 ="123";
//Set Credit Card.CardOwner
com.paypal.soap.api.PayerInfoType theCardOwner = new
com.paypal.soap.api.PayerInfoType();
com.paypal.soap.api.PersonNameType thePayerName = new
com.paypal.soap.api.PersonNameType();
thePayerName.FirstName ="John";
thePayerName.LastName ="Doe";
theCardOwner.PayerName = thePayerName;
com.paypal.soap.api.AddressType theAddress = new
com.paypal.soap.api.AddressType();
theAddress.Street1 ="123 Main";
theAddress.Street2 ="Apt 23";
theAddress.CityName ="Hill Side";
theAddress.StateOrProvince ="FL";
theAddress.PostalCode ="32550";
theAddress.Country = com.paypal.soap.api.CountryCodeType.US;
theCardOwner.Address = theAddress;
cc.CardOwner = theCardOwner;
directPaymentDetails.CreditCard = cc;
//Set Order Total
com.paypal.soap.api.BasicAmountType temp = new
com.paypal.soap.api.BasicAmountType();
com.paypal.soap.api.PaymentDetailsType payDetailType = new
com.paypal.soap.api.PaymentDetailsType();
temp.Value ="118.25";
temp.currencyID =
com.paypal.soap.api.CurrencyCodeType.USD;payDetailType.OrderTotal = temp;
directPaymentDetails.PaymentDetails = payDetailType;
//Set IP
directPaymentDetails.IPAddress ="192.168.200.195";
//Set Transaction Type
directPaymentDetails.PaymentAction =
com.paypal.soap.api.PaymentActionCodeType.Sale;
//Set Request
com.paypal.soap.api.DoDirectPaymentRequestType request = new
com.paypal.soap.api.DoDirectPaymentRequestType();
//Set Payment Detail
request.DoDirectPaymentRequestDetails = directPaymentDetails;
request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified
=true;
com.paypal.soap.api.DoDirectPaymentResponseType response =
(com.paypal.soap.api.DoDirectPaymentResponseType)caller.Call("DoDirectPayment"
, request);
Response.Write("response=" + response.Ack);
Response.Write(
"
response=" + response.Errors[0].LongMessage.ToString() + " - " +
response.Errors[0].ErrorCode.ToString());
Tag: paypal, soap, add paypal, simple add paypal, step by step add paypal, paypal sample code in c#.net asp.net, paypal soap request api do direct payment c# request, paypal sdk asp.net items, com.paypal.sdk.profiles for asp.net
Sunday, July 17, 2011
All Asp Data control uses in one program code
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//bind();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Columns.Add("City");
ds.Tables.Add(dt);
if (ds.Tables[0].Rows.Count == 0)
{
DataRow dr = dt.NewRow();
dr[0] = "1";
dr[1] = "mithilesh";
dr[2] = "varanasi";
dt.Rows.Add(dr);
//ds.Tables.Add(dt);
}
GridView2.DataSource = dt;
GridView2.DataBind();
}
}
public void bind()
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
cn.Open();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("select * from emp", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
//GridView1.DataSource = dt;
//GridView1.DataBind();
//Repeater1.DataSource = dt;
//Repeater1.DataBind();
//DataList1.DataSource = dt;
//DataList1.DataBind();
//DetailsView1.DataSource = dt;
//DetailsView1.DataBind();
//FormView1.DataSource = dt;
//FormView1.DataBind();
//ListView1.DataSource = dt;
//ListView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//SqlConnection cn = new SqlConnection();
//cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
//cn.Open();
//int i=Convert.ToInt32(GridView1.SelectedIndex);
//int id = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);
//string a = GridView1.Rows[i].Cells[1].Text;
//string b = GridView1.Rows[i].Cells[2].Text;
//string c = GridView1.Rows[i].Cells[3].Text;
//TextBox1.Text = id.ToString();
//TextBox2.Text = a.ToString();
//TextBox3.Text = b.ToString();
//TextBox4.Text = c.ToString();
//bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//GridView1.EditIndex = e.NewEditIndex;
//bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//SqlConnection cn = new SqlConnection();
//cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
//cn.Open();
//int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text);
//SqlCommand cmd = new SqlCommand("delete from emp where eid='" + id + "'",cn);
//cmd.ExecuteNonQuery();
//bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//GridView1.EditIndex = -1;
//bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
// SqlConnection cn = new SqlConnection();
// cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
// cn.Open();
// Int32 id = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text);
// string a = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
// string b = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
//string c = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
// SqlCommand cm = new SqlCommand("update emp set enmae='" + a + "',ecity='" + b + "',econtact='" + c + "' where eid='" + id + "'", cn);
// cm.ExecuteNonQuery();
// GridView1.EditIndex = -1;
// bind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void TextBox3_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//SqlConnection cn = new SqlConnection();
//cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
//cn.Open();
//SqlCommand cm = new SqlCommand("update emp set enmae='" +TextBox2.Text+ "',ecity='" + TextBox3.Text+ "',econtact='" +TextBox4.Text + "' where eid='" + Convert.ToInt32(TextBox1.Text) + "'", cn);
//cm.ExecuteNonQuery();
//bind();
//TextBox1.Text = "";
//TextBox2.Text = "";
//TextBox3.Text = "";
//TextBox4.Text = "";
foreach (GridViewRow ch in GridView1.Rows)
{
CheckBox c = (CheckBox)GridView1.Rows[ch.RowIndex+1].FindControl("CheckBox1");
if(c.Checked==true)
{
int id = Convert.ToInt32(GridView1.Rows[ch.RowIndex+1].Cells[0].Text);
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
cn.Open();
SqlCommand cm = new SqlCommand("delete from emp where eid='" + id + "'", cn);
cm.ExecuteNonQuery();
bind();
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//SqlConnection cn = new SqlConnection();
//cn.ConnectionString = "data source=RANJAN-PC;initial catalog=mithilesh;uid=sa;pwd=chandan;integrated security=false";
//cn.Open();
//SqlCommand cm = new SqlCommand("insert into emp values('" + Convert.ToInt32(TextBox1.Text) + "','" + TextBox2.Text.ToString() + "','" + TextBox3.Text.ToString() + "','" + TextBox4.Text.ToString() + "')", cn);
//cm.ExecuteNonQuery();
//bind();
//TextBox1.Text = "";
//TextBox2.Text = "";
//TextBox3.Text = "";
//TextBox4.Text = "";//int i = 0;
//if (e.CommandName.Equals("delete"))
//{
int i=0;
foreach (RepeaterItem ri in Repeater1.Items)
{
CheckBox c = (CheckBox)ri.FindControl("chk1");
if (c.Checked == true)
{
i = Convert.ToInt32(c);
}
}
Response.Write("total chk is" + i.ToString());
//}
}
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
bind();
}
protected void DetailsView1_PageIndexChanged(object sender, EventArgs e)
{
}
protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
FormView1.PageIndex = e.NewPageIndex;
bind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//CheckBox chk = (CheckBox)e.Item.FindControl("chk");
//if (chk.Checked == true)
//{
// Response.Write("check");
//}
}
protected void Button3_Command(object sender, CommandEventArgs e)
{
//int i = 0;
//if (e.CommandName.Equals("delete"))
//{
// foreach (RepeaterItem ri in Repeater1.Items)
// {
// CheckBox c = (CheckBox)ite
// if (c.Checked == true)
// {
// i = i + 1;
// }
// }
// Response.Redirect("total chk is" + i.ToString());
//}
}
}
Friday, July 15, 2011
Client side validation Using Javascript
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Pagetitle>
<script language="javascript" type="text/javascript">
function valid()
{
if(document.getElementById('TextBox1').value=="")
{
alert("blank");
document.getElementById('TextBox1').focus();
return false;
}
if(document.getElementById('TextBox1').value.length<3)
{
alert("short length");
document.getElementById('TextBox1').focus();
return false;
}
if(document.getElementById('TextBox2').value=="")
{
alert("again blank");
document.getElementById('TextBox2').focus();
return false;
}
if(document.getElementById('TextBox3').value=="")
{
alert("this field can not be blank")
document.getElementById('TextBox3').focus();
return false;
}
// if(document.getElementById('TextBox3').value!=document.getElementById('TextBox2').value)
// {
// alert("both field are not same")
// document.getElementById('TextBox3').focus();
// return false;
// }
var add=/^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var eadd=document.getElementById('TextBox3').value;
var myarray=eadd.match(add);
if(myarray==null)
{
alert("not in correct format");
document.getElementById('TextBox3').focus();
return false;
}
return true
}
script>
head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:TextBox ID="TextBox1" runat="server">asp:TextBox>
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server">asp:TextBox>
<br />
<br />
<asp:TextBox ID="TextBox3" runat="server">asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="return valid()" onclick="Button1_Click1" />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
div>
form>
body>
html>
code of armestrong no,,,febo series,,,palindrome
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//int i, j;
//for (i = 0; i < 4; i++)
//{
// for (j = 4; j > i; j--)
// {
// System.Console.Write("*");
// }
// System.Console.WriteLine();
//}
//System.Console.ReadLine();
////////// for checking palindrome no......
//System.Console.WriteLine("Please enter any no to check wheather it is palindrome or not?");
//int i, j, k, l;
//l = 0;
//string s = System.Console.ReadLine();
//i = Convert.ToInt16(s);
//j = i;
//while (i != 0)
//{
// k = i % 10;
// l = l * 10 + k;
// i = i / 10;
//}
//if (j == l)
//{
// System.Console.WriteLine("Its is palindrome no");
//}
//else
//{
// System.Console.WriteLine("it is not palindrome");
//}
//System.Console.ReadLine();
///////////for armestrong no;;;;
//System.Console.WriteLine("Please enter any no to check wheather it is armestrong or not?");
//int i, j, k, l;
//l = 0;
//string s = System.Console.ReadLine();
//i = Convert.ToInt16(s);
//j = i;
//while (i != 0)
//{
// k = i % 10;
// l = (l + k * k * k);
// i = i / 10;
//}
//if (j == l)
//{
// System.Console.WriteLine("Its is armestrong no");
//}
//else
//{
// System.Console.WriteLine("it is not armestrong");
//}
//System.Console.ReadLine();
int i, j;
int fib=1;
i = -1;
j = 1;
int n = 50;
while (fib <= n)
{
fib = i + j;
i = j;
j = fib;
System.Console.WriteLine(fib.ToString());
}
System.Console.ReadLine();
}
}
}