我创建了一个搜索目录并将所有用户控件加载到表单中的应用程序,然后使用“GetResult()”方法从表单中获取答案。我没有采用这种 OOP 风格,因为我仍在学习如何充分利用 OOP,现在我将使用 OOP 进行设计,这样我就可以进入下一个部分,如果我使用对象会容易得多。现在我已经创建了我的“RequestForm”类,我希望 RequestForm.Result 进入 UC 并调用 GetResults() 方法。我很难做到这一点,但由于我缺乏知识,也许有人可以为我指明正确的方向。
FormUserControl - 抽象类
namespace AccessRequest
{
public abstract class FormUserControl : UserControl
{
public abstract string Name();
public abstract string GetResults();
public abstract string EmailUsers();
}
}
RequestForm - 对象类
namespace AccessRequest
{
public class RequestForm
{
public string Name { get; set; }
public string ControlID { get; set; }
public string StepName { get; set; }
public string FilePath { get; set; }
public string Results {
get
{
//How would I pull my usercontrol results with Control.GetReults() from within this area?
//I have since then turned this into a method. How would I get it to access my UserControl loaded on the asp page to grab the results?
}
set;
}
public string Emails { get; set; }
public int Position { get; set; }
public bool Visible { get; set; }
public RequestForm()
{
}
/// <summary>
/// FormResults gathers all needed information about the forms
/// </summary>
/// <param name="formName">Name of the Form</param>
/// <param name="formControlID">ID of the User Control </param>
/// <param name="wizardStepID">ID of the Wizard Step</param>
/// <param name="formFilePath">File path of the physical form</param>
/// <param name="formResults">Results from the form</param>
/// <param name="formEmails">Other emails to include</param>
public RequestForm(string formName, string formControlId, string wizardStepID, int wizardStepPosition, string formFilePath, string formResults, string formEmails)
{
this.Name = formName;
this.ControlID = formControlId;
this.StepName = wizardStepID;
this.Position = wizardStepPosition;
this.FilePath = formFilePath;
this.Results = formResults;
this.Emails = formEmails;
this.Visible = false;
}
public void SaveList(List<RequestForm> formList)
{
// HttpContext.Current.Session["FormList"] = formList;
}
}
}
这是我在 OnInit 中加载所有表单的 LoadForms() 方法,我还没有完全实现 RequestForm 部分,但我认为它应该去构建我的对象列表。
private void LoadForms()
{
string dotColor = "Black";
string formColor = "#808080";
int loc = 3;
foreach (ListItem item in chklApplications.Items)
{
string formPath = (string)item.Value;
WizardStepBase newStep = new WizardStep();
newStep.ID = "wzStep" + item.Text;
newStep.Title = String.Format("<font color='{0}'> ¤</font> <font color='{1}'>{2} Request</font>", dotColor, formColor, item.Text);
var form = LoadControl(formPath);
form.ID = "uc" + item.Text;
newStep.Controls.Add(form);
wzAccessRequest.WizardSteps.AddAt(loc, newStep);
requestForm.Add(new RequestForm(
item.Text, //Form name
form.ID.ToString(), //User Control ID
newStep.ID.ToString(), //Wizardstep ID
loc, //Wizardstep Position
item.Value.ToString(), //File Path
null, //Form Results
null //Form Emails
));
loc++;
}
}
这是我在向导控件的侧面菜单中设置它们是否可见的地方。顺便说一句,有谁知道我怎么能阻止它为此创建表格标签?现在它正在增长一个很大的空间,我正在插入表格。
protected void SideBarList_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (!ShowWizardStep(e.Item.DataItem))
{
e.Item.CssClass = "Hidden";
}
}
}
感谢我收到的任何建议!!:D