-1
我有下面的代碼來繪製座位可用性的階段。問題是當頁面加載時,默認階段是根據類別的顏色繪製的。但是當我從下拉列表中選擇特定組時,它將顯示特定組座位可用性的階段。瀏覽器中的表格渲染問題
問題是我選擇組後會花費太多時間...我如何繪製舞臺 最小時間我的創建階段的邏輯如下。
- 我的想法是填充(僅限紅色)LOGIC在下拉選擇索引更改。
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))
{
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 = " ";
}
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);
}
}
}