-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryForm.cs
182 lines (169 loc) · 5.35 KB
/
QueryForm.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
/*
* Created by SharpDevelop.
* User: Луферов Александр Николаевич
*
*
*
* Лицензия GPL v2.0: http://www.gnu.org/licenses/gpl-2.0.html.
*/
namespace Surf2Excel
{
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
/// <summary>
/// Description of QueryForm.
/// </summary>
public partial class QueryForm : Form
{
public QueryForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
/// <summary>
/// Update data onto the comboBox controls cbSelAlgn, cbSelExSurf and cbSelPrSurf
/// </summary>
public void UpdateData()
{
// Get list of alignments in drawing
cbSelAlgn.Items.AddRange(CivApp.GetAlignmentList().ToArray() as Object[]);
cbSelExSurf.Items.AddRange(CivApp.GetSurfaceList().ToArray() as Object[]);
cbSelPrSurf.Items.AddRange(CivApp.GetSurfaceList().ToArray() as Object[]);
if (cbSelAlgn.Items.Count == 0
|| cbSelExSurf.Items.Count == 0
|| cbSelPrSurf.Items.Count == 0) {
cbSelAlgn.Enabled = false;
cbSelExSurf.Enabled = false;
cbSelPrSurf.Enabled = false;
btSolut.Enabled = false;
btSelAlgn.Enabled = false;
btSelExSurf.Enabled = false;
btSelPrSurf.Enabled = false;
} else {
cbSelAlgn.Text = (string)cbSelAlgn.Items[0];
cbSelExSurf.Text = (string)cbSelExSurf.Items[0];
cbSelPrSurf.Text = (string)cbSelPrSurf.Items[0];
}
}
/// <summary>
/// Check state of controll: cbSelExSurf, cbSelPrSurf, cbSelAlgn,
/// tbStartPKUse, tbEndPKUse, tbMinWidth, tbMaxWidth, tbStep, tbHeightVyr
/// </summary>
/// <returns>if all their data valid return true, else return false</returns>
private Boolean CheckInputDataState()
{
var IsDataValid = true;
//Check cbSelExSurf, cbSelPrSurf, cbSelAlgn
//they can contain only "" or valid data
if (cbSelAlgn.Text == "" || cbSelPrSurf.Text == "" || cbSelAlgn.Text == "") {
IsDataValid = false;
}
//Check tbStartPKUse, tbEndPKUse
//they can contain "", valid date, and invalid data
if (tbStartPKUse.Text == "" || tbEndPKUse.Text == "") {
IsDataValid = false;
} else {
var start = 0.0d;
var end = 0.0d;
var parseResult1 = Double.TryParse(tbStartPKUse.Text, out start);
var parseResult2 = Double.TryParse(tbEndPKUse.Text, out end);
if (!parseResult1 || !parseResult2) {
IsDataValid = false;
} else {
var startAl = Double.Parse(tbStartPKUse.Text);
var endAl = Double.Parse(tbEndPKUse.Text);
if (start < startAl || start >= end || end > endAl) {
IsDataValid = false;
}
}
}
return IsDataValid;
}
/// <summary>
/// Filtrate any non digit and decimal point characters
/// </summary>
/// <param name="sender">Controll which send events</param>
/// <param name="e">Event arguments</param>
/// <returns>True if pressed digital character or decimal point character
/// (not first character), otherwise false </returns>
private Boolean FiltrateNonDoublePositiveNumbers(object sender, KeyPressEventArgs e)
{
//Filtr any non digit and decimal point characters
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.') {
return true;
}
//Only allow one decimal point and not first character
if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1
&& (sender as TextBox).Text.IndexOf('.') != 0) {
return true;
}
return false;
}
void CbSelAlgnSelectedIndexChanged(object sender, EventArgs e)
{
if (cbSelAlgn.SelectedItem != null) {
//If into the drawing exists alignment enable controlls
gbAlgn.Enabled = true;
gbSect.Enabled = true;
gbRaschUch.Enabled = true;
var alignName = cbSelAlgn.SelectedItem as string;
var startPK = 0.0d;
var endPK = 0.0d;
var length = 0.0d;
CivApp.GetAlignmentData(alignName, out startPK, out endPK, out length);
tbStartPK.Text = startPK.ToString();
tbEndPK.Text = endPK.ToString();
lbAlgnName.Text = alignName;
lbAlgnLength.Text = length.ToString();
}else {
gbAlgn.Enabled = false;
gbSect.Enabled = false;
}
}
void TbMinWidthKeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = FiltrateNonDoublePositiveNumbers(sender, e);
}
void TbMaxWidthKeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = FiltrateNonDoublePositiveNumbers(sender, e);
}
void TbStepKeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = FiltrateNonDoublePositiveNumbers(sender, e);
}
void TbHeightVyrKeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = FiltrateNonDoublePositiveNumbers(sender, e);
}
void TbStartPKUseKeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = FiltrateNonDoublePositiveNumbers(sender, e);
}
void TbEndPKUseKeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = FiltrateNonDoublePositiveNumbers(sender, e);
}
void BtSolutClick(object sender, EventArgs e)
{
//Validating data onto controlls
if (!CheckInputDataState()) {
MessageBox.Show("Проверьте правильность введенных данных");
return;
}
}
void Button1Click(object sender, EventArgs e)
{
this.Close();
}
}
}