Skip to main content

Asp.net C# 3-Tire Sample Project






















Default.aspx.cs

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

 

public partial class _Default : System.Web.UI.Page

{

    ClsAddData ObjAddData = new ClsAddData();

    ClsDbconnection ObjConnection = new ClsDbconnection();

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

 

        }

 

        GridView1.DataSource = ObjAddData.GridFill();

        GridView1.DataBind();

    }

    protected void btnSave_Click(object sender, EventArgs e)

    {

        if (txtName.Text == string.Empty || txtAge.Text == string.Empty || txtEducation.Text == string.Empty || txtContact.Text == string.Empty || txtPan.Text == string.Empty || txtAdhar.Text == string.Empty || txtPassport.Text == string.Empty || ddlGender.SelectedIndex == 0)

        {

            Response.Write("<script>alert('All fields are mandatory!')</script>");

        }

        else

        {

            try

            {

                SqlConnection conn = new SqlConnection(ObjConnection.dbConnection);

                conn.Open();

                ObjAddData.name = txtName.Text;

                ObjAddData.age = txtAge.Text;

                ObjAddData.gender = ddlGender.SelectedItem.Text;

                ObjAddData.education = txtEducation.Text;

                ObjAddData.contactnumber = txtContact.Text;

                ObjAddData.pancard = txtPan.Text;

                ObjAddData.adharcard = txtAdhar.Text;

                ObjAddData.passport = txtPassport.Text;

                ObjAddData.AddData();

                Response.Write("<script>alert('Data saved successfully!')</script>");

                ClearFields();

                GridView1.DataSource = ObjAddData.GridFill();

                GridView1.DataBind();

            }

            catch (Exception ex)

            {

                //Response.Write("<script>alert('+ ex.Message + ')</script>");

                Response.Write(ex.Message);

            }

       

 

        }

    }

 

    protected void btnSearch_Click(object sender, EventArgs e)

    {

        if (txtSearch.Text == string.Empty)

        {

            Response.Write("<script>alert('Please provide details to be searched!')</script>");

        }

        else

        {

            ObjAddData.empID = txtSearch.Text;

            DataSet ds = ObjAddData.SearchUsingID();

            txtName.Text = ds.Tables[0].Rows[0]["Name"].ToString();

            txtAge.Text = ds.Tables[0].Rows[0]["Age"].ToString();

            ddlGender.SelectedItem.Text = ds.Tables[0].Rows[0]["Gender"].ToString();

            txtEducation.Text = ds.Tables[0].Rows[0]["Education"].ToString();

            txtContact.Text = ds.Tables[0].Rows[0]["ContactNumber"].ToString();

            txtPan.Text = ds.Tables[0].Rows[0]["PanCard"].ToString();

            txtAdhar.Text = ds.Tables[0].Rows[0]["AdharCard"].ToString();

            txtPassport.Text = ds.Tables[0].Rows[0]["Passport"].ToString();

        }

    }

 

    protected void btnUpdate_Click(object sender, EventArgs e)

    {

        ObjAddData.empID = txtSearch.Text;

        ObjAddData.name = txtName.Text;

        ObjAddData.age = txtAge.Text;

        ObjAddData.gender = ddlGender.SelectedItem.Text;

        ObjAddData.education = txtEducation.Text;

        ObjAddData.contactnumber = txtContact.Text;

        ObjAddData.pancard = txtPan.Text;

        ObjAddData.adharcard = txtAdhar.Text;

        ObjAddData.passport = txtPassport.Text;

        ObjAddData.UpdateData();

        Response.Write("<script>alert('Data Updated!')</script>");

        ClearFields();

        GridView1.DataSource = ObjAddData.GridFill();

        GridView1.DataBind();

    }

 

    protected void btnDelete_Click(object sender, EventArgs e)

    {

        ObjAddData.empID = txtSearch.Text;

        ObjAddData.DeleteData();

        Response.Write("<script>alert('Data Deleted!')</script>");

        GridView1.DataSource = ObjAddData.GridFill();

        GridView1.DataBind();

        ClearFields();

    }

 

 

    public void ClearFields()

    {

        txtName.Text = "";

        txtAge.Text = "";

        ddlGender.SelectedIndex = 0;

        txtEducation.Text = "";

        txtContact.Text = "";

        txtPan.Text = "";

        txtAdhar.Text = "";

        txtPassport.Text = "";

        txtSearch.Text = "";

    }

 

    protected void btnClear_Click(object sender, EventArgs e)

    {

        ClearFields();

    }

}

ClsDbconnection.cs [DAL]

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Configuration;

using System.Data.SqlClient;

 

/// <summary>

/// Summary description for ClsDbconnection

/// </summary>

public class ClsDbconnection

{

   public string dbConnection = ConfigurationManager.ConnectionStrings["EMPDB"].ConnectionString;

    public ClsDbconnection()

    {

        //

        // TODO: Add constructor logic here

        //

    }

 

ClsAddData.cs [BAL]

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Data;

using System.Data.SqlClient;

 

/// <summary>

/// Summary description for ClsAddData

/// </summary>

public class ClsAddData

{

    ClsDbconnection ObjConnection = new ClsDbconnection();

 

    public string name, age, gender, education, contactnumberidcardpancardadharcard, passport;

    public string empID;

    SqlConnection conn;

    SqlCommand cmd;

 

    public string Name

    {

        get { return name; }

        set { name = value; }

    }

 

    public string Age

    {

        get { return age; }

        set { age = value; }

    }

 

    public string Gender

    {

        get { return gender; }

        set { gender = value; }

    }

 

    public string Education

    {

        get { return education; }

        set { education = value; }

    }

 

    public string ContactNumber

    {

        get { return contactnumber; }

        set { contactnumber = value; }

    }

 

    public string IDCard

    {

        get { return idcard; }

        set { idcard = value; }

    }

    public string Pancard

    {

        get { return pancard; }

        set { pancard = value; }

    }

    public string Adharcard

    {

        get { return adharcard; }

        set { adharcard = value; }

    }

    public string Passport

    {

        get { return passport; }

        set { passport = value; }

    }

 

    public string EmpID

    {

        get { return empID; }

        set { empID = value; }

    }

 

 

    public ClsAddData()

    {

        //

        // TODO: Add constructor logic here

        //

    }

 

    public void AddData()

    {

        conn = new SqlConnection(ObjConnection.dbConnection);

        conn.Open();

        cmd = new SqlCommand("Insert_All", conn);

        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.AddWithValue("@Name", name);

        cmd.Parameters.AddWithValue("@Age", age);

        cmd.Parameters.AddWithValue("@Gender", gender);

        cmd.Parameters.AddWithValue("@Education", education);

        cmd.Parameters.AddWithValue("@ContactNumber"contactnumber);

        cmd.Parameters.AddWithValue("@PanCard"pancard);

        cmd.Parameters.AddWithValue("@AdharCard"Adharcard);

        cmd.Parameters.AddWithValue("@Passport", passport);

        cmd.ExecuteNonQuery();

    }

 

    public void UpdateData()

    {

        conn = new SqlConnection(ObjConnection.dbConnection);

        conn.Open();

        cmd = new SqlCommand("Update_All", conn);

        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.AddWithValue("@ID"empID);

        cmd.Parameters.AddWithValue("@Name", name);

        cmd.Parameters.AddWithValue("@Age", age);

        cmd.Parameters.AddWithValue("@Gender", gender);

        cmd.Parameters.AddWithValue("@Education", education);

        cmd.Parameters.AddWithValue("@ContactNumber"contactnumber);

        cmd.Parameters.AddWithValue("@PanCard"pancard);

        cmd.Parameters.AddWithValue("@AdharCard"Adharcard);

        cmd.Parameters.AddWithValue("@Passport", passport);

        cmd.ExecuteNonQuery();

    }

 

    public void DeleteData()

    {

        conn = new SqlConnection(ObjConnection.dbConnection);

        conn.Open();

        cmd = new SqlCommand("Delet_All", conn);

        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.AddWithValue("@ID"empID);

        cmd.ExecuteNonQuery();

    }

 

    public DataSet GridFill()

    {

        conn = new SqlConnection(ObjConnection.dbConnection);

        conn.Open();

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter("Select_All", conn);

        da.Fill(ds,"Employee");

        return ds;

    }

 

    public DataSet SearchUsingID()

    {

        conn = new SqlConnection(ObjConnection.dbConnection);

        conn.Open();

        cmd = new SqlCommand("SelectbyID", conn);

        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.AddWithValue("@ID"empID);

        cmd.ExecuteNonQuery();

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter(cmd);

        da.Fill(ds, "Employee");

        return ds;

    }

 

}

 

 

Web.Config

 

<?xml version="1.0"?>

 

<!--

  For more information on how to configure your ASP.NET application, please visit

  http://go.microsoft.com/fwlink/?LinkId=169433

  -->

 

<configuration>

 

    <system.web>

      <compilation debug="true" targetFramework="4.5.2" />

      <httpRuntime targetFramework="4.5.2" />

    </system.web>

<connectionStrings>

  <add name="EMPDB" connectionString="Data Source=DESKTOP-HAFM7O1;Initial Catalog=EmpDB;Integrated Security=True" providerName="System.Data.SqlClient"/>

</connectionStrings>

</configuration>












Database [Sql Sever 2014]

 

USE [master]

GO

/****** Object:  Database [EmpDB]    Script Date: 6/27/2023 10:34:27 AM ******/

CREATE DATABASE [EmpDB]

 CONTAINMENT = NONE

 ON  PRIMARY

( NAME = N'EmpDB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.LOCALSERVER\MSSQL\DATA\EmpDB.mdf' , SIZE = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )

 LOG ON

( NAME = N'EmpDB_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.LOCALSERVER\MSSQL\DATA\EmpDB_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)

GO

ALTER DATABASE [EmpDBSET COMPATIBILITY_LEVEL = 120

GO

IF (= FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))

begin

EXEC [EmpDB].[dbo].[sp_fulltext_database] @action = 'enable'

end

GO

ALTER DATABASE [EmpDBSET ANSI_NULL_DEFAULT OFF

GO

ALTER DATABASE [EmpDBSET ANSI_NULLS OFF

GO

ALTER DATABASE [EmpDBSET ANSI_PADDING OFF

GO

ALTER DATABASE [EmpDBSET ANSI_WARNINGS OFF

GO

ALTER DATABASE [EmpDBSET ARITHABORT OFF

GO

ALTER DATABASE [EmpDBSET AUTO_CLOSE OFF

GO

ALTER DATABASE [EmpDBSET AUTO_SHRINK OFF

GO

ALTER DATABASE [EmpDBSET AUTO_UPDATE_STATISTICS ON

GO

ALTER DATABASE [EmpDBSET CURSOR_CLOSE_ON_COMMIT OFF

GO

ALTER DATABASE [EmpDBSET CURSOR_DEFAULT  GLOBAL

GO

ALTER DATABASE [EmpDBSET CONCAT_NULL_YIELDS_NULL OFF

GO

ALTER DATABASE [EmpDBSET NUMERIC_ROUNDABORT OFF

GO

ALTER DATABASE [EmpDBSET QUOTED_IDENTIFIER OFF

GO

ALTER DATABASE [EmpDBSET RECURSIVE_TRIGGERS OFF

GO

ALTER DATABASE [EmpDBSET  DISABLE_BROKER

GO

ALTER DATABASE [EmpDBSET AUTO_UPDATE_STATISTICS_ASYNC OFF

GO

ALTER DATABASE [EmpDBSET DATE_CORRELATION_OPTIMIZATION OFF

GO

ALTER DATABASE [EmpDBSET TRUSTWORTHY OFF

GO

ALTER DATABASE [EmpDBSET ALLOW_SNAPSHOT_ISOLATION OFF

GO

ALTER DATABASE [EmpDBSET PARAMETERIZATION SIMPLE

GO

ALTER DATABASE [EmpDBSET READ_COMMITTED_SNAPSHOT OFF

GO

ALTER DATABASE [EmpDBSET HONOR_BROKER_PRIORITY OFF

GO

ALTER DATABASE [EmpDBSET RECOVERY FULL

GO

ALTER DATABASE [EmpDBSET  MULTI_USER

GO

ALTER DATABASE [EmpDBSET PAGE_VERIFY CHECKSUM 

GO

ALTER DATABASE [EmpDBSET DB_CHAINING OFF

GO

ALTER DATABASE [EmpDBSET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )

GO

ALTER DATABASE [EmpDBSET TARGET_RECOVERY_TIME = 0 SECONDS

GO

ALTER DATABASE [EmpDBSET DELAYED_DURABILITY = DISABLED

GO

EXEC sys.sp_db_vardecimal_storage_format N'EmpDB', N'ON'

GO

USE [EmpDB]

GO

/****** Object:  Table [dbo].[Employee]    Script Date: 6/27/2023 10:34:28 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Employee](

       [ID] [intIDENTITY(1,1) NOT NULL,

       [Name] [nvarchar](50) NULL,

       [Age] [intNULL,

       [Gender] [nchar](10) NULL,

       [Education] [nvarchar](50) NULL,

       [ContactNumber] [nvarchar](50) NULL,

       [PanCard] [nvarchar](50) NULL,

       [AdharCard] [nvarchar](50) NULL,

       [Passport] [nvarchar](50) NULL,

 CONSTRAINT [PK_EmployeePRIMARY KEY CLUSTERED

(

       [ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

 

GO

/****** Object:  StoredProcedure [dbo].[Delet_All]    Script Date: 6/27/2023 10:34:28 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[Delet_All]

(

       @ID int

)

AS

       SET NOCOUNT OFF;

DELETE FROM [Employee] WHERE (([ID] = @ID))

GO

/****** Object:  StoredProcedure [dbo].[Insert_All]    Script Date: 6/27/2023 10:34:28 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[Insert_All]

(

       @Name nvarchar(50),

       @Age int,

       @Gender nchar(10),

       @Education nvarchar(50),

       @ContactNumber nvarchar(50),

       @PanCard nvarchar(50),

       @AdharCard nvarchar(50),

       @Passport nvarchar(50)

)

AS

       SET NOCOUNT OFF;

INSERT INTO [Employee] ([Name], [Age], [Gender], [Education], [ContactNumber], [PanCard], [AdharCard], [Passport]) VALUES (@Name, @Age, @Gender, @Education, @ContactNumber, @PanCard, @AdharCard, @Passport);

      

SELECT ID, Name, Age, Gender, Education, ContactNumber, PanCard, AdharCard, Passport FROM Employee WHERE (ID = SCOPE_IDENTITY())

GO

/****** Object:  StoredProcedure [dbo].[Select_All]    Script Date: 6/27/2023 10:34:28 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[Select_All]

AS

       SET NOCOUNT ON;

SELECT        ID, Name, Age, Gender, Education, ContactNumber, PanCard, AdharCard, Passport

FROM            Employee

GO

/****** Object:  StoredProcedure [dbo].[SelectbyID]    Script Date: 6/27/2023 10:34:28 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[SelectbyID]

(

       @ID int

)

AS

 

SELECT * FROM [Employee] WHERE (([ID] = @ID))

GO

/****** Object:  StoredProcedure [dbo].[Update_All]    Script Date: 6/27/2023 10:34:28 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[Update_All]

(

       @Name nvarchar(50),

       @Age int,

       @Gender nchar(10),

       @Education nvarchar(50),

       @ContactNumber nvarchar(50),

       @PanCard nvarchar(50),

       @AdharCard nvarchar(50),

       @Passport nvarchar(50),

       @ID int

)

AS

       SET NOCOUNT OFF;

UPDATE [Employee] SET [Name] = @Name, [Age] = @Age, [Gender] = @Gender, [Education] = @Education, [ContactNumber= @ContactNumber, [PanCard= @PanCard, [AdharCard= @AdharCard, [Passport] = @Passport WHERE (([ID] = @ID));

      

SELECT ID, Name, Age, Gender, Education, ContactNumber, PanCard, AdharCard, Passport FROM Employee WHERE (ID = @ID)

GO

USE [master]

GO

ALTER DATABASE [EmpDBSET  READ_WRITE

GO

Comments

Popular posts from this blog

Turbo C++ tutorial

Turbo C++ Tutorial  Turbo C++ is a programming language was developed by Borland. C++ was a C++ compiler and integrated development environment and computer language originally from Borland. Most recently it was distributed by Embarcadero Technologies, which acquired all of Borland's compiler tools with the purchase of its CodeGear division in 2008. The original Turbo C++ product line was put on hold after 1994 and was revived in 2006 as an introductory-level IDE, essentially a stripped-down version of their flagship C++Builder. Turbo C++ 2006 was released on September 5, 2006 and was available in 'Explorer' and 'Professional' editions. The Explorer edition was free to download and distribute while the Professional edition was a commercial product. In October 2009 Embarcadero Technologies discontinued support of its 2006 C++ editions. As such, the Explorer edition is no longer available for download and the Professional edition is no longer available

Ganna Gyaras

Ganna Gyaras or called Dev uthavni Aikadashi.... It is also called Prabodhini  Aikadashi. It is belived that after killing the demon called Shankhasur The Great Lord Vishnu went for long sleep... which began after June month...... After diwali's 11th day the Ganna Gyaras is celebrated..... and all the auspicious tasks such as Weddings, New buyings etc. are done.  It is also called that... the end of Chaturmas.... Cool fact... Isn't it..?? Please make comments...... Thank you.

Fino Bank Asp.net C# Desktop Application

    using  System; using  System.Collections.Generic; using  System.ComponentModel; using  System.Data; using  System.Drawing; using  System.Linq; using  System.Text; using  System.Threading.Tasks; using  System.Windows.Forms; namespace  FinoBank_Application {      public   partial   class   frmSplash  :  Form     {          public  frmSplash()         {             InitializeComponent();         }          private   void  frmSplash_Load( object  sender,  EventArgs  e)         {             timer1.Start();         }          private   void  timer1_Tick( object  sender,  EventArgs  e)         {             progressBar1.Minimum = 0;             progressBar1.Maximum = 100;             progressBar1.Value = progressBar1.Value + 1;              //this.progressBar1.Increment(1);              if  (progressBar1.Value <= 0)             {                 lblProgress.Text =  "Initializing components............... " ;             }              else   if  (progressBar1.Va