Step1:
->Create a Database(Ex:SelfTest),
->Create a Table(Ex: Calculation),
See below
Step2:
->Open VS,
->Go to file->New->Website
->Give any name(Ex:CalWithNtier)
->Click ok
Step3:
->Right click project and web form,
->Again Add a class(Ex: DOL (Data Object Layer))
->Again Add a class(Ex: DAL (Data Access Layer))
->Again Add a class(Ex: BOL(business Access Layer))
Step3:
->Write Code DOL.cs)
See below
using System; {
public int Value1 { get; set; }}
->Write code DAL.cs
see below
using System;{
public class DAL{
public int AddRecord(DOL objdol){
SqlConnection con = new SqlConnection(@"Data Source=mithilesh;database=SelfTest;User Id=sa;Password=12345");con.Open();
con.Close();
}
}}
->Write code BOL.cs
see below
using Cal;{
public int AddMethod(DOL objdol)objdol.Sum = objdol.Value1 + objdol.Value2;
DAL objdal = new DAL();
}ublic int SubMethod(DOL objdol)
{
objdol.Sub = objdol.Value1 - objdol.Value2;
DAL objdal = new DAL();
}public int MulMethod(DOL objdol)
{
objdol.Mul = objdol.Value1 * objdol.Value2;DAL objdal = new DAL();
}
public int DivMethod(DOL objdol)
{
objdol.Div = objdol.Value1 / objdol.Value2;DAL objdal = new DAL();
}
}->Go to Default.aspx and write the code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>->Go to the Default.aspx.cs and write the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void method()
{ if (txtValue1.Text == "")
{
lblmessage.Text = "<b style='color:red'>Value1 must be not empty</b>";
txtValue1.Focus();
}
else if (txtValue2.Text == "")
{
lblmessage.Text = "<b style='color:red'>value2 must be not empty</b>";
txtValue2.Focus();
}}
protected void btnAdd_Click(object sender, EventArgs e)
{if (txtValue1.Text == "" || txtValue2.Text == "")
{
method();
}else
{
DOL objdol = new DOL();
objdol.Value1 = int.Parse(txtValue1.Text);
objdol.Value2 = int.Parse(txtValue2.Text);
BOL objbol = new BOL();
int i = objbol.AddMethod(objdol);
lblResult.Text = (objdol.Sum).ToString();
if (i == 1)
{
lblmessage.Text = "<b style='color:green'>Record is inserted</b>";
}
else
{lblmessage.Text = "<b style='color:red'>Insertion Failed</b>";
}
}
} protected void btnSub_Click(object sender, EventArgs e)
{
if (txtValue1.Text == "" || txtValue2.Text == "")
{
method();
}
else
{
DOL objdol = new DOL();
objdol.Value1 = int.Parse(txtValue1.Text);
objdol.Value2 = int.Parse(txtValue2.Text);
BOL objbol = new BOL();
int i = objbol.SubMethod(objdol);
lblResult.Text = (objdol.Sub).ToString();
if (i == 1)
{
lblmessage.Text = "<b style='color:green'>Record is subracted</b>";
} else
{
lblmessage.Text = "<b style='color:red'>Insertion Failed</b>";
}
}
} protected void btnMul_Click(object sender, EventArgs e)
{
if (txtValue1.Text == "" || txtValue2.Text == "")
{
method();
}
else
{ DOL objdol = new DOL();
objdol.Value1 = int.Parse(txtValue1.Text);
objdol.Value2 = int.Parse(txtValue2.Text);
BOL objbol = new BOL();
int i = objbol.MulMethod(objdol);
lblResult.Text = (objdol.Mul).ToString();
if (i == 1)
{
lblmessage.Text = "<b style='color:green'>Record is multiplied</b>"; }
else
{lblmessage.Text = "<b style='color:red'>multiply Failed</b>";
}
}}
protected void btnDiv_Click(object sender, EventArgs e)
{
if (txtValue1.Text == "" || txtValue2.Text == "")
{method();
}
else
{ DOL objdol = new DOL();
objdol.Value1 = int.Parse(txtValue1.Text);
objdol.Value2 = int.Parse(txtValue2.Text);
BOL objbol = new BOL();
int i = objbol.DivMethod(objdol);
lblResult.Text = (objdol.Div).ToString();
f (i == 1)
{
lblmessage.Text = "<b style='color:green'>Record is divided</b>";
}
else
{
lblmessage.Text = "<b style='color:red'>division Failed</b>";
}
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
txtValue1.Text = "";
txtValue2.Text = "";
}
}
->Run the program
and see the out put
->Check the validation
No comments:
Post a Comment