♥ 1.Adım
♥ 2.Adım
♥ 3.Adım
♥ 5.Adım
♥ 6.Adım
♥ 7.Adım
♥ 8.Adım
class Program
{
public delegate void islemler(int x, int y);
static void Main(string[] args)
{
islemler operation = new islemler(Carp);
operation += new islemler(Topla);
operation(5, 3);
Console.ReadLine();
}
static void Carp(int x, int y)
{
Console.WriteLine("Çarpma sonucu : {0} ", x * y);
}
static void Topla(int x, int y)
{
Console.WriteLine("Toplama sonucu : {0} ", x + y);
}
}
class Program
{
public delegate void depoEventHandler();
public static event depoEventHandler depoEvent;
public class Depo
{
private int suseviyesi = 0;
public int SuSeviyesi
{
get { return suseviyesi; }
set
{
suseviyesi = value;
if (suseviyesi > 1000 && depoEvent != null)
depoEvent();
}
}
}
static void Main(string[] args)
{
depoEvent += new depoEventHandler(Doldu);
for (int i = 0; i < 1250; i += 200)
{
Depo t = new Depo();
t.SuSeviyesi = i;
Console.WriteLine("{0}", i);
Thread.Sleep(1000);
}
}
static void Doldu()
{
Console.WriteLine("Depo Taştı");
}
}
public delegate void depoEventHandler();
public static event depoEventHandler depoEvent;
public class Depo
{
private int suseviyesi = 0;
public int SuSeviyesi
{
get { return suseviyesi; }
set
{
suseviyesi = value;
if (suseviyesi > 1000 && depoEvent != null)
depoEvent();
}
}
}
Depodaki su seviyesini belirten bir propertimiz var ve bu propertimizin (SuSeviyesi) her değiştiğinde değerin 1000 i geçip geçmediğini kontrol ediyoruz. burdaki if in içeriğindeki depoEvent != null ifadesi olayımıza bir metod atanıp atanmadığını kontrol ediyor. Eğer su seviyesi 1000 lt den büyükse işte o zaman olayımız gerçekleşmiş demektir ve olayın belirttiği metod çalışacaktır. depoEvent += new depoEventHandler(Doldu);
Select * from TblKategori
Select * from TblKategori where ParentID=2

with cte
as
(
select ID,KategoriAdi,ParentID, 0 AS level , ID as Visited
from TblKategori
where ParentID =2
union all
select TblKategori.ID,TblKategori.KategoriAdi,TblKategori.ParentID, level +1 ,
cte.ParentID
from TblKategori inner join cte
on TblKategori.ParentID=cte.ID
where Visited NOT LIKE ('%<'+convert(varchar(3),TblKategori.ParentID)+'>%')
)
select * from cte D1
<connectionStrings>► 3.Adım Default.aspx sayfasına TreeView kontrolümüzü ekliyoruz
<add name="conn" connectionString="Data Source=192.168.0.3;initial catalog=DBKategori;uid=**;pwd=****;"
providerName="System.Data.SqlClient" />
</connectionStrings>

<asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">► 4.Adım Default.cs sayfasına kodlarımızı ekliyoruz
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<Nodes>
<asp:TreeNode Text="Kategoriler" Value="0"></asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="verdana" Font-Size="11pt" ForeColor="Black" HorizontalPadding="2px"
NodeSpacing="0px" VerticalPadding="0px" />
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle Font-Underline="False" ForeColor="#00cc66" HorizontalPadding="5px" VerticalPadding="0px" />
</asp:TreeView>
namespace SinirsizKategori
{
public partial class Default : System.Web.UI.Page
{
private SqlConnection baglanti;
private SqlDataAdapter komut;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
baglanti = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
komut = new SqlDataAdapter();
string _query = string.Format("select * from TblKategori");
SqlCommand sorgu = new SqlCommand();
DataSet ds = new DataSet();
try
{
if (baglanti.State == ConnectionState.Closed || baglanti.State == ConnectionState.Broken)
baglanti.Open();
sorgu.Connection = baglanti;
sorgu.CommandText = _query;
sorgu.ExecuteNonQuery();
komut.SelectCommand = sorgu;
komut.Fill(ds);
dt = ds.Tables[0];
}
catch { }
populateData(TreeView1.Nodes[0], getrows("0"));
}
DataRowCollection getrows(string id)
{
DataView dw = new DataView(dt);
dw.RowFilter = "ParentID=" + id;
return dw.ToTable().Rows;
}
void populateData(TreeNode node, DataRowCollection col)
{
foreach (DataRow row in col)
{
TreeNode n = new TreeNode();
n.Text = row[1].ToString();
n.Value = row[0].ToString();
node.ChildNodes.Add(n);
populateData(n, getrows(row[0].ToString()));
}
}
}
}