Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 8:46 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ]  Bookmark and Share
Author Message
 Post subject: Binary tree in ASP .net C#
PostPosted: Thu Apr 02, 2009 8:20 am 
Offline

Joined: Sun Mar 15, 2009 8:35 am
Posts: 4
""If this is not a proper place for this topic plz move the topic""

Hi fr.
I have a problem with binary tree .the code is below ,its working properly in IE but not working in FF or SAFARI .....Opera etc .Can anybody suggest me solution for this .I need quick reply .please copy the code below and test it OR if U have any other solution then plz Provise...........
thanks in advance................
<body>
<style type="text/css"></style>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="z-index: 100;
left: 360px; position: absolute; top: 16px" Text="show graph" UseSubmitBehavior="False" />
<asp:Label ID="Label1" runat="server" Text="insert NodeID please???"></asp:Label></div>
</form>
</body>


/////C# code//////////////
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
int maxlevelval = 0, maxnode = 0;

Bitmap objbitmap;
Size recsize = new Size(95, 45);
Graphics objgraphics;
Font font = new Font(FontFamily.GenericSansSerif, 8);
Pen pen = new Pen(Color.Red, 2);
Brush reccolor = Brushes.BlueViolet;
Brush textcolor = Brushes.White;
string selectText;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{

String nodeName = "";
Point lrecpoint, ltextpoint;
Int32 pid = 0, level = 0;
//Int32 NodeID=1;
con.Open();
//NodeID = Int32.Parse(reader.GetSqlValue(reader.GetOrdinal("NodeId")).ToString());
selectText = "";
selectText = "SELECT * FROM Binarytree2 where NodeID=" + TextBox1.Text.Trim();
//if (TextBox1.Text.Trim() == Session["NodeID"].ToString().Trim())
//{
// Response.Write("Match");
//}
//else
//{
// Response.Write("Not Match");
//}
SqlDataReader reader;
using (reader = new SqlCommand(selectText, con).ExecuteReader())
{
// Make sure we have data
while (reader.Read())
{
level = Int32.Parse(reader.GetSqlValue(reader.GetOrdinal("Level")).ToString());
nodeName = reader.GetString(reader.GetOrdinal("NodeName"));
pid = Int32.Parse(reader.GetSqlValue(reader.GetOrdinal("ParentID")).ToString());
break;
}
reader.Close();
}
maxlevelval = level + 2;//4 is for level till we want
maxnode = 8;
Point ppos;
objbitmap = new Bitmap((maxnode) * 100, (maxnode / 4) * 50);
objgraphics = Graphics.FromImage(objbitmap);
objgraphics.SmoothingMode = SmoothingMode.AntiAlias;
ppos = new Point((maxnode) / 4 * 100, 5);
lrecpoint = new Point(ppos.X, ppos.Y);
ltextpoint = new Point(ppos.X + 2, ppos.Y);
Rectangle rect = new Rectangle(lrecpoint, recsize);






objgraphics.DrawRectangle(pen, rect);
objgraphics.FillRectangle(reccolor, rect);
objgraphics.DrawString(nodeName, font, textcolor, ltextpoint);
DrawNode(ppos, pid, nodeName);
Response.Clear();
objbitmap.Save(this.Response.OutputStream, ImageFormat.Jpeg);
objbitmap.Dispose();
objgraphics.Dispose();
con.Close();
}
//private void ZoomImage()
//{
// Image.GetPixelFormatSize=ImagegGetPixelFormatSize.str


public void DrawNode(Point ppos, Int32 pid, String nName)
{
int totalnode = 0, updatevar = 0;
Int32 nodeID = 0, level = 0;
String leftChild = "", rightChild = "", address = "", mobile = "";
Point lchildpos, rchildpos, leftlninitpos, leftlnlastpos, rightlninitpos, rightlnlastpos;
selectText = "";
Point lrecpoint, ltextpoint, rtextpoint, rrecpoint;
selectText = "SELECT NodeID,NodeName,LeftChild, RightChild,Level, ParentID, Address,Mobile FROM Binarytree2 WHERE ParentID = " + pid + "AND NodeName='" + nName + "'";
SqlDataReader reader;
using (reader = new SqlCommand(selectText, con).ExecuteReader())
{
// Make sure we have data
while (reader.Read())
{
nodeID = Int32.Parse(reader.GetSqlValue(reader.GetOrdinal("NodeId")).ToString());
leftChild = reader.GetString(reader.GetOrdinal("LeftChild"));
rightChild = reader.GetString(reader.GetOrdinal("RightChild"));
address = reader.GetString(reader.GetOrdinal("Address"));
mobile = reader.GetString(reader.GetOrdinal("Mobile"));
level = Int32.Parse(reader.GetSqlValue(reader.GetOrdinal("Level")).ToString());
pid = Int32.Parse(reader.GetSqlValue(reader.GetOrdinal("ParentID")).ToString());
break; ;
}
reader.Close();




}
objgraphics.DrawString(mobile, font, textcolor, ppos.X, ppos.Y + 15);
objgraphics.DrawString(address, font, textcolor, ppos.X, ppos.Y + 30);
if (leftChild != "null" && rightChild != "null" && level <= maxlevelval)
{
totalnode = maxnode / 2 + (int)Math.Pow(2, level - maxlevelval + 2);//3 is for level till we want
updatevar = (totalnode) / (int)Math.Pow(2, level - maxlevelval + 2 + 1) * 100;//3 is for level till we want
rchildpos = new Point(ppos.X + updatevar, ppos.Y + 50);


lchildpos = new Point(ppos.X - updatevar, ppos.Y + 75);
lrecpoint = new Point(lchildpos.X, lchildpos.Y);
ltextpoint = new Point(lchildpos.X + 2, lchildpos.Y);
leftlninitpos = new Point(ppos.X + 50, ppos.Y + 45);
leftlnlastpos = new Point(lchildpos.X + 50, lchildpos.Y);
Rectangle lrect = new Rectangle(lrecpoint, recsize);
objgraphics = Graphics.FromImage(objbitmap);
objgraphics.DrawRectangle(pen, lrect);
objgraphics.FillRectangle(reccolor, lrect);
objgraphics.DrawString(leftChild, font, textcolor, ltextpoint);
objgraphics.DrawLine(pen, leftlninitpos, leftlnlastpos);
DrawNode(lchildpos, nodeID, leftChild);




rrecpoint = new Point(rchildpos.X, rchildpos.Y);
rightlninitpos = new Point(ppos.X + 50, ppos.Y + 45);
rightlnlastpos = new Point(rchildpos.X + 50, rchildpos.Y);
rtextpoint = new Point(rchildpos.X + 2, rchildpos.Y);
Rectangle rrect = new Rectangle(rrecpoint, recsize);
objgraphics = Graphics.FromImage(objbitmap);
objgraphics.DrawRectangle(pen, rrect);
objgraphics.FillRectangle(reccolor, rrect);
objgraphics.DrawString(rightChild, font, textcolor, rtextpoint);
objgraphics.DrawLine(pen, rightlninitpos, rightlnlastpos);


DrawNode(rchildpos, nodeID, rightChild);
}


else if (leftChild != "null" && level <= maxlevelval)
{
totalnode = maxnode / 2 + (int)Math.Pow(2, level - maxlevelval + 2);//3 is for level till we want
updatevar = (totalnode) / (int)Math.Pow(2, level - maxlevelval + 2 + 1) * 100;//3 is for level till we want
lchildpos = new Point(ppos.X - updatevar, ppos.Y + 75);
lrecpoint = new Point(lchildpos.X, lchildpos.Y);
ltextpoint = new Point(lchildpos.X + 2, lchildpos.Y);
leftlninitpos = new Point(ppos.X + 50, ppos.Y + 45);
leftlnlastpos = new Point(lchildpos.X + 50, lchildpos.Y);
Rectangle lrect = new Rectangle(lrecpoint, recsize);
objgraphics.DrawRectangle(pen, lrect);
objgraphics.FillRectangle(reccolor, lrect);
objgraphics.DrawString(leftChild, font, textcolor, ltextpoint);
objgraphics.DrawLine(pen, leftlninitpos, leftlnlastpos);
DrawNode(lchildpos, nodeID, leftChild);
}
else if (rightChild != "null" && level <= maxlevelval)
{
totalnode = maxnode / 2 + (int)Math.Pow(2, level - maxlevelval + 2);//4 is for level till we want
updatevar = (totalnode) / (int)Math.Pow(2, level - maxlevelval + 2 + 1) * 100;//4 is for level till we want
rchildpos = new Point(ppos.X + updatevar, ppos.Y + 75);
rrecpoint = new Point(rchildpos.X, rchildpos.Y);
rtextpoint = new Point(rchildpos.X + 2, rchildpos.Y);
rightlninitpos = new Point(ppos.X + 50, ppos.Y + 45);
rightlnlastpos = new Point(rchildpos.X + 50, rchildpos.Y);
Rectangle rrect = new Rectangle(rrecpoint, recsize);
objgraphics.DrawRectangle(pen, rrect);
objgraphics.FillRectangle(reccolor, rrect);
objgraphics.DrawString(rightChild, font, textcolor, rtextpoint);
objgraphics.DrawLine(pen, rightlninitpos, rightlnlastpos);
DrawNode(rchildpos, nodeID, rightChild);
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{

//con.Close();
}

}


Top
 Profile  
 
 Post subject: Re: Binary tree in ASP .net C#
PostPosted: Wed Apr 08, 2009 9:06 am 
Offline
100+ Club

Joined: Tue Jan 20, 2009 7:34 am
Posts: 237
:shock: OMG (i say).
as well that I love SEO.

_________________
aciphex,herbal phentermine,lamisil


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley