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 |
using System;
using System.Collections;
using System.Windows.Forms;
using Ayende.NHibernateQueryAnalyzer.Utilities;
namespace Ayende.NHibernateQueryAnalyzer.UserInterface.Controls
{
public partial class AddParameter : Form
{
private TypedParameter parameter;
private Hashtable types;
public AddParameter(string paramName)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
CreateTypesDictionary();
ux_Name.Text = paramName;
}
public AddParameter(TypedParameter parameter)
: this(parameter.Name)
{
ux_TypeList.SelectedText = parameter.Type.Name;
ux_Value.Text = parameter.Value.ToString();
}
private void CreateTypesDictionary()
{
types = new Hashtable();
types["DateTime"] = typeof(DateTime);
types["boolean"] = typeof(bool);
types["string"] = typeof(string);
types["int"] = typeof(int);
ux_TypeList.Items.AddRange(new[]{"int","string","boolean","DateTime"});
ux_TypeList.SelectedItem = "int";
}
private void ux_NameValue_TextChanged(object sender, EventArgs e)
{
ux_Ok.Enabled = ux_Name.Text != "" &&
ux_Value.Text != "";
}
private void ux_Ok_Click(object sender, EventArgs e)
{
object val;
Type type = (Type)types[ux_TypeList.Text];
try
{
val = Convert.ChangeType(ux_Value.Text, type);
}
catch (Exception)
{
MessageBox.Show("Can't convert '" + ux_Value.Text + "' to " + ux_TypeList.Text);
return;
}
parameter = new TypedParameter(ux_Name.Text,
type, val);
DialogResult = DialogResult.OK;
Close();
}
public TypedParameter Parameter
{
get
{
return parameter;
}
}
}
} |