代码参考:
frmConfigSet.aspx 以配置文件名为参数,根据配置文件自动生成维护界面,并进行维护,保存。
HtmlTable tab = new HtmlTable();
tab.ID = "tDynamic";
tab.Attributes.Add("width", "80%");
tab.Attributes.Add("class", "tablebody");
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell tc = new HtmlTableCell();
XmlNodeList nodes = xmldoc.DocumentElement.SelectNodes("Item");
string sConfigContent = "";
if (xmldoc.DocumentElement.Attributes["ConfigContent"] != null)
sConfigContent = xmldoc.DocumentElement.Attributes["ConfigContent"].Value;
string sItemDesc = "";
int iRow = 0;
foreach (XmlNode node in nodes)
{
iRow++;
tr = new HtmlTableRow();
tr.ID = "tDynamicRow" + iRow;
AddControlByNode(node,iRow,ref tr);
AddControl(tab, tr);
sItemDesc = "";
if (node.Attributes["ItemContent"] != null)
sItemDesc = node.Attributes["ItemContent"].Value;
if (sItemDesc.Length > 0)
{
//添加描述行
iRow++;
tr = new HtmlTableRow();
tr.ID = "tDyContectRow" + iRow;
tc = new HtmlTableCell();
tc.ID = "tDyContectTD_" + iRow;
tc.InnerText = sItemDesc;
tc.Attributes.Add("class", "list");
tc.Attributes.Add("colspan", "2");
AddControl(tr, tc);
AddControl(tab, tr);
}
}
tab.ID = "tDynamic";
tab.Attributes.Add("width", "80%");
tab.Attributes.Add("class", "tablebody");
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell tc = new HtmlTableCell();
XmlNodeList nodes = xmldoc.DocumentElement.SelectNodes("Item");
string sConfigContent = "";
if (xmldoc.DocumentElement.Attributes["ConfigContent"] != null)
sConfigContent = xmldoc.DocumentElement.Attributes["ConfigContent"].Value;
string sItemDesc = "";
int iRow = 0;
foreach (XmlNode node in nodes)
{
iRow++;
tr = new HtmlTableRow();
tr.ID = "tDynamicRow" + iRow;
AddControlByNode(node,iRow,ref tr);
AddControl(tab, tr);
sItemDesc = "";
if (node.Attributes["ItemContent"] != null)
sItemDesc = node.Attributes["ItemContent"].Value;
if (sItemDesc.Length > 0)
{
//添加描述行
iRow++;
tr = new HtmlTableRow();
tr.ID = "tDyContectRow" + iRow;
tc = new HtmlTableCell();
tc.ID = "tDyContectTD_" + iRow;
tc.InnerText = sItemDesc;
tc.Attributes.Add("class", "list");
tc.Attributes.Add("colspan", "2");
AddControl(tr, tc);
AddControl(tab, tr);
}
}
/// <summary>
/// 获取设置的控件
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private Control GetSettingControl(XmlNode node)
{
string strCtrlType = node.Attributes["ControlType"].Value;
string strValue = node.Attributes["Value"].Value;
Control control;
switch (strCtrlType.ToLower())
{
case "text":
control = new TextBox();
control.ID = "tDynamic" + "_txt_" + node.Attributes["Name"].Value;
((TextBox)control).Width = new Unit("70%");
((TextBox)control).Attributes.Add("Tag", node.Attributes["Name"].Value);
((TextBox)control).Text = strValue;
break;
case "checkbox":
control = new CheckBox();
control.ID = "tDynamic" + "_chk_" + node.Attributes["Name"].Value;
((CheckBox)control).Attributes.Add("Tag", node.Attributes["Name"].Value);
((CheckBox)control).Text = node.Attributes["Desc"].Value;
if (strValue.ToLower() == "false")
{
((CheckBox)control).Checked = false;
}
else
{
((CheckBox)control).Checked = true;
}
break;
case "droplist":
control = new DropDownList();
control.ID = "tDynamic" + "_drp_" + node.Attributes["Name"].Value;
((DropDownList)control).Attributes.Add("Tag", node.Attributes["Name"].Value);
((DropDownList)control).Width = new Unit("70%");
string[] sItems = node.Attributes["Dict"].Value.Split(",".ToCharArray());
for (int i = 0; i < sItems.Length; i++)
{
string[] arr = sItems[i].Split("|".ToCharArray());
((DropDownList)control).Items.Add(new ListItem(arr[1], arr[0]));
}
((DropDownList)control).SelectedValue = strValue;
break;
case "datetime":
control = (Epower.ITSM.Web.Controls.CtrDateAndTime)LoadControl("~/controls/ctrdateandtime.ascx");
((Epower.ITSM.Web.Controls.CtrDateAndTime)control).ShowTime = false;
control.ID = "tDynamic" + "_date_" + node.Attributes["Name"].Value;
((Epower.ITSM.Web.Controls.CtrDateAndTime)control).Attributes.Add("Tag", node.Attributes["Name"].Value);
break;
default:
control = null;
break;
}
return control;
}
/// 获取设置的控件
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private Control GetSettingControl(XmlNode node)
{
string strCtrlType = node.Attributes["ControlType"].Value;
string strValue = node.Attributes["Value"].Value;
Control control;
switch (strCtrlType.ToLower())
{
case "text":
control = new TextBox();
control.ID = "tDynamic" + "_txt_" + node.Attributes["Name"].Value;
((TextBox)control).Width = new Unit("70%");
((TextBox)control).Attributes.Add("Tag", node.Attributes["Name"].Value);
((TextBox)control).Text = strValue;
break;
case "checkbox":
control = new CheckBox();
control.ID = "tDynamic" + "_chk_" + node.Attributes["Name"].Value;
((CheckBox)control).Attributes.Add("Tag", node.Attributes["Name"].Value);
((CheckBox)control).Text = node.Attributes["Desc"].Value;
if (strValue.ToLower() == "false")
{
((CheckBox)control).Checked = false;
}
else
{
((CheckBox)control).Checked = true;
}
break;
case "droplist":
control = new DropDownList();
control.ID = "tDynamic" + "_drp_" + node.Attributes["Name"].Value;
((DropDownList)control).Attributes.Add("Tag", node.Attributes["Name"].Value);
((DropDownList)control).Width = new Unit("70%");
string[] sItems = node.Attributes["Dict"].Value.Split(",".ToCharArray());
for (int i = 0; i < sItems.Length; i++)
{
string[] arr = sItems[i].Split("|".ToCharArray());
((DropDownList)control).Items.Add(new ListItem(arr[1], arr[0]));
}
((DropDownList)control).SelectedValue = strValue;
break;
case "datetime":
control = (Epower.ITSM.Web.Controls.CtrDateAndTime)LoadControl("~/controls/ctrdateandtime.ascx");
((Epower.ITSM.Web.Controls.CtrDateAndTime)control).ShowTime = false;
control.ID = "tDynamic" + "_date_" + node.Attributes["Name"].Value;
((Epower.ITSM.Web.Controls.CtrDateAndTime)control).Attributes.Add("Tag", node.Attributes["Name"].Value);
break;
default:
control = null;
break;
}
return control;
}