1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP binary tree..

Discussion in 'C#' started by nishithkant, Apr 2, 2009.

  1. #1
    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, ;
    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();
    }

    }
     
    nishithkant, Apr 2, 2009 IP