protected void LoadSettings() { DataEditorPropertyPanel pnlType = new DataEditorPropertyPanel(); pnlType.Text = ui.Text("dataBaseDatatype"); _dropdownlist = new DropDownList(); _dropdownlist.ID = "dbtype"; _dropdownlist.Items.Add(DBTypes.Date.ToString()); _dropdownlist.Items.Add(DBTypes.Integer.ToString()); _dropdownlist.Items.Add(DBTypes.Ntext.ToString()); _dropdownlist.Items.Add(DBTypes.Nvarchar.ToString()); DataEditorPropertyPanel pnlPrevalue = new DataEditorPropertyPanel(); pnlPrevalue.Text = ui.Text("prevalue"); _textbox = new TextBox(); _textbox.ID = "prevalues"; _textbox.Visible = _displayTextBox; // put the childcontrols in context - ensuring that // the viewstate is persisted etc. pnlType.Controls.Add(_dropdownlist); Controls.Add(pnlType); if (_displayTextBox) { pnlPrevalue.Controls.Add(_textbox); Controls.Add(pnlPrevalue); } foreach (KeyValuePair <string, DataEditorSetting> kv in _datatype.Settings()) { DataEditorSettingType dst = kv.Value.GetDataEditorSettingType(); dtSettings.Add(kv.Key, dst); DataEditorPropertyPanel panel = new DataEditorPropertyPanel(); panel.Text = kv.Value.GetName(); panel.Text += "<br/><small>" + kv.Value.description + "</small>"; if (_datatype.HasSettings()) { DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); List <Setting <string, string> > s = ss.GetSettings(_datatype.DataTypeDefinitionId); ss.Dispose(); if (s.Find(set => set.Key == kv.Key).Value != null) { dst.Value = s.Find(set => set.Key == kv.Key).Value; } } panel.Controls.Add(dst.RenderControl(kv.Value)); Label invalid = new Label(); invalid.Attributes.Add("style", "color:#8A1F11"); invalid.ID = "lbl" + kv.Key; panel.Controls.Add(invalid); this.Controls.Add(panel); } }
public void Save() { bool hasErrors = false; foreach (KeyValuePair <string, DataEditorSettingType> k in dtSettings) { var result = k.Value.Validate(); Label lbl = this.FindControlRecursive <Label>("lbl" + k.Key); if (result == null && lbl != null) { if (lbl != null) { lbl.Text = string.Empty; } } else { if (hasErrors == false) { hasErrors = true; } if (lbl != null) { lbl.Text = " " + result.ErrorMessage; } } } if (!hasErrors) { // save the prevalue data and get on with you life ;) if (_datatype != null) { _datatype.DBType = (cms.businesslogic.datatype.DBTypes) Enum.Parse(typeof(cms.businesslogic.datatype.DBTypes), _dropdownlist.SelectedValue, true); } else if (_datatypeOld != null) { _datatypeOld.DBType = (DBTypes)Enum.Parse(typeof(DBTypes), _dropdownlist.SelectedValue, true); } if (_displayTextBox) { // If the prevalue editor has an prevalue textbox - save the textbox value as the prevalue Prevalue = _textbox.Text; } DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); ss.ClearSettings(_datatype.DataTypeDefinitionId); int i = 0; foreach (KeyValuePair <string, DataEditorSettingType> k in dtSettings) { ss.InsertSetting(_datatype.DataTypeDefinitionId, k.Key, k.Value.Value, i); i++; } ss.Dispose(); } }