How to create class file in Asp.Net ?


Sunday, July 25, 2010

Hi,

You can just add App_Code file and add class file to this folder and copy this code to that class file and modify according to your need.

using System;
using System.Data;
using System.Configuration;
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;
using commonlib.Common;

/// <summary>
/// Summary description for Program
/// </summary>
public class Program
{
    #region "Fields"

    string sOperation;
    int iProgramID;
    string sProgramName;
    string sSlogan;
    string sStartTime;
    string sEndTime;
    string sDetail;
    int iCityID;
    string sStatus;

    #endregion

    #region "Construtor"
    public Program()
    {
    }

    public Program(string SOperation, int IProgramID, string SProgramName, string SSlogan, string SStartTime, string SEndTime, string SDetail, int ICityID, string SStatus)
    {
        this.sOperation = SOperation;
        this.iProgramID = IProgramID;
        this.sProgramName = SProgramName;
        this.sSlogan = SSlogan;
        this.sStartTime = SStartTime;
        this.sEndTime = SEndTime;
        this.sDetail = SDetail;
        this.iCityID = ICityID;
        this.sStatus = SStatus;
    }
    #endregion

    #region "Properties"

    public string SOperation
    {
        get { return sOperation; }
        set { sOperation = value; }
    }

    public int IProgramID
    {
        get { return iProgramID; }
        set { iProgramID = value; }
    }

    public string SProgramName
    {
        get { return sProgramName; }
        set { sProgramName = value; }
    }

    public string SSlogan
    {
        get { return sSlogan; }
        set { sSlogan = value; }
    }

    public string SStartTime
    {
        get { return sStartTime; }
        set { sStartTime = value; }
    }

    public string SEndTime
    {
        get { return sEndTime; }
        set { sEndTime = value; }
    }

    public string SDetail
    {
        get { return sDetail; }
        set { sDetail = value; }
    }

    public int ICityID
    {
        get { return iCityID; }
        set { iCityID = value; }
    }

    public string SStatus
    {
        get { return sStatus; }
        set { sStatus = value; }
    }

    #endregion

    #region "Functions"

    public int ProgramOperation(string user, string pass)
    {

        SqlConnection conn = new SqlConnection("Data Source=localhost;Database=MyDB;Integrated Security=SSPI");
        SqlCommand command = new SqlCommand("XYZ_SP_CheckProgramAvailability", conn);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@User", SqlDbType.VarChar).Value = user;
        command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = pass;
        conn.Open();
        int rows = command.ExecuteNonQuery();
        conn.Close();

    }

    #endregion
}


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer

e-Procurement Technologies Ltd (India)
www.abcprocure.com



No comments :