/
UniversalStatic.cs
128 lines (110 loc) · 4.12 KB
/
UniversalStatic.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
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace BioMetrixCore
{
internal class UniversalStatic
{
public const string acx_Disconnect = "Disconnected";
public static bool ValidateIP(string addrString)
{
IPAddress address;
if (IPAddress.TryParse(addrString, out address))
return true;
else
return false;
}
public static void DrawLineInFooter(Control control, Color color, int thickness)
{
int y = control.Height;
DrawLine(control, color, 0, y, control.Width, y, thickness);
}
public static void DrawLine(Control control, Color color, int x, int y, int x1, int y1, int thickness)
{
Graphics graphicsObj = control.CreateGraphics();
graphicsObj.DrawLine(new Pen(color, thickness), x, y, x1, y1);
}
public static bool PingTheDevice(string ipAdd)
{
try
{
IPAddress ipAddress = IPAddress.Parse(ipAdd);
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(ipAddress, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
return true;
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}
public static string SplitPascal(string text)
{
Regex r = new Regex("([A-Z]+[a-z]+)");
string result = r.Replace(text, m => (m.Value.Length > 3 ? m.Value : m.Value.ToLower()) + " ");
return result;
}
public static Image StringToImage(string imageString)
{
byte[] bArray1 = Convert.FromBase64String(imageString);
MemoryStream ms = new MemoryStream(bArray1);
Image logo = Image.FromStream(ms, true, true);
return logo;
}
public static string IntegerValidation(char[] enteredString, string actualString)
{
foreach (char c in enteredString.AsEnumerable())
{
if (Char.IsDigit(c))
{ actualString = actualString + c; }
else
{
actualString.Replace(c, ' ');
actualString.Trim();
}
}
return actualString;
}
public static void ValidateInteger(TextBox tbx)
{
string actualString = string.Empty;
char[] enteredString = tbx.Text.ToCharArray();
tbx.Text = IntegerValidation(enteredString, actualString);
tbx.Select(tbx.Text.Length, 0);
}
public static void ChangeGridProperties(DataGridView dgvMaster)
{
dgvMaster.DefaultCellStyle.Font = new Font("Segoe UI", 8F);
dgvMaster.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgvMaster.RowHeadersWidth = 10;
dgvMaster.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
dgvMaster.RowHeadersVisible = false;
dgvMaster.RowTemplate.DefaultCellStyle.Padding = new Padding(5, 0, 10, 0);
foreach (DataGridViewColumn c in dgvMaster.Columns)
{
c.Resizable = DataGridViewTriState.False;
c.ReadOnly = true;
}
dgvMaster.AllowUserToOrderColumns = true;
dgvMaster.BackgroundColor = SystemColors.Control;
dgvMaster.BorderStyle = BorderStyle.Fixed3D;
}
}
}