-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColumnDisplay.cs
206 lines (185 loc) · 5.02 KB
/
ColumnDisplay.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SQLDatabase.Net.Explorer
{
public partial class ColumnDisplay : UserControl
{
public delegate void OnPrimaryKeyCheckedEvent(object sender);
public event OnPrimaryKeyCheckedEvent OnPrimaryKeyChecked = null;
public ColumnDisplay()
{
InitializeComponent();
Column = new SqlDataColumn();
}
private SqlDataColumn _column = new SqlDataColumn();
public SqlDataColumn Column
{
get
{
UpdateColumnValues();
return _column;
}
set {
_column = value;
UpdateDisplayValuesFromColumn();
}
}
public void UpdateDisplayValuesFromColumn()
{
if (_column == null) return;
ColumnName = _column.Name;
IsNullable = _column.Nullable;
IsPKey = _column.IsPKey;
DefaultValue = Convert.ToString(_column.DefaultValue);
DataType = _column.Type;
AutoInc = _column.AutoInc;
UpdateCheckboxState();
}
public void UpdateColumnValues()
{
if (_column == null) return;
_column.Name = ColumnName;
_column.Nullable = IsNullable;
_column.IsPKey = IsPKey;
_column.DefaultValue = DefaultValue;
_column.Type = DataType;
_column.AutoInc = AutoInc;
}
public ColumnDisplay(SqlDataColumn column) : this()
{
this.Column = column;
}
public bool AutoInc
{
get
{
return cbAutoInc.Checked;
}
set
{
cbAutoInc.Checked = value;
}
}
public string ColumnName
{
get
{
return tbColumnName.Text;
}
set
{
if (value == null)
{
tbColumnName.Text = string.Empty;
}
else
{
tbColumnName.Text = value;
}
}
}
public bool IsNullable
{
get
{
return cbNullable.Checked;
}
set
{
cbNullable.Checked = value;
}
}
public bool IsPKey
{
get
{
return cbPrimaryKey.Checked;
}
set
{
cbPrimaryKey.Checked = value;
pictureBox1.Visible = value;
}
}
public string DefaultValue
{
get
{
return tbDefaultValue.Text;
}
set
{
tbDefaultValue.Text = value;
}
}
private void UpdateCheckboxState()
{
if (IsPKey)
{
cbAutoInc.Enabled = true;
IsNullable = false;
cbNullable.Enabled = false;
}
else
{
AutoInc = false;
cbAutoInc.Enabled = false;
cbNullable.Enabled = true;
}
pictureBox1.Visible = IsPKey;
}
public string DataType
{
get
{
return cbDataType.Text;
}
set
{
cbDataType.SelectedIndex = -1;
if (string.IsNullOrEmpty(value)) return;
for (var i = 0; i < cbDataType.Items.Count; i++)
{
if (cbDataType.Items[i].ToString().ToUpper() == value.ToUpper())
{
cbDataType.SelectedIndex = i;
break;
}
}
}
}
private void cbPrimaryKey_CheckedChanged(object sender, EventArgs e)
{
UpdateCheckboxState();
}
private void cbPrimaryKey_Click(object sender, EventArgs e)
{
if (cbPrimaryKey.Checked) OnPrimaryKeyChecked?.Invoke(this);
}
private void ColumnDisplay_Leave(object sender, EventArgs e)
{
UpdateColumnValues();
pictureBox1.Visible = Column.IsPKey;
}
private void cbAutoInc_Click(object sender, EventArgs e)
{
if (cbAutoInc.Checked)
{
tbDefaultValue.Text = string.Empty;
Column.DefaultValue = string.Empty;
tbDefaultValue.Enabled = false;
DataType = "Integer";
} else
{
tbDefaultValue.Enabled = true;
}
}
}
}