您目前尚未登陆,请选择【登陆】或【注册
首页->其他源码->学生管理信息系统+留言板>>Module/CCUtility.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:学生管理信息系统+留言板
当前文件:文件类型 StudentSys/Module/CCUtility.cs打开代码结构图
普通视图
		            
1namespace StudentSys.Module 2{ 3 using System; 4 using System.Collections; 5 using System.ComponentModel; 6 using System.Data; 7 using System.Data.OleDb; 8 using System.Drawing; 9 using System.Web; 10 using System.Web.SessionState; 11 using System.Web.UI; 12 using System.Web.UI.WebControls; 13 using System.Web.UI.HtmlControls; 14 15//定义PositionData类 16 public class PositionData { 17 18 private string name; 19 private string CatID; 20 21 public PositionData(string Name, string CategoryID) 22 { 23 this.name = Name; 24 this.CatID = CategoryID; 25 } 26 27 public string Name 28 { 29 get { 30 return name; 31 } 32 } 33 34 public string CategoryID { 35 get { 36 return CatID; 37 } 38 } 39 } 40 41 //定义CCUtility类 42 public class CCUtility 43 { 44 public const int FIELD_TYPE_Text = 0; 45 public const int FIELD_TYPE_Number = 1; 46 public const int FIELD_TYPE_Date = 2; 47 public const int FIELD_TYPE_Memo = 3; 48 protected HttpSessionState Session; 49 protected HttpServerUtility Server; 50 protected HttpRequest Request; 51 protected HttpResponse Response; 52 53 public static string ToSQL(string Param, int iType) { 54 if (Param == null || Param.Length == 0) { 55 return "Null"; 56 } else { 57 string str = Quote(Param); 58 if (iType == FIELD_TYPE_Number) { 59 return str.Replace(',','.'); 60 } else { 61 return "\'" + str + "\'"; 62 } 63 } 64 } 65 66 public CCUtility(object parent) 67 { 68 DBOpen(); 69 try 70 { 71 Session=((System.Web.UI.Page)parent).Session; 72 Server=((System.Web.UI.Page)parent).Server; 73 Request=((System.Web.UI.Page)parent).Request; 74 Response=((System.Web.UI.Page)parent).Response; 75 }catch{ 76 Session=((System.Web.UI.UserControl)parent).Session; 77 Server=((System.Web.UI.UserControl)parent).Server; 78 Request=((System.Web.UI.UserControl)parent).Request; 79 Response=((System.Web.UI.UserControl)parent).Response; 80 } 81 82 } 83 84 85 86 public String GetValFromLOV(String val, String[] arr) { 87 String ret = ""; 88 if (arr.Length % 2 == 0) { 89 int temp=Array.IndexOf(arr,val); 90 ret=temp==-1?"":arr[temp+1];} 91 return ret; 92 } 93 94 95 96 public bool IsNumeric(object source, string value) { 97 try{ 98 Decimal temp=Convert.ToDecimal(value); 99 return true; 100 }catch { 101 return false; 102 } 103 } 104 105 public static string Quote(string Param) { 106 if (Param == null || Param.Length == 0) { 107 return ""; 108 } else { 109 return Param.Replace("'","''"); 110 } 111 } 112 113 public static string GetValue(DataRow row, string field) { 114 if (row[field].ToString() == null) 115 return ""; 116 else 117 return row[field].ToString(); 118 } 119 120 121 //与数据库连接方法的定义 122 public OleDbConnection Connection; 123 124 public DataSet FillDataSet(string sSQL) 125 { 126 DataSet ds = new DataSet(); 127 OleDbDataAdapter command = new OleDbDataAdapter(sSQL, Connection); 128 return ds; 129 } 130 131 public int FillDataSet(string sSQL,ref DataSet ds) 132 { 133 OleDbDataAdapter command = new OleDbDataAdapter(sSQL, Connection); 134 return command.Fill(ds, "Table"); 135 } 136 137 public int FillDataSet(string sSQL,ref DataSet ds,int start, int count) 138 { 139 OleDbDataAdapter command = new OleDbDataAdapter(sSQL, Connection); 140 return command.Fill(ds, start, count, "Table"); 141 } 142 143 //打开数据库联结 144 public void DBOpen() 145 { 146 //从Web.Config中获取连接数据库字符串 147 string sConnectionString=System.Configuration.ConfigurationSettings.AppSettings["sStudentSysDBConnectionString"]; 148 //创建一个联结实例 149 Connection = new OleDbConnection(sConnectionString); 150 Connection.Open(); 151 152 } 153 154 public void DBClose(){ 155 Connection.Close(); 156 } 157 158 public string GetParam(string ParamName) { 159 string Param = Request.QueryString[ParamName]; 160 if (Param == null) 161 Param = Request.Form[ParamName]; 162 if (Param == null) 163 return ""; 164 else 165 return Param; 166 } 167 168 public string Dlookup(string table, string field, string sWhere) 169 { 170 string sSQL = "SELECT " + field + " FROM " + table + " WHERE " + sWhere; 171 172 OleDbCommand command = new OleDbCommand(sSQL, Connection); 173 OleDbDataReader reader=command.ExecuteReader(CommandBehavior.SingleRow); 174 string sReturn; 175 176 if (reader.Read()) { 177 sReturn = reader[0].ToString(); 178 if (sReturn == null) 179 sReturn = ""; 180 } else { 181 sReturn = ""; 182 } 183 184 reader.Close(); 185 return sReturn; 186 } 187 188 public int DlookupInt(string table, string field, string sWhere) 189 { 190 string sSQL = "SELECT " + field + " FROM " + table + " WHERE " + sWhere; 191 192 OleDbCommand command = new OleDbCommand(sSQL, Connection); 193 OleDbDataReader reader=command.ExecuteReader(CommandBehavior.SingleRow); 194 int iReturn = -1; 195 196 if (reader.Read()) { 197 iReturn = reader.GetInt32(0); 198 } 199 200 reader.Close(); 201 return iReturn; 202 } 203 204 public void Execute(string sSQL) 205 { 206 OleDbCommand cmd = new OleDbCommand(sSQL, Connection); 207 cmd.ExecuteNonQuery(); 208 } 209 210 211 public void buildListBox(ListItemCollection Items,string sSQL, string sId, string sTitle, string CustomInitialDisplayValue,string CustomInitialSubmitValue) 212 { 213 Items.Clear(); 214 OleDbCommand command = new OleDbCommand(sSQL, Connection); 215 OleDbDataReader reader = command.ExecuteReader(); 216 217 if(CustomInitialDisplayValue!=null) Items.Add(new ListItem(CustomInitialDisplayValue,CustomInitialSubmitValue)); 218 219 while(reader.Read()) { 220 if(sId==""&&sTitle=="") { 221 Items.Add(new ListItem(reader[1].ToString(),reader[0].ToString())); 222 }else{ 223 Items.Add(new ListItem(reader[sTitle].ToString(),reader[sId].ToString())); 224 } 225 } 226 reader.Close(); 227 } 228 229 public void buildListBox(ListItemCollection Items,string[] values, string CustomInitialDisplayValue,string CustomInitialSubmitValue) 230 { 231 Items.Clear(); 232 if(CustomInitialDisplayValue!=null) Items.Add(new ListItem(CustomInitialDisplayValue,CustomInitialSubmitValue)); 233 for(int i=0;i<values.Length;i+=2)Items.Add(new ListItem(values[i+1],values[i])); 234 } 235 236 237 public ICollection buildListBox(string sSQL, string sId, string sTitle, string CustomInitialDisplayValue,string CustomInitialSubmitValue) 238 { 239 DataRow row; 240 241 OleDbDataAdapter command = new OleDbDataAdapter(sSQL, Connection); 242 DataSet ds = new DataSet(); 243 ds.Tables.Add("lookup"); 244 245 DataColumn column = new DataColumn(); 246 column.DataType = System.Type.GetType("System.String"); 247 column.ColumnName = sId; 248 ds.Tables[0].Columns.Add(column); 249 250 column = new DataColumn(); 251 column.DataType = System.Type.GetType("System.String"); 252 column.ColumnName = sTitle; 253 ds.Tables[0].Columns.Add(column); 254 255 if (CustomInitialDisplayValue!=null) { 256 row = ds.Tables[0].NewRow(); 257 row[0] = CustomInitialSubmitValue; 258 row[1] = CustomInitialDisplayValue; 259 ds.Tables[0].Rows.Add(row);} 260 261 command.Fill(ds, "lookup"); 262 return new DataView(ds.Tables[0]); 263 } 264 265 266 public static string getCheckBoxValue(string sVal, string CheckedValue, string UnCheckedValue, int iType) 267 { 268 if (sVal.Length == 0) { 269 return ToSQL(UnCheckedValue, iType); 270 } else { 271 return ToSQL(CheckedValue, iType); 272 } 273 } 274 275 276 public bool CheckSecurity(int iLevel) { 277 if (Session["UserID"] == null || Session["UserID"