| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 996 人关注过本帖
标题:常用的小类库!!!
取消只看楼主 加入收藏
leo_li
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2004-4-21
收藏
 问题点数:0 回复次数:0 
常用的小类库!!!

using System; using System.Data; using System.Data.OleDb; using System.Text; using System.IO; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Web.UI; using System.Web; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Web.SessionState;

namespace lpt_sys { /// <summary> /// ClassLpt 的摘要说明。 /// </summary> public class ClassLpt { public ClassLpt() { // // TOD 在此处添加构造函数逻辑 // }

String OleConnstr="Provider=MSDAORA.1;Password=lpt;User ID=lpt;Data Source=winsfc"; // String OleConnstr="Provider=MSDAORA.1;Password=lpt;User ID=lpt;Data Source=sfcdb"; public string TxtRet = "<br><div align=right><a href='javascript:history.go(-1)'>[返回]</a></div>"; public string msg1 = "目前正处于测试阶段,有问题请." + "<br><font color='51485f'>请联络:李兆华 分机2266</font>" + " &nbsp;&nbsp;谢谢合作!<br>[错误信息]<font color = '336633'>";

public Boolean Execute_Reasult(string sql) { OleDbConnection MyConn = new OleDbConnection(OleConnstr); MyConn.Open(); DataSet MyDataset = new DataSet(); OleDbCommand MyCommand = new OleDbCommand(sql, MyConn); OleDbDataAdapter myAdapter = new OleDbDataAdapter(MyCommand); myAdapter.Fill(MyDataset,"one"); DataTable mytable=MyDataset.Tables["one"]; if (mytable.Rows.Count>0) { return true; } else { return false; } }

public OleDbDataReader Reader(string sql) { OleDbConnection MyConn = new OleDbConnection(OleConnstr); try { MyConn.Open(); OleDbCommand MyCmd= new OleDbCommand(sql,MyConn); OleDbDataReader myReader=MyCmd.ExecuteReader(); while (myReader.Read()) { Console.Write(myReader.GetInt32(0) + ", " + myReader.GetString(1)); } // always call Close when done reading. myReader.Close(); // Close the connection when done with it. MyConn.Close(); return myReader; } catch { MyConn.Close(); } finally { MyConn.Close(); } return null; }

public DataSet Get_Ds(string sql) { OleDbConnection MyConn = new OleDbConnection(OleConnstr); MyConn.Open(); DataSet MyDataset = new DataSet(); OleDbCommand MyCommand = new OleDbCommand(sql, MyConn); OleDbDataAdapter myAdapter = new OleDbDataAdapter(MyCommand); myAdapter.Fill(MyDataset,"one"); return MyDataset; }

public DataSet Get_Ds(string sql,string tab) { OleDbConnection MyConn = new OleDbConnection(OleConnstr); MyConn.Open(); DataSet MyDataset = new DataSet(); OleDbCommand MyCommand = new OleDbCommand(sql, MyConn); OleDbDataAdapter myAdapter = new OleDbDataAdapter(MyCommand); myAdapter.Fill(MyDataset,tab); return MyDataset; }

public void Execute(string sql) { OleDbConnection myConnection = new OleDbConnection(OleConnstr); OleDbCommand myCommand = new OleDbCommand(sql, myConnection); myConnection.Open(); myCommand.ExecuteNonQuery(); myCommand.Dispose(); myConnection.Close(); }

public string Q(string Temp) {string t; if (IsLen0(Temp)) { return "''"; } else { t=Temp.Trim() + ""; return "'" + Temp.ToUpper() + "'"; } }

public Boolean IsLen0(object obj) { if(obj.ToString().Trim().Length==0) { return true; } else { return false; } }

public string D(string Tmp) { string t; if(IsLen0(Tmp)) { return "''"; } else { t=Tmp.Trim() + ""; return "#" + Tmp.ToUpper() + "#"; } }

public string Checked(Boolean val) { if (val==true) { return "Y"; } else { return "N"; } }

public void Check(System.Web.UI.WebControls.CheckBox obj,string val) { if (val.ToUpper()=="Y") { obj.Checked =true; } else { obj.Checked=false; } }

public void DrpSelect(System.Web.UI.WebControls.DropDownList obj,string val) { int i; for(i=0;i<=obj.Items.Count-1;i++) { //if(obj.Items[i].Value.Trim().ToUpper()==val.Trim().ToUpper()) //obj.Items[i].Selected=true; //else // obj.Items[i].Selected=false; obj.Items[i].Selected=((obj.Items[i].Text.Trim()).ToUpper() == (val.Trim()).ToUpper()); } }

public string CheckStrNull(object val) { if(val!=System.DBNull.Value) return val.ToString().Trim(); else return "";

}

public int CheckIntNull(string str) { if (str.Trim()=="") return 0; else return int.Parse(str.Trim()); }

public double CheckDouNull(object obj) { switch(obj.GetType().FullName) { case "System.DBNull" : return 0; case "System.Int16" : return (int)obj; case "System.Int32" : return (int)obj; case "System.Int64": return (int)obj; case "System.Decimal": return (double)((Decimal)obj); case "System.Double": return (Double)obj; case "System.String": return double.Parse((string)obj); default: return (double)obj; } }

public int CInt(object PValue ) { switch (PValue.GetType().FullName) { case "System.DBNull" : return 0; case "System.Double" : return (int)PValue; case "System.Int32" : return (int)PValue; case "System.Decimal": return (int)((decimal)PValue); case "System.String" : return int.Parse((string)PValue); //字符串型转换为int,float,double,... default : return (int)PValue; } }

} }

搜索更多相关主题的帖子: 类库 
2004-04-21 15:20
快速回复:常用的小类库!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029819 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved