Monday, November 19, 2012

3 tier architecture


using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Data;
using System.Collections;
DAL:

namespace DAL
{
   public class DbConnection
    {
        SqlConnection con;
        SqlCommand cmd;
        SqlDataAdapter adp;
        StringBuilder sb;
        SqlDataReader _rdr;

        public DbConnection()
        {
            con = new SqlConnection(ConfigurationSettings.AppSettings["conn"].ToString());
            sb = new StringBuilder("");
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        public void OpenDbConnection()
        {
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
        }
        public void CloseDbConnection()
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
        public SqlCommand GetDbCommand()
        {
            if (cmd != null)
            {
                return cmd;
            }
            else
            {
                cmd = new SqlCommand();
                cmd.Connection = con;
                return cmd;
            }
        }
        public int ExecuteNonQuery(string _spname, SqlParameter[] sp_param)
        {
            OpenDbConnection();
            cmd = GetDbCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = _spname;
            foreach (SqlParameter _parm in sp_param)
            {
                cmd.Parameters.Add(_parm);
            }
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        public ArrayList GetAdminLogininfo(string username, string password)
        {
            OpenDbConnection();
            cmd = GetDbCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Pipe_SP_AdminLogin";
            cmd.Parameters.AddWithValue("@username", username);
            cmd.Parameters.AddWithValue("@password", password);
            cmd.Parameters.Add("@returnVar", SqlDbType.Bit);
            cmd.Parameters["@returnVar"].Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@ID", SqlDbType.Int);
            cmd.Parameters["@ID"].Direction = ParameterDirection.Output;
                 
            cmd.ExecuteNonQuery();
            ArrayList result = new ArrayList();
            result.Add(cmd.Parameters["@returnVar"].Value);
         
            result.Add(cmd.Parameters["@ID"].Value);
     

            return result;
       
                }
        public ArrayList GetRepLogininfo(string username, string password)
        {
            OpenDbConnection();
            cmd = GetDbCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Pipe_SP_RepLogin";
            cmd.Parameters.AddWithValue("@username", username);
            cmd.Parameters.AddWithValue("@password", password);
            cmd.Parameters.Add("@returnVar", SqlDbType.Bit);
            cmd.Parameters["@returnVar"].Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@ID", SqlDbType.Int);
            cmd.Parameters["@ID"].Direction = ParameterDirection.Output;

            cmd.ExecuteNonQuery();
            ArrayList result = new ArrayList();
            result.Add(cmd.Parameters["@returnVar"].Value);

            result.Add(cmd.Parameters["@ID"].Value);


            return result;

        }
        public ArrayList GetClientLogininfo(string Email, string password)
        {
            OpenDbConnection();
            cmd = GetDbCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "SUB_SP_GetClientLoginInfo";
            cmd.Parameters.AddWithValue("@Email", Email);
            cmd.Parameters.AddWithValue("@password", password);
            cmd.Parameters.Add("@returnVar", SqlDbType.Bit);
            cmd.Parameters["@returnVar"].Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@ClientID", SqlDbType.Int);
            cmd.Parameters["@ClientID"].Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@OrgId", SqlDbType.VarChar, 50);
            cmd.Parameters["@OrgId"].Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
            ArrayList result = new ArrayList();
            result.Add(cmd.Parameters["@returnVar"].Value);
            result.Add(cmd.Parameters["@ClientID"].Value);
            result.Add(cmd.Parameters["@OrgID"].Value);

            return result;
        }



        public DataTable ExecuteDataTable(string _spname, SqlParameter[] sp_param)
        {
            OpenDbConnection();
            cmd = GetDbCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = _spname;
            if (sp_param != null)
            {
                foreach (SqlParameter _parm in sp_param)
                {
                    cmd.Parameters.Add(_parm);
                }
            }
            DataSet dt = new DataSet();
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(dt);
            adp.Dispose();
            cmd.Dispose();
            CloseDbConnection();
            return dt.Tables[0];
        }
        public int ExecuteScalar(string _sql)
        {
            OpenDbConnection();
            cmd = GetDbCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = _sql;
            int count = int.Parse(cmd.ExecuteScalar().ToString());
            cmd.Dispose();
            CloseDbConnection();
            return count;
        }
        public SqlDataReader ExecuteReader(string _sql)
        {
            OpenDbConnection();
            cmd = GetDbCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = _sql;
            _rdr = cmd.ExecuteReader();
            return _rdr;
        }
        public DataTable ExecuteDT(string _Sql)
        {
            cmd = GetDbCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = _Sql;
            DataSet dt = new DataSet();
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(dt);
            adp.Dispose();
            cmd.Dispose();
            return dt.Tables[0];
        }
        //public SqlDataAdapter GetDataAdaptor()
        //{
        //    if (adp != null)
        //    {
        //        return adp;
        //    }
        //    else
        //    {
        //        adp = new SqlDataAdapter(;

        //    }
        //}
    }


}


BAL :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DAL;

namespace BAL
{
   public class ClsAddLeads
    {

        #region "Properties"

        public int ID { get; set; }
        public int RepsID { get; set; }
        public int LeadsID { get; set; }
        public DateTime DateAdded { get; set; }
        public string Fname { get; set; }
        public string Contact { get; set; }
        public string Position { get; set; }
        public DateTime LastContactDate { get; set; }
        public string Phone { get; set; }
        public string LegacyPartner { get; set; }
        public string Investment { get; set; }
        public string Notes { get; set; }  
        public string Mode { get; set; }

        #endregion

        #region "All Insert,Update,Delete operation are done"
        public int Leads()
        {
            DbConnection _clsdb = new DbConnection();
            SqlParameter[] _sp = new SqlParameter[11];
            _sp[0] = new SqlParameter("@ID", ID);
            _sp[1] = new SqlParameter("@RepsID", RepsID);
            _sp[2] = new SqlParameter("@Fname", Fname);
            _sp[3] = new SqlParameter("@Contact", Contact);
            _sp[4] = new SqlParameter("@Position", Position);
            _sp[5] = new SqlParameter("@LastContactDate",Convert.ToDateTime(LastContactDate));
            _sp[6] = new SqlParameter("@Phone", Phone);
            _sp[7] = new SqlParameter("@LegacyPartner", LegacyPartner);
            _sp[8] = new SqlParameter("@Investment", Investment);
            _sp[9] = new SqlParameter("@Notes", Notes);
            _sp[10] = new SqlParameter("@mode", Mode);
            
            int i = _clsdb.ExecuteNonQuery("Pipe_SP_Leads", _sp);
            return i;
        }

        public int AddRepsLeads()
        {
            DbConnection _clsdb = new DbConnection();
            SqlParameter[] _sp = new SqlParameter[5];
            _sp[0] = new SqlParameter("@ID", ID);
            _sp[1] = new SqlParameter("@RepsID", RepsID);
            _sp[2] = new SqlParameter("@LeadsID",LeadsID);
            _sp[3] = new SqlParameter("@DateAdded", DateAdded);
            _sp[4] = new SqlParameter("@mode", Mode);

            int i = _clsdb.ExecuteNonQuery("Pipe_SP_Leads", _sp);
            return i;
        }
        #endregion


        #region "LoadAll Leads Details"
        public DataTable GetLeads()
        {
            string sql = "select * from Pipe_TBL_AddLeads where Fname='" + Fname + "'";
            DbConnection _clsdb = new DbConnection();
            DataTable dt = _clsdb.ExecuteDT(sql);

            return dt;
        }

        public DataTable GetReps()
        {
            string sql = "select * from Pipe_TBL_RepsLeads where LeadsID='"+ LeadsID +"' order By ID ";
            DbConnection _clsdb = new DbConnection();
            DataTable dt = _clsdb.ExecuteDT(sql);

            return dt;
        }

        #endregion

        #region "All Insert,Update,Delete operation are done"
        public int DeleteLeads()
        {
            DbConnection _clsdb = new DbConnection();
            SqlParameter[] _sp = new SqlParameter[11];
            _sp[0] = new SqlParameter("@ID", ID);
            _sp[1] = new SqlParameter("@Fname", Fname);
            _sp[2] = new SqlParameter("@Contact", Contact);
            _sp[3] = new SqlParameter("@Position", Position);
            _sp[4] = new SqlParameter("@LastContactDate", null);
            _sp[5] = new SqlParameter("@Phone", Phone);
            _sp[6] = new SqlParameter("@LegacyPartner", LegacyPartner);
            _sp[7] = new SqlParameter("@Investment", Investment);
            _sp[8] = new SqlParameter("@Notes", Notes);
            _sp[9] = new SqlParameter("@mode", Mode);
            _sp[10] = new SqlParameter("@RepsID", RepsID);
            int i = _clsdb.ExecuteNonQuery("Pipe_SP_Leads", _sp);
            return i;
        }
        #endregion



        #region "LoadAll Leads Details"
        public DataTable LeadsDetails()
        {
            string sql = "select * from Pipe_TBL_AddLeads  order by ID";
            DbConnection _clsdb = new DbConnection();
            DataTable dt = _clsdb.ExecuteDT(sql);

            return dt;
        }

        #endregion

        #region "LoadAll Leads Details"
        public DataTable ShowLeads()
        {
            string sql = "select C.LeadsID,C.RepsID,A.ID,A.fname,A.Position,A.phone from Pipe_TBL_AddLeads as A , Pipe_TBL_RepsLeads as C where C.LeadsID=A.ID and  C.RepsID='" + RepsID + "' order by A.ID";
            //string sql = "select A.ID,A.RepsID,B.Fullname,A.fname,A.Position,A.phone from Pipe_TBL_AddLeads as A , Pipe_TBL_AddReps as B where A.RepsID=B.ID and A.RepsID='" + RepsID + "' order by A.ID";
            DbConnection _clsdb = new DbConnection();
            DataTable dt = _clsdb.ExecuteDT(sql);

            return dt;
        }

        #endregion

  

        #region "LoadAll Leads details by ID"
        public DataTable Leadsdata()
        {
            string sql = "select * from Pipe_TBL_AddLeads where ID='" + ID + "'";
            DbConnection _clsdb = new DbConnection();
            DataTable dt = _clsdb.ExecuteDT(sql);
            return dt;
        }

        #endregion


        #region "LoadAll Leads details by RepsID for Reports"
        public DataTable LeadsReport()
        {
           // string sql = "select ID,RepsID,fname,Position,CONVERT(VARCHAR(12),LastContactDate, 106) as LastContactDate,Phone ,Contact,LegacyPartner,Investment,Notes from Pipe_TBL_AddLeads where RepsID='" + RepsID + "'";

            string sql = "select C.LeadsID,C.RepsID,A.ID,A.fname,A.Position,A.phone,CONVERT(VARCHAR(12),A.LastContactDate, 106) as LastContactDate,Contact,LegacyPartner,Investment,Notes from Pipe_TBL_AddLeads as A , Pipe_TBL_RepsLeads as C where C.LeadsID=A.ID and  C.RepsID='" + RepsID + "' order by A.ID";
            DbConnection _clsdb = new DbConnection();
            DataTable dt = _clsdb.ExecuteDT(sql);
            return dt;
        }

        #endregion

        #region "LoadAll Leads details by RepsID"
        public DataTable LeadsdataByRepsID()
        {
            //string sql = "select A.ID,A.RepsID,B.Fullname,A.fname,A.Position,A.phone from Pipe_TBL_AddLeads as A , Pipe_TBL_AddReps as B where A.RepsID=B.ID and RepsID='" + RepsID + "' order by A.ID";
            string sql = "select C.LeadsID,C.RepsID,A.ID,A.fname,A.Position,A.phone from Pipe_TBL_AddLeads as A , Pipe_TBL_RepsLeads as C where C.LeadsID=A.ID and C.RepsID='" + RepsID + "' order by A.ID";

            DbConnection _clsdb = new DbConnection();
            DataTable dt = _clsdb.ExecuteDT(sql);
            return dt;
           
        }

        #endregion

        #region "Load Reps Name for reports"
        public DataTable RepsName()
        {
            string sql = "SELECT DISTINCT A.FullName as FullName FROM Pipe_TBL_AddReps as A,Pipe_TBL_AddLeads as B where B.RepsID=A.ID ORDER BY A.FullName";
            DbConnection _clsdb = new DbConnection();
            DataTable dt = _clsdb.ExecuteDT(sql);
            return dt;
        }

        #endregion

    }
}


PL:


   ClsAddLeads oRL = new ClsAddLeads();
                            oRL.RepsID = Convert.ToInt16(RepsselectedItem);
                            oRL.LeadsID =Convert.ToInt16(ViewState["ID"]);
                            oRL.DateAdded = DateTime.Now;
                            oRL.Mode = "RepsLeads";
                            int ok = oRL.AddRepsLeads();
                            if (ok == -1)
                            {

                                lblResult.Visible = true;
                                lblResult.ForeColor = Color.Green;
                                lblResult.Text = "Save successful ";
                            }





Friday, November 2, 2012

Remember me functionality in asp.net with VB.net using Cookies


 use the below code to save the userid and password deatils in cookies 

on login button:-

 If CheckBox1.Checked = True Then
                Response.Cookies("UName").Value = txtUserID.Text
                Response.Cookies("PWD").Value = txtPwd.Text
                Response.Cookies("UName").Expires = DateTime.Now.AddMonths(2)
                Response.Cookies("PWD").Expires = DateTime.Now.AddMonths(2)
End If


use the below code to Retrive the userid and password deatils From cookies 


on page load :-

  If Not IsPostBack Then
            If Request.Cookies("UName") IsNot Nothing Then
                txtUserID.Text = Request.Cookies("UName").Value
            End If
            If Request.Cookies("PWD") IsNot Nothing Then
                Dim pass As TextBox = DirectCast(Me.FindControl("txtPwd"), TextBox)
                pass.Attributes.Add("value", Request.Cookies("PWD").Value)
            
            End If
            If Request.Cookies("UName") IsNot Nothing AndAlso Request.Cookies("PWD") IsNot Nothing Then
                CheckBox1.Checked = True
            End If
        End If

Tuesday, May 8, 2012

How to clear a Multiple TextBox values in a single click in C# .NET


void ClearInputs(ControlCollection ctrls)
 {
        foreach (Control ctrl in ctrls)
        {
            if (ctrl is TextBox)
                ((TextBox)ctrl).Text = string.Empty;
            ClearInputs(ctrl.Controls);
        }
 }


protected void BtnSave_Click(object sender, EventArgs e)
{
           ClearInputs(Page.Controls);
}

Thursday, March 22, 2012

How to copy data from one table to another table in sql server

Syntax:- select * into NewTableName from ExistingTableName


Example:- select * into employee1 from employee


Note: where employee is the existing table. this query create a new table (employee1) and copy all the data of employee table in newly created table


        I hope this will help you!!

Friday, February 17, 2012

Introduction to PayPal


Introduction

PayPal is probably one of the first things that gets mentioned once you start discussion on online payments. It’s not so without reason – in 2008, PayPal moved over 60 billion dollars between accounts which is, you’ll agree, a respectable amount. And also, all trends show that this growth will continue – with huge number of new accounts (over 184 million accounts in 2008 compared to 96.2 million in 2005), with a new platform named PayPal X, and with more cool applications that involve paying (like Twitpay), you can bet that PayPal is here to stay. So, how can you join the whole PayPal Development movement?
Unfortunately, I would say – not so easily. When I first started with PayPal integration - it was hard, really hard. If you wish to see what I mean, just jump to the PayPal Developer Center. There is no way you’ll easily fish out what you need from that site if you are a PayPal newbie; simply - there are too many links, too many resources, and too many mixings of important and not-so-important information. So, how should you start?

Getting Started with PayPal

To those who really want to get into PayPal, and are willing to shell out some buck, I would recommend the Pro PayPal E-Commerce book - that’s how I eventually got into understanding the concepts behind PayPal integration. For those who are not so eager to pay – don’t worry, that’s why this article is here... I'll go over most of the stuff that book covers, but in a more brief and concise manner.
First and foremost - understanding what kinds of integration PayPal offers is, I would say, the most important thing in order to successfully start your development journey. A common mistake, that happened to me also, is to start at once with the PayPal API and Express Checkout. I mean it’s natural - we are developers, and when they tell us to integrate with something, the first thing we look for is the SDK & API… the PayPal API comes up as a result… we say “That’s it” to ourselves… and start working. The problem is – the majority of payment scenarios can be handled with a way simpler approach - HTML forms that are part of the Website Payments Standard.
So, without further ado, here is a classification of PayPal integrations:
  • Website Payments Standard (HTML)
  • Postpayment Processing
    • AutoReturn
    • Payment Data Transfer (PDT)
    • Instant Payment Notification (IPN)
  • PayPal API
    • Express Checkout
    • Direct Payment (Website Payments Pro)
  • Payflow Gateway
Items in classification are also ordered in a way I would suggest for everyone to follow. So, if you are new to PayPal – first learn all of the options that you have with the Website Payments Standard (HTML). Then, if you need to add some basic post-payment processing, see if Auto-Return or PDT will solve your problem… if not, IPN is a more robust option you have at your disposal.
The next level would involve the PayPal API and implementing the Express Checkout, which is the most flexible PayPal integration solution. And finally, if you long for the ability to directly process credit cards on your website, you’ll pay a monthly fee to PayPal and implement Direct Payment (effectively getting what is called Website Payments Pro).
The last item from our classification - the Payflow Gateway is, on the other hand, a different beast. It doesn’t “update the stack” in a way the previously mentioned technologies do. It is a solution aimed specifically at those businesses that have/want an Internet Merchant Account (IMA) and just need the payment gateway. In order to keep the article consistent, I’ll skip explaining the details of the Payflow Gateway. However, if you have any questions related to it, feel free to leave a message in the comments section and I’ll try to answer.
That said, let’s get to setting up a test PayPal account, and then we’ll delve deeper into describing the mentioned integrations.

Setting up a Test Account

Word of notice – you’ll want to follow this step even if you already have a live PayPal account. There are two reasons for using test accounts:
  • you don’t want to test and play with real money
  • you want to have access to different types of PayPal accounts
    • Personal account – most people have these; just an account that allows you to use PayPal when paying for stuff online. Theoretically, you can use a Personal account to accept money; just know that you’ll be severely constrained – there is a $500 receiving limit per month, and you are only able to accept one time payments using the Website Payments Standard (HTML). The big advantage of a Personal account is that you don’t need to pay any transaction fee when receiving money. Note, however, that if you receive more than $500 in one month, you’ll be prompted to either upgrade to a Premier/Business account or reject the payment.
    • Premier account – step up from a personal account; for anyone who wants to run a personal online business. This type of account has all of the integration options (accepting credit cards, recurring payments, PayPal API). However, most people skip directly from Personal to Business account as Premier account has the same transaction fees (in most cases, 2.9% + $0.30 per transaction) while lacking reporting, multi-user access, and other advanced merchant services of the Business account.
    • Business account – it has all of the features of the Premier account plus a few more (ability to operate under your business’s name is one of them). If you are developing a website that needs to accept payments in 99% of situations, you’ll go with this type of account.
To start, visit the PayPal Sandbox and sign-up for a new account. The process is straightforward, and most developers should have no trouble finishing it. However, here are the pictures that will help you navigate through the process:
Signing up for sandbox account
Signing up for a Sandbox account
Filling in details of your sandbox account
Filling in the details of your Sandbox account
Once done with entering the details for your Sandbox account, you'll need to check the email you provided in order to complete the registration. After that, you'll be able to login and start creating Sandbox PayPal accounts. Clicking onTest Accounts (menu on the left), and then Create Account: Preconfigured - will get you a form like the one on the image below:
Creating a Sandbox Test Account
Creating a Sandbox test account
Clarification of Account Type radio buttons: by selecting Buyer, you'll create a Personal account, and by selecting Seller, you'll create a Business account. For testing most integration scenarios, you'll need both accounts, so be sure to create them. Here is what you should eventually have on your screen after you click on Test Accounts:
Overview of your testing accounts
Overview of your testing accounts
Checking the radio button next to any of the accounts from the list and clicking on Enter Sandbox Test Site should bring up the Sandbox PayPal site which will allow you to login and administer your account in the same way as with a regular PayPal account. The only difference is that you'll have a huge PayPal Sandbox header and text that displays the email address of your developer account. To see what I'm talking about, check the image below:
Administering PayPal Sandbox account
Administering a PayPal Sandbox account
Last but not least - in order to use your Sandbox account for testing, you need to be logged in with your developer account. If you are not logged in and you follow some payment link, you'll get the following screen:
Login to use the PayPal Sandbox features
Login to use the PayPal Sandbox features




Website Payments Standard (HTML)

In this section, I'll provide you with a number of examples that will show how to create your own HTML form for receiving money over PayPal. You'll see how to use different variables in order to influence payment details. Before we delve into details, let's take a look at the two most basic variables:
  • form's action attribute - in most cases, it should be https://www.paypal.com/cgi-bin/webscr. If you are using Sandbox for testing payments, you'll change it to https://www.sandbox.paypal.com/cgi-bin/webscr - effectively, you just insert the word sandbox into the URL (this is also true for some other integrations; e.g., the PayPal API). For upcoming examples, I won't be using the Sandbox URL because most of you would just get that "Login to use the PayPal Sandbox features" screen (look up for the image).
  • form's business child - I'll use youremailaddress@yourdomain.com for most examples; if you copy-paste the code, you'll want to replace that with the email of your PayPal account.

Basic Payment

OK, let’s say you have an opened PayPal account and you just wish to be able to accept a $0.01 payment for a painting you are selling through your site. Just insert the following HTML into your page and you are set to go:

here is my source : 



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


<!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>Paypal</title>
   
</head>
<body>
    <form id="paypalForm" method="post" action="<%Response.Write(URL);%>">
        <input type="hidden" name="cmd" value="<%Response.Write(cmd);%>" />
        <input type="hidden" name="business" value="<%Response.Write(business);%>" />
        <input type="hidden" name="item_name" value="<%Response.Write(item_name);%>" />
        <input type="hidden" name="amount" value="<%Response.Write(amount);%>" />
        <input type="hidden" name="no_shipping" value="<%Response.Write(no_shipping);%>" />
        <input type="hidden" name="return" value="<%Response.Write(return_url);%>" />
        <input type="hidden" name="rm" value="<%Response.Write(rm);%>" />
        <input type="hidden" name="notify_url" value="<%Response.Write(notify_url);%>" />
        <input type="hidden" name="cancel_return" value="<%Response.Write(cancel_url);%>" />
        <input type="hidden" name="currency_code" value="<%Response.Write(currency_code);%>" />
        <input type="hidden" name="custom" value="<%Response.Write(request_id);%>" />
     
    </form>
   <script language="javascript">
    document.forms["paypalForm"].submit ();
    </script>
   
</html>




here is my C# Code  : Here u need to send some important paramenters which is use for  Transaction.


using System;
using System.Collections;
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 Microsoft.VisualBasic;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
public partial class Paypal : System.Web.UI.Page
{


    //"_notify-validate"
    protected string cmd = "_xclick";
    protected string business = "your-sandboxmailID@mail.com";
    protected string item_name = "Payment for Registration";
    protected string amount;
    protected string return_url = "http://yourwebURL/Paypal/Paypal.aspx";
    protected string notify_url = "http://yourwebURL/Paypal/Paypal.aspx";
    protected string cancel_url = "http://yourwebURL/Paypal/Paypal.aspx";
    protected string currency_code = "USD";
    protected string no_shipping = "1";
    protected string URL;
    protected string request_id;


    protected string rm;
    protected void Page_Load(object sender, EventArgs e)
 
{
 URL = "https://www.sandbox.paypal.com/cgi-bin/webscr";


 //This parameter determines the was information about successfull transaction will be          passed to the script
 // specified in the return_url parameter.
 // "1" - no parameters will be passed.
 // "2" - the POST method will be used.
 // "0" - the GET method will be used. 
 // The parameter is "0" by deault.
 rm = "2";


 // the total cost of the cart
 amount = 0.01;
 //Session("Amount")
 // the identifier of the payment request
 request_id = 1;
 //Session("request_id")
}
  
}


enjoy the code.




Thursday, December 29, 2011

What are DataSets and DataAdapters ?

Datasets store a copy of data from the database tables. However, Datasets can not directly retrieve data from Databases. DataAdapters are used to link Databases with DataSets. If we see diagrammatically,
DataSets < ----- DataAdapters < ----- DataProviders < ----- Databases
DataSets and DataAdapters are used to display and manipulate data from databases.

Reading Data into a Dataset

To read data into Dataset, you need to:
  • Create a database connection and then a dataset object.
  • Create a DataAdapter object and refer it to the DB connection already created. Note that every DataAdapter has to refer to a connection object. For example, SqlDataAdapter refers to SqlDataConnection.
  • The Fill method of DataAdapter has to be called to populate the Dataset object.
We elaborate the above mentioned steps by giving examples of how each step can be performed:


1)      As we said, our first task is to create a connection to database. We would explore later that there is no need of opening and closing database connection explicitly while you deal with DataAdapter objects. All you have to do is, create a connection to database using the code like this:
SqlConnection con = new SqlConnection ("data source=localhost; uid= sa; pwd= abc; database=Northwind");
We would use Northwind database by using OleDbConnection. The Code would
Look like:


OleDbConnection con= new OleDbConnection ("Provider =Microsoft.JET.OLEDB.4.0;" + "Data Source=C:\\Program Files\\Microsoft Office\\Office\\Samples\\Northwind.mdb");


2)      Now, create a Dataset object which would be used for storing and manipulating data. You would be writing something like


DataSet myDataSet = new DataSet ("Northwind");
Since the name of source database is Northwind, we have passed the same name in the constructor.


3)      The DataSet has been created but as we said before, this DataSet object can not directly interact with Database. We need to create a DataAdapter object which would refer to the connection already created. The following line would declare a DataAdapter object:


OleDbAdapter myDataAdapter = new OleDbAdapter (CommandObject, con);


The above line demonstrates one of many constructors of OleDbAdapter class. This constructor takes a command object and a database connection object. The purpose of command object is to retrieve suitable data needed for populating DataSet. As we know SQL commands directly interacting with database tables, a similar command can be assigned to CommandObject.


OleDbCommand CommandObject = new OleDbCommand ("Select * from employee");


Whatever data you need for your Dataset should be retrieved by using suitable command here. The second argument of OleDbAdapter constructor is connection object con.


Alternative approach for initializing DataAdapter object:
Place a null instead of CommandObject while you initialize the OleDbAdapter object:


OleDbAdapter myDataAdapter = new OleDbAdapter (null, con);


Then you assign your query to the CommandObject and write:


myDataAdapter.SelectCommand = CommandObject;




4)      Now, the bridge between the DataSet and Database has been created. You can populate dataset by using the Fill command:


myDataAdapter.Fill (myDataSet, "EmployeeData");


The first argument to Fill function is the DataSet name which we want to populate. The second argument is the name of DataTable. The results of SQL queries go into DataTable. In this example, we have created a DataTable named EmployeeData and the values in this table would be the results of SQL query: "Select * from employee". In this way, we can use a dataset for storing data from many database tables.
5)      DataTables within a Dataset can be accessed using Tables. To access EmployeeData, we need to write:


myDataSet.Tables["EmployeeData"].


To access rows in each Data Table, you need to write:


myDataSet.Tables["EmployeeData].Rows




To summarize:

  • Datasets store a copy of data from the database tables.
  • Datasets can not directly retrieve data from Databases.
  • DataAdapters are used to link Databases with DataSets.
  • To populate dataset, db connection is created which is followed by creating a DataAdapter and calling its Fill method.
  • OleDbCommand class can be used for applying desired SQL command on DataAdapter object. Dataset would be populated according to the selection criteria given in this command.
  • DataTables contain results of SQL query.
  • Modifications in DataTable can be done which would be later written on database by GetChanges method of Dataset.



Friday, December 16, 2011

What is .NET Framework ?

There are two combined definitions for the .NET Framework:
It’s a Language-neutral Component Library: this is a collection of code that we can call on and it will do certain functionality for us.  A good example of this is: if I need to connect to some TCPIP network, I don’t have to learn TCPIP and how to use it in a networking protocol.  I can use a class or a component that is already programmed into the .NET framework class library, and simply pass it some information and it’ll do it for me.  So we go a number of : Code Modules: these things are organized in such a way that we can
  • find what we need and they are specialized to do everything from managing collections to managing network, connections, managing security on our code...etc
  • The second part of the definition of .NET Framework is that it’s an ExecutionEnvironment:
    1. CTS (common type system)
    2. CLR (common language runtime): it watches everything that happens in .NET, it protect us from writing bad code, protects us from a security standpoint from people who try to hack us, and controls the environment that we are running in: what can we do safely and what we can’t do safely.  Managing our objects in the memory.
The .NET Framework can be divided into four main components:
  • Common Language Runtime (it’s the brain of the .NET framework)
  • .NET Framework Class Library: this is all the code functionality that Microsoft preprogrammed for you.
  • ADO.NET (the data access portion of .NET: DATA/XML)
  • ASP.NET (the web portion of the .NET Framework)
        .Net framework architecture diagram: