using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using Cheminfo.Domain;
using WebCheminfo_Components;
public class BizBase
{
//构造字符串容器,对String 的操作每次都要重新分配内存,所以这里用 StringBuilder
private const int pageSize = 10;
/// <summary>
/// 如果这里的orderType 是两个或者两个以上的时候这里的 sortType=3,其他情况下 sortType=4
/// </summary>
public const int recorderCount = 0;
public int _iRowCount = 0;
private int totalCount = 0;
private int totalPageCount = 0;
DateTime start = DateTime.Now;
public BizBase()
{
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
public DataSet GetDataSource(int maximumRows, int startRowIndex, string sqlcmd, string connString)
{
DataSet ds = new DataSet();
ds = cncic.kmp.DataBase.helper.SQL.ExecuteDataset(connString, CommandType.Text, sqlcmd);
this._iRowCount = ds.Tables[0].Rows.Count;
return ds;
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public DataSet GetDataSource(int maximumRows, int startRowIndex, string connString,
string tableName, string fieldList, string primaryKey, string where,
string order, int pageIndex, bool isRun, int sortType)
{
//ObjSession os = new ObjSession(HttpContext.Current.Session);
//string cacheKey = primaryKey + pageIndex +
// os.AdvanceSearch.Bt + os.AdvanceSearch.Scs.ToString() + os.AdvanceSearch.Ss.ToString();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
if (isRun)
{
try
{
#region 1
//if (cncic.Cache.DefaultCacheStrategy.GetWebCacheObj[cacheKey] == null ||
// cncic.Cache.DefaultCacheStrategy.GetWebCacheObj[cacheKey + "totalCount"] == null
// || cncic.Cache.DefaultCacheStrategy.GetWebCacheObj[cacheKey + "totalPageCount"] == null)
//{
#endregion
SqlParameter spTotalCount = new SqlParameter("@TotalCount", totalCount);
SqlParameter spTotalPageCount = new SqlParameter("@TotalPageCount", totalPageCount);
SqlParameter spRecorderCount = new SqlParameter("@RecorderCount",SqlDbType.Int);
spRecorderCount.Value = recorderCount;
spTotalCount.Direction = ParameterDirection.Output;
spTotalPageCount.Direction = ParameterDirection.Output;
//SqlParameter[] sps = new SqlParameter[] {
// new SqlParameter("@TableName",tableName),
// new SqlParameter("@FieldList",fieldList),
// new SqlParameter("@PrimaryKey",primaryKey),
// new SqlParameter("@Where",where),
// new SqlParameter("@Order",order),
// new SqlParameter("@SortType",sortType),
// new SqlParameter("@RecorderCount",recorderCount),
// new SqlParameter("@PageSize",pageSize),
// new SqlParameter("@PageIndex",pageIndex),
// spTotalCount,spTotalPageCount
// };
//ds = cncic.kmp.DataBase.helper.SQL.ExecuteDataset(connString, CommandType.StoredProcedure, "P_viewPage",sps);
#region myself
using (SqlConnection sqlconn = new SqlConnection(connString))
{
sqlconn.Open();
SqlCommand sqlcomm = new SqlCommand("P_viewPage", sqlconn);
sqlcomm.CommandType = CommandType.StoredProcedure;
sqlcomm.Parameters.Add(new SqlParameter("@TableName", tableName));
sqlcomm.Parameters.Add(new SqlParameter("@FieldList", fieldList));
sqlcomm.Parameters.Add(new SqlParameter("@PrimaryKey", primaryKey));
sqlcomm.Parameters.Add(new SqlParameter("@Where", where));
sqlcomm.Parameters.Add(new SqlParameter("@Order", order));
sqlcomm.Parameters.Add(new SqlParameter("@SortType", sortType));
sqlcomm.Parameters.Add(new SqlParameter("@PageSize", pageSize));
sqlcomm.Parameters.Add(new SqlParameter("@PageIndex", pageIndex));
sqlcomm.Parameters.Add(spRecorderCount);
sqlcomm.Parameters.Add(spTotalCount);
sqlcomm.Parameters.Add(spTotalPageCount);
SqlDataAdapter sdatmp = new SqlDataAdapter(sqlcomm);
sdatmp.Fill(ds);
}
#endregion
HttpContext.Current.Session["totalCount"] = spTotalCount.Value.ToString();
HttpContext.Current.Session["totalPageCount"] = spTotalPageCount.Value.ToString();
this._iRowCount = ds.Tables[0].Rows.Count;
HttpContext.Current.Session.Timeout = 30;
#region 2
// #region 加入缓存
// UtilsCheminfo.cacheCheminfo.AddObjectWith(cacheKey, ds);
// cncic.Cache.DefaultCacheStrategy.GetWebCacheObj[cacheKey + "totalCount"] = totalCount;
// cncic.Cache.DefaultCacheStrategy.GetWebCacheObj[cacheKey + "totalPageCount"] = totalPageCount;
// #endregion
//}
//else
//{
// #region 从缓存从取出数据
// ds = (DataSet)cncic.Cache.DefaultCacheStrategy.GetWebCacheObj[cacheKey];
// totalCount = int.Parse(cncic.Cache.DefaultCacheStrategy.GetWebCacheObj[cacheKey + "totalCount"].ToString());
// totalPageCount = int.Parse(cncic.Cache.DefaultCacheStrategy.GetWebCacheObj[cacheKey + "totalPageCount"].ToString());
// #endregion
//}
#endregion
}
catch (Exception ex)
{
throw ex;
}
}
else
{
ds.Tables.Add(dt);
}
#region 时间差
TimeSpan timeTaken = DateTime.Now - start;
HttpContext.Current.Session["timeTaken"] = timeTaken.TotalSeconds.ToString("#0.00");
#endregion
return ds;
}
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
public int RowAllCount(int maximumRows, int startRowIndex)
{
return _iRowCount;
}
}