-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.cs
182 lines (148 loc) · 5.16 KB
/
Utility.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Net.Mail;
using System.IO;
//using Microsoft.Office.Interop.Outlook;
namespace MGM_Transformer
{
public class Utility
{
static public int GetAgentNoFromRepID(int iRepID)
{
int iRetVal = -1;
DataSet dsAgentNo;
dsAgentNo = DataLink.Select("select MGMAgentNo from Rep where RepID = " + iRepID, DataLinkCon.mgmuser);
if (dsAgentNo.Tables.Count > 0)
{
if (dsAgentNo.Tables[0].Rows.Count > 0)
{
iRetVal = Convert.ToInt32(dsAgentNo.Tables[0].Rows[0]["MGMAgentNo"]);
}
}
return iRetVal;
}
static public int GetQuoteEmailID(int iQuoteID)
{
int iQuoteEmailID = -1;
DataSet dsQuote = DataLink.Select("select max(QuoteEmailID) as QuoteEmailID from QuoteEmails where QuoteID = " + iQuoteID, DataLinkCon.mgmuser);
if (dsQuote.Tables.Count > 0)
{
if (dsQuote.Tables[0].Rows.Count > 0)
{
if (!DBNull.Value.Equals(dsQuote.Tables[0].Rows[0]["QuoteEmailID"]))
iQuoteEmailID = Convert.ToInt32(dsQuote.Tables[0].Rows[0]["QuoteEmailID"]);
}
}
return iQuoteEmailID;
}
static public bool IsValidEmail(string email)
{
try
{
var addr = new System.Net.Mail.MailAddress(email);
return addr.Address == email;
}
catch
{
return false;
}
}
static public string GetStringValue(DataSet ds, string sColumnName, int iIndex = 0)
{
string retVal = "";
try
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > iIndex)
{
if (ds.Tables[0].Rows[iIndex].Table.Columns.Contains(sColumnName))
{
if (DBNull.Value.Equals(ds.Tables[0].Rows[iIndex][sColumnName]))
return null;
retVal = Convert.ToString(ds.Tables[0].Rows[iIndex][sColumnName]);
}
}
}
}
catch (Exception ex) { return ""; }
return retVal;
}
static public List<T> GetValueList<T>(DataSet ds, string sColumnName)
{
List<T> retVal = new List<T>();
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0].Table.Columns.Contains(sColumnName))
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (!DBNull.Value.Equals(dr[sColumnName]) && dr[sColumnName].ToString() != "")
retVal.Add((T)(dr[sColumnName]));
}
}
}
}
return retVal;
}
static public decimal GetDecimalValue(DataSet ds, string sColumnName, int iIndex = 0)
{
decimal retValue = -1;
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > iIndex)
{
if (ds.Tables[0].Rows[iIndex].Table.Columns.Contains(sColumnName))
{
if (!decimal.TryParse(ds.Tables[0].Rows[iIndex][sColumnName].ToString(), out retValue))
retValue = -1;
}
}
}
return retValue;
}
/// <summary>
/// If we have 112.5 KVA, for example, returns 112.
/// </summary>
/// <param name="sValue"></param>
/// <returns></returns>
static public int IntFromString(string sValue)
{
if (sValue.IndexOf(".") > 0)
{
sValue = sValue.Substring(0, sValue.IndexOf("."));
}
int i = 0;
int.TryParse(sValue, out i);
return i;
}
static public int GetIntValue(DataSet ds, string sColumnName)
{
int retVal = -1;
try
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0].Table.Columns.Contains(sColumnName))
{
if (ds.Tables[0].Rows[0][sColumnName] == DBNull.Value)
retVal = -1;
else
retVal = Convert.ToInt32(ds.Tables[0].Rows[0][sColumnName]);
}
}
}
}
catch (Exception ex) { return -1; }
return retVal;
}
}
}