温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:项目管理系统(多用户)源码
当前文件:
ProjectManager/App_Code/common/Utilities.cs[9K,2009-6-12 11:52:29],打开代码结构图
ProjectManager/App_Code/common/Utilities.cs[9K,2009-6-12 11:52:29],打开代码结构图1using System; 2
using System.Collections.Generic; 3
using System.Text; 4
using System.Net.Mail; 5
using System.Drawing; 6
using System.Web.Security; 7
using System.Data; 8
using System.Web.UI; 9
using System.Web.UI.WebControls; 10
using System.Web.UI.HtmlControls; 11
using System.Collections; 12
using System.Data.Common; 13
namespace projmanager 14
{ 15
public class Utilities 16
{ 17
18
public static void SendMail(string from, string to, string subject, string body) 19
{ 20
21
SmtpClient mailClient = new SmtpClient(/*BalloonShopConfiguration.MailServer*/""); 22
23
MailMessage mailMessage = new MailMessage(from, to, subject, body); 24
/* 25
// For SMTP servers that require authentication 26
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); 27
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "SmtpHostUserName"); 28
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "SmtpHostPassword"); 29
*/ 30
// Send mail 31
mailClient.Send(mailMessage); 32
} 33
34
// Send error log mail 35
36
/* 37
public static void LogError(Exception ex) 38
{ 39
// get the current date and time 40
string dateTime = DateTime.Now.ToLongDateString() + ", at " 41
+ DateTime.Now.ToShortTimeString(); 42
// stores the error message 43
string errorMessage = "Exception generated on " + dateTime; 44
// obtain the page that generated the error 45
System.Web.HttpContext context = System.Web.HttpContext.Current; 46
errorMessage += "\n\n Page location: " + context.Request.RawUrl; 47
// build the error message 48
errorMessage += "\n\n Message: " + ex.Message; 49
errorMessage += "\n\n Source: " + ex.Source; 50
errorMessage += "\n\n Method: " + ex.TargetSite; 51
errorMessage += "\n\n Stack Trace: \n\n" + ex.StackTrace; 52
// send error email in case the option is activated in Web.Config 53
if (BalloonShopConfiguration.EnableErrorLogEmail) 54
{ 55
string from = "noreply@cristiandarie.ro"; 56
string to = BalloonShopConfiguration.ErrorLogEmail; 57
string subject = BalloonShopConfiguration.SiteName + " error report"; 58
string body = errorMessage; 59
SendMail(from, to, subject, body); 60
} 61
} 62
*/ 63
64
65
public static int getWeeksByDate(DateTime dt) 66
{ 67
int days = dt.DayOfYear; 68
int weeks = 0; 69
if (days % 7 == 0) 70
{ 71
weeks = days / 7; 72
} 73
else 74
{ 75
weeks = days / 7 + 1; 76
} 77
return weeks; 78
} 79
80
81
public static void TieButton(Page page, Control TextBoxToTie, Control ButtonToTie) 82
{ 83
// Init jscript 84
string jsString = ""; 85
86
// Check button type and get required jscript 87
if (ButtonToTie is LinkButton) 88
{ 89
jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {" 90
+ page.ClientScript.GetPostBackEventReference(ButtonToTie, "").Replace(":", "$") + ";return false;} else return true;"; 91
} 92
else if (ButtonToTie is ImageButton) 93
{ 94
jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {" 95
+ page.ClientScript.GetPostBackEventReference(ButtonToTie, "").Replace(":", "$") + ";return false;} else return true;"; 96
} 97
else 98
{ 99
jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {document." 100
+ "forms[0].elements['" + ButtonToTie.UniqueID.Replace(":", "_") + "'].click();return false;} else return true; "; 101
} 102
103
// Attach jscript to the onkeydown attribute - we have to cater for HtmlControl or WebControl 104
if (TextBoxToTie is HtmlControl) 105
{ 106
((HtmlControl)TextBoxToTie).Attributes.Add("onkeydown", jsString); 107
} 108
else if (TextBoxToTie is WebControl) 109
{ 110
((WebControl)TextBoxToTie).Attributes.Add("onkeydown", jsString); 111
} 112
} 113
114
115
public static void BindingDataGridView(GridView dg, DataTable dt, string[] DataKeyNames) 116
{ 117
dg.DataSource = dt; 118
dg.DataKeyNames = DataKeyNames; 119
dg.DataBind(); 120
} 121
122
public static void BindingDropDownList(DropDownList ddl, DataTable dt, string strTextField, string strValueField) 123
{ 124
ddl.DataSource = dt; 125
ddl.DataTextField = strTextField; 126
if (strValueField != "" || strValueField != null) 127
ddl.DataValueField = strValueField; 128
ddl.DataBind(); 129
} 130
131
public static void BindingListBox(ListBox lb, DataTable dt, string strDisplayMember, string strValueMember) 132
{ 133
lb.DataSource = dt; 134
lb.DataTextField = strDisplayMember; 135
if (strValueMember != "" || strValueMember != null) 136
lb.DataValueField = strValueMember; 137
lb.DataBind(); 138
} 139
140
141
public static string GetValueInDDLByText(DropDownList ddl, string strSelectDisplayMember) 142
{ 143
string str = String.Empty; 144
foreach (ListItem li in ddl.Items) 145
{ 146
if (li.Text == strSelectDisplayMember) 147
{ 148
str = li.Value; 149
} 150
} 151
return str; 152
} 153
154
public static ArrayList GetFontsName() 155
{ 156
ArrayList al = new ArrayList(); 157
foreach (FontFamily oneFontFamily in FontFamily.Families) 158
{ 159
al.Add(oneFontFamily.Name); 160
} 161
return al; 162
} 163
164
public static void BindingDataList(DataList dl, DataTable dt, string datakeyfield) 165
{ 166
dl.DataSource = dt; 167
dl.DataKeyField = datakeyfield; 168
dl.DataBind(); 169
} 170
public static void BindingDropDownList(DropDownList ddl, ArrayList al) 171
{ 172
ddl.DataSource = al; 173
ddl.DataValueField = ddl.DataTextField; 174
ddl.DataMember = ddl.DataValueField; 175
ddl.DataBind(); 176
} 177
178
public static void SetSelectDropDownListByDisplayMember(DropDownList ddl, string strDisplayMember) 179
{ 180
int i = 0; 181
foreach (ListItem li in ddl.Items) 182
{ 183
if (li.Text == strDisplayMember) 184
{ 185
ddl.SelectedIndex = i; 186
break; 187
} 188
i++; 189
} 190
} 191
192
public static void SetSelectDropDownListByValueMember(DropDownList ddl, string strValueMember) 193
{ 194
int i = 0; 195
foreach (ListItem li in ddl.Items) 196
{ 197
if (li.Value == strValueMember) 198
{ 199
ddl.SelectedIndex = i; 200
break; 201
} 202
i++; 203
} 204
205
} 206
207
208
public static string Encrypt(string strS) 209
{ 210
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(strS, true, 10); 211
return (FormsAuthentication.Encrypt(ticket).ToString()); 212
} 213
214
public static string Decrypt(string strS) 215
{ 216
return (FormsAuthentication.Decrypt(strS).Name.ToString()); 217
} 218
219
220
public static bool CheckEmpIsProjectManager(string employeeid,string departmentid) 221
{ 222
bool IsProjectManager = false; 223
string sql = "select projectid from project p where p.departmentid=" + departmentid + " and projectmanagerid=" + employeeid; 224
225
if (DataAccess.ExecuteScalar(sql) !=null) 226
{ 227
IsProjectManager = true; 228
} 229
230
return IsProjectManager; 231
} 232
233
public static int GetEmpGroupIDByGroupLeaderID(string groupleaderid, string departmentid) 234
{ 235
int glid = -1; 236
string sql = "select groupid from [group] g where g.groupleaderid =" + groupleaderid; 237
object ret = DataAccess.ExecuteScalar(sql); 238
if (ret != null) 239
{ 240
glid = (int)ret; 241
} 242
return glid; 243
} 244
245
public static bool CheckEmpIsGroupLeader(string groupleaderid, string departmentid) 246
{ 247
if (GetEmpGroupIDByGroupLeaderID(groupleaderid, departmentid) == -1) 248
{ 249
return false; 250
} 251
else 252
{ 253
return true; 254
} 255
} 256
257
public static bool IsMyWeekly(string weeklyid,string employeeid) 258
{ 259
bool ret = false; 260
string sql = "select weeklyid from weekly where employeeid=" + employeeid + " and weeklyid=" + weeklyid; 261
DbDataReader ddr = DataAccess.ExecuteDataReader(sql); 262
if (ddr.HasRows) 263
{ 264
ret = true; 265
} 266
ddr.Close(); 267
return ret; 268
} 269
270
} 271
} 272






}