1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
//------------------------------------------------------------------------------
// <copyright file="EntityDataSourceStatementEditorForm.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//
// Enables a user to edit CommandText, OrderBy, Select, and
// Where properties and parameters
//------------------------------------------------------------------------------
using System.Collections.Generic;
using System.Web.UI.Design.WebControls.Util;
using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Web.UI.Design.WebControls;
using System.Web.UI.WebControls;
using System.Windows.Forms;
namespace System.Web.UI.Design.WebControls
{
internal class EntityDataSourceStatementEditorForm : DesignerForm
{
private System.Windows.Forms.Panel _checkBoxPanel;
private System.Windows.Forms.CheckBox _autoGenerateCheckBox;
private System.Windows.Forms.Panel _statementPanel;
private System.Windows.Forms.Label _statementLabel;
private System.Windows.Forms.TextBox _statementTextBox;
private ParameterEditorUserControl _parameterEditorUserControl;
private System.Windows.Forms.Button _okButton;
private System.Windows.Forms.Button _cancelButton;
private System.Web.UI.Control _entityDataSource;
private ParameterCollection _parameters;
private string _cachedStatementText;
private readonly string _helpTopic;
public EntityDataSourceStatementEditorForm(System.Web.UI.Control entityDataSource, IServiceProvider serviceProvider,
bool hasAutoGen, bool isAutoGen, string propertyName, string statementLabelText, string statementAccessibleName,
string helpTopic, string statement, ParameterCollection parameters)
: base(serviceProvider)
{
_entityDataSource = entityDataSource;
InitializeComponent();
InitializeUI(propertyName, statementLabelText, statementAccessibleName);
InitializeTabIndexes();
InitializeAnchors();
_helpTopic = helpTopic;
if (!hasAutoGen)
{
HideCheckBox();
}
_parameters = parameters;
_autoGenerateCheckBox.Checked = isAutoGen;
_statementPanel.Enabled = !isAutoGen;
_statementTextBox.Text = statement;
_statementTextBox.Select(0, 0);
List<Parameter> paramList = new List<Parameter>();
foreach (Parameter p in parameters)
{
paramList.Add(p);
}
_parameterEditorUserControl.AddParameters(paramList.ToArray());
_cachedStatementText = null;
}
public bool AutoGen
{
get
{
return _autoGenerateCheckBox.Checked;
}
}
protected override string HelpTopic
{
get
{
return _helpTopic;
}
}
public ParameterCollection Parameters
{
get
{
return _parameters;
}
}
public string Statement
{
get
{
return _statementTextBox.Text;
}
}
private void HideCheckBox()
{
_autoGenerateCheckBox.Checked = false;
_checkBoxPanel.Visible = false;
int moveUp = _statementPanel.Location.Y - _checkBoxPanel.Location.Y;
Point loc = _statementPanel.Location;
loc.Y -= moveUp;
_statementPanel.Location = loc;
loc = _parameterEditorUserControl.Location;
loc.Y -= moveUp;
_parameterEditorUserControl.Location = loc;
Size size = _parameterEditorUserControl.Size;
size.Height += moveUp;
_parameterEditorUserControl.Size = size;
size = this.MinimumSize;
size.Height -= moveUp;
this.MinimumSize = size;
this.Size = size;
}
private void InitializeAnchors()
{
_checkBoxPanel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
_autoGenerateCheckBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
_statementPanel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
_statementLabel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
_statementTextBox.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
_parameterEditorUserControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
_okButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
_cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this._okButton = new System.Windows.Forms.Button();
this._cancelButton = new System.Windows.Forms.Button();
this._statementLabel = new System.Windows.Forms.Label();
this._statementTextBox = new System.Windows.Forms.TextBox();
this._autoGenerateCheckBox = new System.Windows.Forms.CheckBox();
this._parameterEditorUserControl = (ParameterEditorUserControl)Activator.CreateInstance(typeof(ParameterEditorUserControl), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { ServiceProvider, _entityDataSource }, null);
this._checkBoxPanel = new System.Windows.Forms.Panel();
this._statementPanel = new System.Windows.Forms.Panel();
this._checkBoxPanel.SuspendLayout();
this._statementPanel.SuspendLayout();
this.SuspendLayout();
this.InitializeSizes();
//
// _okButton
//
this._okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this._okButton.Name = "_okButton";
this._okButton.Click += new System.EventHandler(this.OnOkButtonClick);
//
// _cancelButton
//
this._cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this._cancelButton.Name = "_cancelButton";
this._cancelButton.Click += new System.EventHandler(this.OnCancelButtonClick);
//
// _commandLabel
//
this._statementLabel.Name = "_commandLabel";
//
// _statementTextBox
//
this._statementTextBox.AcceptsReturn = true;
this._statementTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this._statementTextBox.Multiline = true;
this._statementTextBox.Name = "_statementTextBox";
this._statementTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
//
// _autoGenerateCheckBox
//
this._autoGenerateCheckBox.CheckAlign = ContentAlignment.TopLeft;
this._autoGenerateCheckBox.TextAlign = ContentAlignment.TopLeft;
this._autoGenerateCheckBox.Name = "_autoGenerateCheckBox";
this._autoGenerateCheckBox.UseVisualStyleBackColor = true;
this._autoGenerateCheckBox.CheckedChanged += new EventHandler(OnAutoGenerateCheckBoxCheckedChanged);
//
// _checkBoxPanel
//
this._checkBoxPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this._checkBoxPanel.Controls.Add(this._autoGenerateCheckBox);
this._checkBoxPanel.Name = "_radioPanel";
//
// _statementPanel
//
this._statementPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this._statementPanel.Controls.Add(this._statementLabel);
this._statementPanel.Controls.Add(this._statementTextBox);
this._statementPanel.Name = "_statementPanel";
//
// _parameterEditorUserControl
//
this._parameterEditorUserControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this._parameterEditorUserControl.Name = "_parameterEditorUserControl";
//
// EntityDataSourceStatementEditorForm
//
this.AcceptButton = this._okButton;
this.CancelButton = this._cancelButton;
this.Controls.Add(this._statementPanel);
this.Controls.Add(this._checkBoxPanel);
this.Controls.Add(this._cancelButton);
this.Controls.Add(this._okButton);
this.Controls.Add(this._parameterEditorUserControl);
this.Name = "EntityDataSourceStatementEditorForm";
this._checkBoxPanel.ResumeLayout(false);
this._checkBoxPanel.PerformLayout();
this._statementPanel.ResumeLayout(false);
this._statementPanel.PerformLayout();
this.ResumeLayout(false);
InitializeForm();
}
#endregion
private void InitializeSizes()
{
int top = 0;
_checkBoxPanel.Location = new Point(12, 12);
_checkBoxPanel.Size = new Size(456, 32);
_autoGenerateCheckBox.Location = new Point(0, 0);
_autoGenerateCheckBox.Size = new Size(456, 30);
top = _checkBoxPanel.Bottom;
_statementPanel.Location = new Point(12, top + 4);
_statementPanel.Size = new Size(456, 124);
top = 0;
_statementLabel.Location = new Point(0, 0);
_statementLabel.Size = new Size(200, 16);
top = _statementLabel.Bottom;
_statementTextBox.Location = new Point(0, top + 3);
_statementTextBox.Size = new Size(456, 78);
top = _statementPanel.Bottom;
_parameterEditorUserControl.Location = new Point(12, top + 5);
_parameterEditorUserControl.Size = new Size(460, 216);
top = _parameterEditorUserControl.Bottom;
_okButton.Location = new Point(313, top + 6);
_okButton.Size = new Size(75, 23);
_cancelButton.Location = new Point(393, top + 6);
_cancelButton.Size = new Size(75, 23);
top = _cancelButton.Bottom;
ClientSize = new Size(480, top + 12);
MinimumSize = new Size(480 + 8, top + 12 + 27);
}
private void InitializeTabIndexes()
{
_checkBoxPanel.TabStop = false;
_autoGenerateCheckBox.TabStop = true;
_statementPanel.TabStop = false;
_statementLabel.TabStop = false;
_statementTextBox.TabStop = true;
_parameterEditorUserControl.TabStop = true;
_okButton.TabStop = true;
_cancelButton.TabStop = true;
int tabIndex = 0;
_checkBoxPanel.TabIndex = tabIndex += 10;
_autoGenerateCheckBox.TabIndex = tabIndex += 10;
_statementPanel.TabIndex = tabIndex += 10;
_statementLabel.TabIndex = tabIndex += 10;
_statementTextBox.TabIndex = tabIndex += 10;
_parameterEditorUserControl.TabIndex = tabIndex += 10;
_okButton.TabIndex = tabIndex += 10;
_cancelButton.TabIndex = tabIndex += 10;
}
private void InitializeUI(string propertyName, string labelText, string accessibleName)
{
this.Text = Strings.ExpressionEditor_Caption;
this.AccessibleName = Strings.ExpressionEditor_Caption;
_okButton.Text = Strings.OKButton;
_okButton.AccessibleName = Strings.OKButtonAccessibleName;
_cancelButton.Text = Strings.CancelButton;
_cancelButton.AccessibleName = Strings.CancelButtonAccessibleName;
_statementLabel.Text = labelText;
_statementTextBox.AccessibleName = accessibleName;
if (String.Equals(propertyName, "Where", StringComparison.OrdinalIgnoreCase))
{
_autoGenerateCheckBox.Text = Strings.ExpressionEditor_AutoGenerateWhereCheckBox;
_autoGenerateCheckBox.AccessibleName = Strings.ExpressionEditor_AutoGenerateWhereCheckBoxAccessibleName;
}
else if (String.Equals(propertyName, "OrderBy", StringComparison.OrdinalIgnoreCase))
{
_autoGenerateCheckBox.Text = Strings.ExpressionEditor_AutoGenerateOrderByCheckBox;
_autoGenerateCheckBox.AccessibleName = Strings.ExpressionEditor_AutoGenerateOrderByCheckBoxAccessibleName;
}
}
private void OnAutoGenerateCheckBoxCheckedChanged(object sender, EventArgs e)
{
if (_autoGenerateCheckBox.Checked)
{
_cachedStatementText = _statementTextBox.Text;
_statementTextBox.Text = null;
}
else if (!String.IsNullOrEmpty(_cachedStatementText))
{
_statementTextBox.Text = _cachedStatementText;
}
_statementPanel.Enabled = !_autoGenerateCheckBox.Checked;
}
private void OnCancelButtonClick(System.Object sender, System.EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void OnOkButtonClick(System.Object sender, System.EventArgs e)
{
_parameters.Clear();
Parameter[] paramList = _parameterEditorUserControl.GetParameters();
foreach (Parameter p in paramList)
{
_parameters.Add(p);
}
DialogResult = DialogResult.OK;
Close();
}
}
}
|