c# - 为学生绘制时间表(代码逻辑错误..)
问题描述
当我试图为我们学院的学生绘制这个“时间表”时,我遇到了这个问题,如果我下午有半天的讲座,我将其设为 collspan=2 但它在下一个单元格中出现错误,女巫属于明天...?如果我没有很好地描述我的问题,请原谅,但我希望我的代码提供的图像对你有意义。
void emploi()
{
bool flag = false;
int jour = 1;
while (jour <= 6)
{
switch (jour)
{
case 1: cell1.Text = "Lundi"; break; case 2: cell1.Text = "Mardi"; break; case 3: cell1.Text = "Mercredi"; break; case 4: cell1.Text = "Jeudi"; break;case 5: cell1.Text = "Vendredi"; break;case 6: cell1.Text = "Samedi"; break;
}
tRow.Cells.Add(cell1); cell1 = new TableCell();
foreach (var v in emp.function_Afficher_Group("TDI202"))
{ flag = false;
if (v.Seance.Substring(0, 1) == jour.ToString())
{
if (v.Seance.Substring(1) == "S1")
{
cell1.ID = jour + "/" + v.Seance.Substring(2);
SeanceInfo.Text = v.Module + Environment.NewLine + v.Salle + Environment.NewLine + v.Formateur + Environment.NewLine;
cell1.Controls.Add(SeanceInfo);
fillcombos(jour + "S1",2019,false);
SeanceInfo.Click += (object sender, EventArgs e) => {LinkButton button = sender as LinkButton;button.Visible = false;};
}
if (v.Seance.Substring(1) == "S2")
{
cell1.ID = jour + "/" + v.Seance.Substring(2);
SeanceInfo.Text = v.Module + Environment.NewLine + v.Salle + Environment.NewLine + v.Formateur + Environment.NewLine;
cell1.Controls.Add(SeanceInfo);
fillcombos(jour + "S2", 2019, false);
SeanceInfo.Click += (object sender, EventArgs e) => { LinkButton button = sender as LinkButton; button.Visible = false; };
}
if (v.Seance.Substring(1) == "S3")
{
cell1.ID = jour + "/" + v.Seance.Substring(2);
SeanceInfo.Text = v.Module + Environment.NewLine + v.Salle + Environment.NewLine + v.Formateur + Environment.NewLine;
cell1.Controls.Add(SeanceInfo);
fillcombos(jour + "S3", 2019, false);
SeanceInfo.Click += (object sender, EventArgs e) => { LinkButton button = sender as LinkButton; button.Visible = false; };
}
if (v.Seance.Substring(1) == "S4")
{
cell1.ID = jour + "/" + v.Seance.Substring(2);
SeanceInfo.Text = v.Module + Environment.NewLine + v.Salle + Environment.NewLine + v.Formateur + Environment.NewLine;
cell1.Controls.Add(SeanceInfo);
fillcombos(jour + "S4", 2019, false);
SeanceInfo.Click += (object sender, EventArgs e) => { LinkButton button = sender as LinkButton; button.Visible = false; };
}
if (cell1.ID == jour + "/2")
{
int ind = tRow.Cells.Count-1;
if ((tRow.Cells[ind].Controls[0] as LinkButton).Text == (cell1.Controls[0] as LinkButton).Text && (cell1.Controls[0] as LinkButton).Text!= "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine)
{
tRow.Cells[ind].ColumnSpan = 2;
flag = true;
}
}
if (cell1.ID == jour + "/4")
{
int ind = tRow.Cells.Count - 1;
if ((tRow.Cells[ind].Controls[0] as LinkButton).Text == (cell1.Controls[0] as LinkButton).Text && (cell1.Controls[0] as LinkButton).Text != "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine)
{
tRow.Cells[ind].ColumnSpan = 2;
flag = true;
}
}
if ((cell1.Controls[0] as LinkButton).Text == ""+Environment.NewLine+""+ Environment.NewLine +""+ Environment.NewLine)
cell1.BackColor = System.Drawing.Color.LightGray ;
cell1.CssClass = "myCells"; (cell1.Controls[0] as LinkButton).CssClass = "tt";
if (flag == false)
{
tRow.Cells.Add(cell1); cell1 = new TableCell(); SeanceInfo = new LinkButton(); dropForm = new DropDownList();
}
}
}
Table1.Rows.Add(tRow);
tRow = new TableRow();
jour++;
}
}
解决方案
已解决 ----> 带有注释的行//*******
void emploi()
{
bool flag = false;
int jour = 1;
while (jour <= 6)
{
switch (jour)
{
case 1: cell1.Text = "Lundi"; break; case 2: cell1.Text = "Mardi"; break; case 3: cell1.Text = "Mercredi"; break; case 4: cell1.Text = "Jeudi"; break;case 5: cell1.Text = "Vendredi"; break;case 6: cell1.Text = "Samedi"; break;
}
tRow.Cells.Add(cell1); cell1 = new TableCell();
foreach (var v in emp.function_Afficher_Group("TDI202"))
{ flag = false;
if (v.Seance.Substring(0, 1) == jour.ToString())
{
if (v.Seance.Substring(1) == "S1")
{
cell1.ID = jour + "/" + v.Seance.Substring(2);
SeanceInfo.Text = v.Module + Environment.NewLine + v.Salle + Environment.NewLine + v.Formateur + Environment.NewLine;
cell1.Controls.Add(SeanceInfo);
fillcombos(jour + "S1",2019,false);
SeanceInfo.Click += (object sender, EventArgs e) => {LinkButton button = sender as LinkButton;button.Visible = false;};
}
if (v.Seance.Substring(1) == "S2")
{
cell1.ID = jour + "/" + v.Seance.Substring(2);
SeanceInfo.Text = v.Module + Environment.NewLine + v.Salle + Environment.NewLine + v.Formateur + Environment.NewLine;
cell1.Controls.Add(SeanceInfo);
fillcombos(jour + "S2", 2019, false);
SeanceInfo.Click += (object sender, EventArgs e) => { LinkButton button = sender as LinkButton; button.Visible = false; };
}
if (v.Seance.Substring(1) == "S3")
{
cell1.ID = jour + "/" + v.Seance.Substring(2);
SeanceInfo.Text = v.Module + Environment.NewLine + v.Salle + Environment.NewLine + v.Formateur + Environment.NewLine;
cell1.Controls.Add(SeanceInfo);
fillcombos(jour + "S3", 2019, false);
SeanceInfo.Click += (object sender, EventArgs e) => { LinkButton button = sender as LinkButton; button.Visible = false; };
}
if (v.Seance.Substring(1) == "S4")
{
cell1.ID = jour + "/" + v.Seance.Substring(2);
SeanceInfo.Text = v.Module + Environment.NewLine + v.Salle + Environment.NewLine + v.Formateur + Environment.NewLine;
cell1.Controls.Add(SeanceInfo);
fillcombos(jour + "S4", 2019, false);
SeanceInfo.Click += (object sender, EventArgs e) => { LinkButton button = sender as LinkButton; button.Visible = false; };
}
if (cell1.ID == jour + "/2")
{
int ind = tRow.Cells.Count-1;
if ((tRow.Cells[ind].Controls[0] as LinkButton).Text == (cell1.Controls[0] as LinkButton).Text && (cell1.Controls[0] as LinkButton).Text!= "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine)
{
tRow.Cells[ind].ColumnSpan = 2;
flag = true;
}
}
if (cell1.ID == jour + "/4")
{
int ind = tRow.Cells.Count - 1;
if ((tRow.Cells[ind].Controls[0] as LinkButton).Text == (cell1.Controls[0] as LinkButton).Text && (cell1.Controls[0] as LinkButton).Text != "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine)
{
tRow.Cells[ind].ColumnSpan = 2;
flag = true;
}
}
if ((cell1.Controls[0] as LinkButton).Text == ""+Environment.NewLine+""+ Environment.NewLine +""+ Environment.NewLine)
cell1.BackColor = System.Drawing.Color.LightGray ;
cell1.CssClass = "myCells"; (cell1.Controls[0] as LinkButton).CssClass = "tt";
if (flag == false)
{
tRow.Cells.Add(cell1); cell1 = new TableCell(); SeanceInfo = new LinkButton(); dropForm = new DropDownList();
}
}
cell1 = new TableCell(); //*****added this before leaving the foreach
}
Table1.Rows.Add(tRow);
tRow = new TableRow();
jour++;
}
}
推荐阅读
- python-3.6 - 如何使用诗歌解决这个 pycparser 安装错误?
- css - 为什么使用导入时样式导入不起作用?
- css - 将 React 组件设置为鼠标滚轮上的水平滚动
- javascript - 图书馆管理系统中的图书数量输出问题
- angular - 找不到指定项目的“lint”目标或数据路径“”必须具有必需的属性“lintFilePatterns”
- php - php工匠优化期间的ErrorException
- go - 如何检索 FieldOption 值
- node.js - 无法在 mongodb 中按日期过滤数据
- image - TensorFlow Lite 图像分类推理 Python - 从 HxWxC 到 CxHxW 的图像
- vulkan - 我怎么知道 Vulkan 何时不再使用内存,以便我可以覆盖/重用它?