window application in 3 tier Architecture


Posted Date:     Total Responses: 0    Posted By: raj kumar sahu   Member Level: Silver   Points/Cash: 8   


How to make project in .net 3 tier architecture

Step1 > Make a blank solution by New?project?Other Project Type?Visual Studio Solution?Blank
Solution. Then provide eg, Name :- test
Location:-d:

Step2> Go to the location you will found that there is a folder test and when you double click on it you
Will find test solution. Then add two new folder function and application
Function:- folder will contain class library and .dll
Application;- folder will contain web form or window form and so on..

Step3> Go to studio Solution Explorer and add three class library
Solution(R-Click)?Add?New Project
Language?c#
Templates?Class Library
Location?d:\test\function
Name of class library are BOclass, BALclass, DALclass

Step4> Go to studio Solution Explorer and add window form
Solution(R-Click)?Add?New Project
Language?c#
Templates?form
Location?d:\test\application
Name?testform

Step5>Build each project BOclass,BALclass,DALclass,testform

Step6>BALclass(R-Click)?Addrefference?Project {BOclass,DALclass}

Step7>DALclass(R-Click)?Addrefference?Project {BOclass,DALclass}

Step8>testform(R-Click)?Addrefference?Project {BOclass,BALclass,DALclass}
Step9>Build Solution
Step10>Add app.config for database access
now there is code for boclass,balclass,dalclass,windowform

App.config







BOclass

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BOclass
{
public class boaddclient
{
public string c_name { get; set; }
public string c_add { get; set; }
public string c_mobile { get; set; }
}
}

DALclass

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using BOclass;

namespace DALclass
{
public class daladdclient
{
public int dalclient(boaddclient boinfo)
{
string str = ConfigurationSettings.AppSettings["mycon"];
OleDbConnection con = new OleDbConnection(str);
string qry = "insert into client(c_name,c_address,c_mobileno) values('" + boinfo.c_name + "','" + boinfo.c_add + "','" + boinfo.c_mobile + "')";
//string qry1="select count(*) from client where c_name='"+boinfo.c_name+"' and c_mobileno='"+boinfo.c_mobile+"'";
//string qry2 = "select c_id from client where c_name='" + boinfo.c_name + "' and c_mobileno='" + boinfo.c_mobile + "'";
OleDbCommand cmd = new OleDbCommand(qry, con);
//OleDbCommand cmd1 = new OleDbCommand(qry1, con);
//OleDbCommand cmd2 = new OleDbCommand(qry2, con);
try
{
con.Open();
//int rt1 =Convert.ToInt32( cmd1.ExecuteScalar());
//if (rt1 > 0)
//{
// int rt2=Convert.ToInt32(cmd2.ExecuteScalar());
// return rt2;
//}
//else
//{
int rt = cmd.ExecuteNonQuery();
return rt;
//}

}
catch
{
throw;
}
finally
{
con.Close();
con.Dispose();
}
}
}
}



BALclass

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BOclass;
using DALclass;


namespace BALclass
{
public class baladdclient
{
public int balclient(boaddclient boinfo)
{
daladdclient dalinfo = new daladdclient();
return dalinfo.dalclient(boinfo);
}
}
}

Testform.cs(Design)

savebtn and close btn


Testform.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BOclass;
using BALclass;
using DALclass;

namespace digital
{
public partial class client : Form
{
public client()
{
InitializeComponent();
}

private void btnclose_Click(object sender, EventArgs e)
{
foreach (Form f in Application.OpenForms)
{
if (f.GetType() == typeof(newsale))
{
f.Activate();
return;
}
}
Form newform = new newsale();
newform.MdiParent = this.MdiParent;
newform.Dock = DockStyle.Fill;
newform.Show();
newform.Focus();
this.Close();
}

private void btnsave_Click(object sender, EventArgs e)
{
if (txtcname.Text.Trim().Length == 0)
{
MessageBox.Show("Enter Client name....");
}
else if (txtcaddress.Text.Trim().Length == 0)
{
MessageBox.Show("Enter Client address....");

}
else if (txtcmobile.Text.Trim().Length == 0)
{
MessageBox.Show("Enter Client Mobile no....");

}
else
{
try
{
baladdclient balinfo = new baladdclient();
boaddclient boinfo = new boaddclient();
boinfo.c_name = txtcname.Text.Trim();
boinfo.c_add = txtcaddress.Text.Trim();
boinfo.c_mobile = txtcmobile.Text.Trim();
int rt = balinfo.balclient(boinfo);
if (rt > 0)
{
MessageBox.Show("Client Inserted Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtcname.Text = ""; txtcaddress.Text = ""; txtcmobile.Text = "";

}
else
{
MessageBox.Show("Some Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}
catch (Exception p)
{
MessageBox.Show(p.Message.ToString());
}

}
}

private void mobile_keypress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;

if (!char.IsDigit(ch) && ch != 8)
{
e.Handled = true;
}
}


}
}







Project Feedbacks

Author: Member Level: SilverRevenue Score: 1 out of 5
where is the attachement code .. attach it na


Author: Member Level: GoldRevenue Score: 2 out of 52 out of 5
hi,
Your Project Was Very good.ican understand it very clearly.but ihav a sugession,that is please improve your project design.
Thanks and Regards
Sivasreenath



Post Feedback
You must Sign In to post a feedback.
Next Project: Simple Admission Form
Previous Project: online examination system

Return to Project Index

Post New Project


Related Projects


Top Contributors
TodayLast 7 Daysmore...

Awards & Gifts

Online Members

More...
 
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India