1.web.config文件图:内容见图
2.取出<add key="stringname" value="value" />中值的方法:
/// <summary>
/// Read resource from web.config
/// </summary>
/// <param name="nodes"></param>
/// <returns></returns>
public static string GetResourceStr(string key)
{
return System.Configuration.ConfigurationSettings.AppSettings[key];
}
3.PageCtrl.cs页面代码
using System;
namespace CommtobaccoMgr
{
/// <summary>
/// PageCtrl 的摘要说明。
/// </summary>
public class PageCtrl
{
private int PageNo;
private int PageSize;
public int TotalCount;
public PageCtrl(int PageNo,int PageSize)
{
this.PageNo = PageNo;
this.PageSize = PageSize;
}
public string PagedSQL(int PageNo,int PageSize,string ID,string Sort,string SQL)
{
string returnSQL;
returnSQL = "SELECT TOP " + PageSize + " * FROM (" + SQL + ") Table1 WHERE Table1." + ID + " NOT IN ";
returnSQL += " (SELECT TOP " + PageSize * (PageNo-1) + " " + ID + " FROM ( " + SQL + ") Table2 ORDER BY " + Sort + ")";
returnSQL += "ORDER BY " + Sort;
return returnSQL;
}
public string PagedSQL(string ID,string Sort,string SQL)
{
return this.PagedSQL(this.PageNo,this.PageSize,ID,Sort,SQL);
}
public string GetCountSQL(string SQL)
{
string returnSQL;
returnSQL = "SELECT COUNT(*) FROM (" + SQL + ") Table4Count";
return returnSQL;
}
}
}
4.分页数据集的操作:
public DataTable SearchSaleResult(string Selorgid,string QueryDate,string bankid,PageCtrl pageCtrl,string customerid,string customercode)
{
SqlConnection con = null;
SqlCommand cmd = null;
con = new SqlConnection(Util.Connection.ConnectionString);
con.Open();
cmd = new SqlCommand();
cmd.Connection = con;
string sql="";
string tableSett="";
string tableBal="";
string selectSql ="";
DateTime curentTime=System.Convert.ToDateTime(System.DateTime.Now.ToShortDateString());
DateTime queryTime=System.Convert.ToDateTime(QueryDate);
TimeSpan subSpan=curentTime.Subtract(queryTime);
int subTime=System.Convert.ToInt16(subSpan.TotalDays);
if (subTime<31 && subTime>=0)
{
tableSett="cm_settlement";
tableBal="cm_balanceresult";
}
else
{
tableSett="TB_V_settlement";
tableBal="TB_V_balanceresult";
}
sql = "select t2.journalid,t3.account_id,t2.bankseq,t2.orgid,isnull(t2.reserve3,'') As Reason,t2.creator,t2.customerid,t2.orderid,t2.payment,t2.settlestatus,t1.bankbalance,t1.bankstatus,t4.customercode,"
+" balancestatus = case balancestatus when '2' then '0' else isnull(balancestatus, '1') end "
+ " from "+tableSett+" t2 LEFT OUTER JOIN "+tableBal+" t1 ON t2.journalid = t1.journalid LEFT OUTER JOIN tb_account t3 ON t3.customer_id = t2.customerid left outer join TB_NOTIFICATION t4 on t3.customer_id=t4.customer_id "
+ "where settlestatus not in ('04','05') and isnull(t2.reserve3, '') <> '冲正' ";
if(Selorgid!="")
{
sql+="and t2.orgid = '"+Selorgid+"'";
}
if(QueryDate!="")
{
sql+="and Datediff(dd,creatortime,cast('"+QueryDate + "' as datetime))=0 ";
}
if(bankid!="")
{
sql+="and t2.bankid = '"+bankid+"'";
}
if (customerid!=""&&customercode=="")
{
sql+="and t2.customerid = '"+customerid+"'";
}
if(customercode!=""&&customerid=="")
{
string customeridByCode=AddCode.GetCustomerIDByCustomercode(customercode);
sql+="and t4.customer_id='"+customeridByCode+"'";
}
if(customerid!=""&&customercode!="")
{
sql+="and t2.customerid = '"+customerid+"'";
}
selectSql = pageCtrl.PagedSQL("journalid","balancestatus desc, settlestatus desc,customerid ASC,journalid desc",sql);
cmd.CommandText = pageCtrl.GetCountSQL(sql);
pageCtrl.TotalCount = (int)cmd.ExecuteScalar();
SqlDataAdapter adapter = new SqlDataAdapter(selectSql,Util.Connection.ConnectionString);
DataTable table = new DataTable();
adapter.Fill(table);
adapter.Dispose();
return table;
}//我直接COPY的代码
5.剩下的话就只要你操作table了
6.说明:很多参数的设置都可以放在web.config中,这样可以在编译后能修改其中的数据,而不用修改源代码!