添加单击如果语句
本文关键字:语句 如果 单击 添加 | 更新日期: 2023-09-27 18:31:33
有没有更好的方法通过addClick
传递它(理想情况下,我根本不想要这个,我希望它自动通过)?
public void addClick(object sender, EventArgs e)
{
if ((string) HttpContext.Current.Session["whichMenu"] == "systemDateFormats")
{
WorldViewNet.system.DateFormats dateformats = new WorldViewNet.system.DateFormats();
dateformats.addClick();
}
else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingLabels")
{
WorldViewNet.programming.Labels labels = new WorldViewNet.programming.Labels();
labels.addClick();
}
else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingPLUSearch")
{
WorldViewNet.programming.PLUSearch pluSearch = new WorldViewNet.programming.PLUSearch();
pluSearch.addClick();
}
else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingServings")
{
WorldViewNet.programming.Servings servings = new WorldViewNet.programming.Servings();
servings.addClick();
}
else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingShops")
{
WorldViewNet.programming.Shops shops = new WorldViewNet.programming.Shops();
shops.addClick();
}
else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingTextsSearch")
{
WorldViewNet.programming.TextsSearch textsSearch = new WorldViewNet.programming.TextsSearch();
textsSearch.addClick();
}
else if ((string) HttpContext.Current.Session["whichMenu"] == "systemTemplates")
{
WorldViewNet.system.Templates templates = new WorldViewNet.system.Templates();
templates.addClick();
}
}
如果有人有任何建议,这将帮助我,我将不胜感激。
我下面的模型可能对您的代码有好处:
public void addClick(object sender, EventArgs e)
{
object control;
string opt = (string) HttpContext.Current.Session["whichMenu"];
switch (opt)
{
case "systemDateFormats": control = new WorldViewNet.system.DateFormats();
break;
case "programmingLabels": control = new WorldViewNet.programming.Labels();
break;
case "programmingPLUSearch": control = new WorldViewNet.programming.PLUSearch();
break;
case "programmingServings": control = new WorldViewNet.programming.Servings();
break;
case "programmingShops": control = new WorldViewNet.programming.Shops();
break;
case "programmingTextsSearch": control = new WorldViewNet.programming.TextsSearch();
break;
case "systemTemplates": control = new WorldViewNet.system.Templates();
break;
default: new WorldViewNet.system.DefaultType();
}
((dynamic)control).addClick();
}