📄 eformcontrols.cs
字号:
get { return field; }
set { field = value; }
}
public string FieldLabel
{
get
{
// TODO: Add EformRadioButtonGroup.FieldLabel getter implementation
return null;
}
set
{
// TODO: Add EformRadioButtonGroup.FieldLabel setter implementation
}
}
public bool Required
{
get
{
// TODO: Add EformRadioButtonGroup.Required getter implementation
return false;
}
set
{
// TODO: Add EformRadioButtonGroup.Required setter implementation
}
}
public bool ShowHelpBubble
{
get
{
// TODO: Add EformRadioButtonGroup.ShowHelpBubble getter implementation
return false;
}
set
{
// TODO: Add EformRadioButtonGroup.ShowHelpBubble setter implementation
}
}
public string HelpDescription
{
get
{
// TODO: Add EformRadioButtonGroup.HelpDescription getter implementation
return null;
}
set
{
// TODO: Add EformRadioButtonGroup.HelpDescription setter implementation
}
}
public bool ShowLabel
{
get
{
// TODO: Add EformRadioButtonGroup.ShowLabel getter implementation
return false;
}
set
{
// TODO: Add EformRadioButtonGroup.ShowLabel setter implementation
}
}
#endregion
#region group style
private string groupStyle;
/// <summary>
/// Sets the style attribute for the radio buttons in the group
/// </summary>
public string GroupStyle
{
get { return groupStyle; }
set { groupStyle = value; }
}
#endregion
public EformRadioButtonGroup() : base() { }
protected override void CreateChildControls()
{
base.CreateChildControls();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
foreach (Control c in this.Controls)
{
if (c is EformRadioButton)
{
EformRadioButton r = (EformRadioButton) c;
DecorateRadioButton(r);
}
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
// handle GroupStyle
if (groupStyle != null && groupStyle != "")
{
foreach (Control c in this.Controls)
{
if (c is EformRadioButton)
{
EformRadioButton r = (EformRadioButton) c;
r.Attributes["style"] = groupStyle;
}
}
}
}
// need to do this on load, not render
private void DecorateRadioButton(EformRadioButton r)
{
if (groupName != null && !"".Equals(groupName))
{
r.GroupName = groupName;
}
if (table != null && !"".Equals(table))
{
r.Table = table;
}
if (recordId != null && !"".Equals(recordId))
{
r.RecordId = recordId;
}
}
public EformRadioButton GetCheckedButton(HttpRequest request)
{
string activatedId = request.Form[this.UniqueID + ":" + this.GroupName];
if (activatedId == null || "".Equals(activatedId))
{
return null;
}
foreach (Control c in this.Controls)
{
if (c is EformRadioButton)
{
EformRadioButton r = (EformRadioButton) c;
if (activatedId.Equals(r.ID))
{
return r;
}
}
}
return null;
}
public string GetSelectedValue(HttpRequest request)
{
string activatedId = request.Form[this.UniqueID + ":" + this.GroupName];
if (activatedId == null || "".Equals(activatedId))
{
return null;
}
foreach (Control c in this.Controls)
{
if (c is EformRadioButton)
{
EformRadioButton r = (EformRadioButton) c;
if (activatedId.Equals(r.ID))
{
return r.Value;
}
}
}
return null;
}
}
/// <summary>
/// A ComboBox/DropDown hybrid
/// </summary>
[DefaultProperty("Text"), ToolboxData("<{0}:EformSelect runat=server></{0}:EformSelect>")]
public class EformSelect : TextBox, IEformInputField // should we not extend ComboBox for poly reasons?
{
#region private types to implement interfaces
private string recordId;
private string parentRecordId;
private string table;
private string field;
private string fieldLabel;
private bool required;
private bool showHelpBubble;
private string helpDescription;
private bool showLabel;
private string lookupCode;
#endregion
#region IEformInputField Members
public string RecordId
{
get { return recordId; }
set { recordId = value; }
}
public string ParentRecordId
{
get { return parentRecordId; }
set { parentRecordId = value; }
}
#endregion
#region ICaisisInputControl Members
public string Table
{
get { return table; }
set { table = value; }
}
public string Field
{
get { return field; }
set { field = value; }
}
public string FieldLabel
{
get { return fieldLabel; }
set { fieldLabel = value; }
}
public bool Required
{
get { return required; }
set { required = value; }
}
public bool ShowHelpBubble
{
get { return showHelpBubble; }
set { showHelpBubble = value; }
}
public string HelpDescription
{
get { return helpDescription; }
set { helpDescription = value; }
}
public bool ShowLabel
{
get { return showLabel; }
set { showLabel = value; }
}
#endregion
#region additional properties
public string LookupCode
{
get { return lookupCode; }
set { lookupCode = value; }
}
#endregion
#region enable hidden stuff
private string enableHiddenOnUIEvent;
public string EnableHiddenOnUIEvent
{
get { return enableHiddenOnUIEvent; }
set { enableHiddenOnUIEvent = value; }
}
#endregion
#region allow adding functionality to the client-side onchange event
private string appendToOnChange;
public string AppendToOnChange
{
get { return appendToOnChange; }
set { appendToOnChange = value; }
}
#endregion
#region SelectedValue - just link to this.Text
public string SelectedValue
{
get { return this.Text; }
set { this.Text = value; }
}
#endregion
private string anonymousFunction = null;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if(LookupCode != null && LookupCode.Length > 0)
{
Page.RegisterClientScriptBlock(LookupCode + "_" + this.field, PageUtil.FillComboDropDown(this.field, LookupCode));
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// will we have viewstate issues now that this extends TextBox?
// various tasks to make this control "combobox-like"
// this.ReadOnly = true;
this.CssClass = "pdComboBox";
if (this.Style["width"] == null || this.Style["width"] == "")
{
this.Style["width"] = "100";
}
// TODO: investigate advantage of string pooling / redundant event blocks
// for all sorts of fun reasons, this goes here:
this.anonymousFunction = this.BuildAnonymousFunction();
// add on click attribute - simulate a select box
StringBuilder onClickAtt = new StringBuilder("prepareComboSelect('");
onClickAtt.Append(this.ClientID);
onClickAtt.Append("Container'); publishComboSelectValues(");
onClickAtt.Append(this.field);
onClickAtt.Append("OptionsArray, '");
onClickAtt.Append(this.ClientID);
onClickAtt.Append("Container', '");
onClickAtt.Append(this.ClientID);
onClickAtt.Append("', ");
onClickAtt.Append(anonymousFunction);
onClickAtt.Append("); ");
this.Attributes.Add("onclick", onClickAtt.ToString());
// add onkeyup attribute
StringBuilder onKeyPressAtt = new StringBuilder("return handleEverythingElse('");
// this suffix is redudant, see below ...
onKeyPressAtt.Append(this.ClientID);
onKeyPressAtt.Append("Container', '");
onKeyPressAtt.Append(this.ClientID);
onKeyPressAtt.Append("', ");
onKeyPressAtt.Append(this.field);
// TODO: append a list of hiddens
onKeyPressAtt.Append("OptionsArray, '', ");
onKeyPressAtt.Append(anonymousFunction);
onKeyPressAtt.Append(");");
this.Attributes.Add("onkeypress", onKeyPressAtt.ToString());
// add onkeydown attribute
StringBuilder onKeyDownAtt = new StringBuilder("handleArrows('");
onKeyDownAtt.Append(this.ClientID);
onKeyDownAtt.Append("Container', '");
onKeyDownAtt.Append(this.ClientID);
onKeyDownAtt.Append("', ");
onKeyDownAtt.Append(this.field);
onKeyDownAtt.Append("OptionsArray, '', ");
onKeyDownAtt.Append(anonymousFunction);
onKeyDownAtt.Append(");");
this.Attributes.Add("onkeydown", onKeyDownAtt.ToString());
// add onfocus attribute
StringBuilder onFocusAtt = new StringBuilder("publishComboSelectValues(");
onFocusAtt.Append(this.field);
onFocusAtt.Append("OptionsArray, '");
onFocusAtt.Append(this.ClientID);
onFocusAtt.Append("Container', '");
onFocusAtt.Append(this.ClientID);
onFocusAtt.Append("', ");
onFocusAtt.Append(anonymousFunction);
onFocusAtt.Append("); ");
this.Attributes.Add("onfocus", onFocusAtt.ToString());
}
protected override void Render(HtmlTextWriter writer)
{
// render textbox
base.Render(writer);
// render image
string pathPrefix = "../../"; // future releases may need to convert this if used outside of eform
writer.Write("<img src=\"");
writer.Write(pathPrefix);
// we could make the image style available if we wanted to
writer.Write("Images/ComboSelectBtn.gif\" height=\"18\" width=\"14\" vspace=\"1\" border=\"0\" align=\"absMiddle\" ");
writer.Write("Title=\"Enter data or select from dropdown options. Options are filtered as you enter data.\" ");
writer.Write("class=\"pdFormFieldButtonOn\" ");
writer.Write("onclick=\"prepareComboSelect('");
writer.Write(this.ClientID);
writer.Write("Container'); publishComboSelectValues(");
writer.Write(this.field);
writer.Write("OptionsArray, '");
writer.Write(this.ClientID);
writer.Write("Container', '");
writer.Write(this.ClientID);
writer.Write("', ");
writer.Write(anonymousFunction);
writer.Write("); \"/>");
// render line break
writer.Write("<br/>");
// render span container
writer.Write("<span id=\"");
writer.Write(this.ClientID);
writer.Write("Container\"></span>");
}
private string BuildAnonymousFunction()
{
// sanity check
/*
if ((this.enableHiddenOnUIEvent == null || this.enableHiddenOnUIEvent == "") &&
(this.appendToOnChange == null || this.appendToOnChange == ""))
{
return "null";
}
*/
StringBuilder b = new StringBuilder("function(_val) { ");
// enable hiddens
if (this.enableHiddenOnUIEvent != null && this.enableHiddenOnUIEvent != "")
{
b.Append("enableHiddens('");
b.Append(this.GetClientSideHiddenList(this.enableHiddenOnUIEvent));
b.Append("'); ");
}
// we need to replace "this.value" with "document.getElementById('abc').value"
if (this.appendToOnChange != null && this.appendToOnChange != "")
{
b.Append(this.appendToOnChange.Replace("this.value", "_val"));
}
// wrap up
b.Append(" }");
return b.ToString();
}
private string GetClientSideHiddenList(string baseHiddenList)
{
if (baseHiddenList != null)
{
ArrayList enable = new ArrayList();
string[] hiddens = baseHiddenList.Split(new char[] {','});
foreach (string h in hiddens)
{
Control c = this.Parent.FindControl(h);
if (c != null)
{
enable.Add(c.ClientID);
}
}
return String.Join(",", (string[]) enable.ToArray(typeof (string)));
}
return "";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -