开发者

table rendering problem in browser

I have below code of drawing a stage for seat availability. the problem is when page loads the default stage is drawn based on category color. but when i choose particular group from dropdown and it will show a stage from particular group seat availability.

problem is after i choose group it will take too much time... how can i draw stage with minimum time my logic of creating stage is below.

-- My idea is to fill (red color only) LOGIC on dropdown selected index changed.

private void CreateDynamicTable()
{
    string str = @"Data Source=SHREE\SQLEXPRESS;Initial Catalog=StageCraftNew;User ID=sa;Password=vivek";
    SqlConnection con = new SqlConnection(str);

    // FOR SEAT ASSIGNMENT (RED COLOR)
    SqlCommand cmdSeat = new SqlCommand("Select FName,LName,SeatNo from Person_Master a,Member_Master b,SeatAssign_Master c where a.Personid=b.Personid and b.Memberid=c.memberid and b.Active='True' and c.Year='" + 2 + "' and GID='" + DropDownList1.SelectedIndex + "'", con);
    SqlDataAdapter daSeat = new SqlDataAdapter(cmdSeat);
    DataSet dsSeat = new DataSet();
    daSeat.Fill(dsSeat);

    // FOR SEAT ALPHABETS (BLUE COLOR)
    SqlCommand cmdSeatMaster = new SqlCommand("select cm.CId,sm.Row,sm.ColorCode,cm.CategoryColor from Category_master cm,Seat_Master sm where cm.CId=sm.CId", con);
    SqlDataAdapter daSeatMaster = new SqlDataAdapter(cmdSeatMaster);
    DataSet dsSeatMaster = new DataSet();
    daSeatMaster.Fill(dsSeatMaster);      


    // FOR STAGE DRAW

    Table tbl = new Table();


    using (SqlConnection conn = new SqlConnection(str))
    {
        using (SqlCommand cmd = new SqlCommand("select * from Stage", conn))
        {
           开发者_Go百科 SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);

            int tblRows = ds.Tables[0].Rows.Count;
            int tblCols = ds.Tables[0].Columns.Count;
            // Create a Table and set its properties 

            tbl.BorderStyle = BorderStyle.Solid;
            tbl.CellSpacing = 0;
            tbl.Attributes.Add("style","width:850px;height:auto;table-layout:fixed;margin-top:40px;font-size:13px;font-family:verdana");

            // FOR STAGE DRAW
            for (int i = 0; i < tblRows; i++)
            {        
                TableRow tr = new TableRow();               

                string alpha = "";
                for (int j = 1; j < tblCols; j++)
                {
                    TableCell tc = new TableCell();
                    tc.BackColor = System.Drawing.Color.White;
                    Label lbl = new Label();

                    if (ds.Tables[0].Rows[i][j].ToString() == "55" || ds.Tables[0].Rows[i][j].ToString() == "56")
                    {
                        lbl.Text = "&nbsp;&nbsp;&nbsp;";                          
                    }
                    else
                    {
                        lbl.Text = ds.Tables[0].Rows[i][j].ToString();
                    }

                    if (alpha == "")
                    {
                        Regex r = new Regex("^[A-Z]*$");

                        if (r.IsMatch(lbl.Text))
                        {
                            alpha = lbl.Text;                                
                        }
                    }

                    // FOR SEAT ALPHABETS (BLUE COLOR)
                    for (int row = 0; row < dsSeatMaster.Tables[0].Rows.Count; row++)
                    {
                        for (int col = 0; col < dsSeatMaster.Tables[0].Columns.Count; col++)
                        {
                            if (dsSeatMaster.Tables[0].Rows[row]["Row"].ToString() == alpha)
                            {
                                tc.BackColor = System.Drawing.ColorTranslator.FromHtml(dsSeatMaster.Tables[0].Rows[row]["ColorCode"].ToString());
                                tc.Attributes.Add("style", "text-align:center");

                            }               
                        }
                    }

                    // FOR CATEGORY COLOR

                    for (int row = 0; row < dsSeatMaster.Tables[0].Rows.Count; row++)
                    {
                        for (int col = 0; col < dsSeatMaster.Tables[0].Columns.Count; col++)
                        {

                            if (dsSeatMaster.Tables[0].Rows[row]["Row"].ToString() == alpha)
                            {
                                tc.BackColor = System.Drawing.ColorTranslator.FromHtml(dsSeatMaster.Tables[0].Rows[row]["CategoryColor"].ToString());
                                tc.Attributes.Add("style", "text-align:center");
                            }
                        }
                    }


                    // FOR SEAT ASSIGNMENT (RED COLOR)
                    for (int row = 0; row < dsSeat.Tables[0].Rows.Count; row++)
                    {
                        for (int col = 0; col < dsSeat.Tables[0].Columns.Count; col++)
                        {
                            Regex r = new Regex("^[A-Z]*$");

                            if (r.IsMatch(ds.Tables[0].Rows[i][j].ToString()) && ds.Tables[0].Rows[i][j].ToString() != "")
                            {
                                tc.BackColor = System.Drawing.ColorTranslator.FromHtml("#ADD8E6");
                                tc.Attributes.Add("style", "text-align:center");
                            }
                            else if (ds.Tables[0].Rows[i][j].ToString() == "")
                            {
                                tc.BackColor = System.Drawing.Color.White;

                            }
                            else if (alpha + "" + ds.Tables[0].Rows[i][j].ToString() == dsSeat.Tables[0].Rows[row]["SeatNo"].ToString() && alpha + "" + ds.Tables[0].Rows[i][j].ToString() != "")
                            {
                                    tc.Attributes.Add("class", "demo-tip-twitter");
                                    tc.Attributes.Add("style", "cursor:pointer;text-align:center;");                    
                                    tc.ToolTip = "Seat: "+ alpha + "" + ds.Tables[0].Rows[i][j].ToString() + "\n" + dsSeat.Tables[0].Rows[row]["Fname"].ToString() + " " + dsSeat.Tables[0].Rows[row]["Lname"].ToString();
                                    tc.BackColor = System.Drawing.Color.Red;

                            }

                        }
                    }
                    tc.Controls.Add(lbl);
                    tr.Cells.Add(tc);                      
                }

                // Add the TableRow to the Table
                tbl.Rows.Add(tr);
            }
            form1.Controls.Add(tbl);

        }

    }

}


Nothing stands out in your code, but I didn't notice that you have two loops that are almost identical to each other:

 // FOR SEAT ALPHABETS (BLUE COLOR) 
for (int row = 0; row < dsSeatMaster.Tables[0].Rows.Count; row++) 
{ 
    for (int col = 0; col < dsSeatMaster.Tables[0].Columns.Count; col++) 
    { 
        if (dsSeatMaster.Tables[0].Rows[row]["Row"].ToString() == alpha) 
        { 
            tc.BackColor = System.Drawing.ColorTranslator.FromHtml(dsSeatMaster.Tables[0].Rows[row]["ColorCode"].ToString()); 
            tc.Attributes.Add("style", "text-align:center"); 

        }                
    } 
} 

// FOR CATEGORY COLOR 

for (int row = 0; row < dsSeatMaster.Tables[0].Rows.Count; row++) 
{ 
    for (int col = 0; col < dsSeatMaster.Tables[0].Columns.Count; col++) 
    { 

        if (dsSeatMaster.Tables[0].Rows[row]["Row"].ToString() == alpha) 
        { 
            tc.BackColor = System.Drawing.ColorTranslator.FromHtml(dsSeatMaster.Tables[0].Rows[row]["CategoryColor"].ToString()); 
            tc.Attributes.Add("style", "text-align:center"); 
        } 
    } 
} 

I'm not sure what the desired effect is, but it looks like you could remove one of the loops and fit the logic into one. I don't know what your measure of slow is, but that should help to speed things up a little.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜