FormUtil.cs
5.0 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TSA_V.Common
{
public class FormUtil
{
public static int GetIntValue(string str)
{
int value = 0;
try
{
value = int.Parse(str );
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static int GetIntValue(Control txt)
{
int value = 0;
try
{
value = int.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static int GetIntValue(TextBox txt)
{
int value = 0;
try
{
value = int.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static short GetShortValue(TextBox txt)
{
short value = 0;
try
{
value = short.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static double getDoubleValue(TextBox txt)
{
double value = 0;
try
{
value = double.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static short get16ShortValue(TextBox txt)
{
short value = 0;
try
{
value = System.Convert.ToInt16(txt.Text,16);
}
catch
{
value = 0;
}
return value;
}
public static string GetShowStr(double value)
{
string wStr = "";
if (value == (int)value)
{
wStr = string.Format("{0:d}", (int)value);
}
else
{
wStr = string.Format("{0:f}", value);
}
return wStr;
}
public static bool IsIp(string ip)
{
string[] ipstr = ip.Split('.');
if (ipstr.Length == 4)
{
foreach (string str in ipstr)
{
int count = 0;
try
{
count = Convert.ToInt32(str);
}
catch (Exception ex)
{
return false;
}
if (count <0 || count > 255)
{
return false;
}
}
return true;
}
else
{
return false;
}
}
public static string getValue(TextBox txtBoardName)
{
return txtBoardName.Text.Trim();
}
public static uint GetuIntValue(TextBox txtNode)
{
uint value = 0;
try
{
value = Convert.ToUInt32(txtNode.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static double StrToDouble(string obj)
{
double value = 0;
try
{
value = double.Parse(obj.Trim());
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static string GetSpanStr(TimeSpan span)
{
//return Convert.ToDateTime(span.ToString()).ToString("HH:mm:ss");
string seconds = Math.Round(span.TotalSeconds % 60, 1).ToString();
if (seconds.IndexOf(".") >= 0)
{
seconds = seconds.ToString().PadLeft(4, '0');
}
else
{
seconds = seconds.ToString().PadLeft(2, '0');
}
return span.Hours.ToString().PadLeft(2, '0') + ":" + span.Minutes.ToString().PadLeft(2, '0') + ":" + seconds;
}
public static string GetSpanStr2(TimeSpan span)
{
//return Convert.ToDateTime(span.ToString()).ToString("HH:mm:ss");
string seconds =((int) Math.Round(span.TotalSeconds % 60, 1)).ToString();
if (seconds.IndexOf(".") >= 0)
{
seconds = seconds.ToString().PadLeft(4, '0');
}
else
{
seconds = seconds.ToString().PadLeft(2, '0');
}
return span.Hours.ToString().PadLeft(2, '0') + ":" + span.Minutes.ToString().PadLeft(2, '0') + ":" + seconds;
}
}
}