/// <summary>
/// 根据sql语句获取news收集
/// </summary>
/// <param name="sql">注意:这里sql语句只能选择主键一个字段。 如: select ExpoID from CMS_Expo</param>
/// <param name="pageIndex">当前页码</param>
/// <param name="pageSize">每页显示的条数</param>
/// <param name="includePageIndex">是否包含分页信息</param>
/// <param name="returnFullThread">是否分页</param>
/// <returns>CMS_Expo的集合</returns>
public override CMS_ExpoCollection GetCMS_ExpoSet(string sql, int pageIndex, int pageSize, bool includePageIndex, bool returnFullThread)
{
using (SqlConnection myConnection = new SqlConnection(this.connectionString))
{
using (SqlCommand command = new SqlCommand("dbo.[RS_Get_CMS_ExpoSet]", myConnection))
{
command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@PageIndex", SqlDbType.Int, 4).Value = pageIndex;
command.Parameters.Add("@PageSize", SqlDbType.Int, 4).Value = pageSize;
command.Parameters.Add("@sqlPopulate", SqlDbType.NText).Value = sql;
command.Parameters.Add("@IncludePageIndex", SqlDbType.Bit).Value = includePageIndex;
command.Parameters.Add("@ReturnFullThread", SqlDbType.Bit).Value = returnFullThread;
command.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction = ParameterDirection.Output; CMS_ExpoCollection cms_expoSet = new CMS_ExpoCollection(); // Execute the command
myConnection.Open();
using (SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read())
{
cms_expoSet.Add(PopulateCMS_ExpoEntryFromIDataReader(dr));
} if (includePageIndex)
{
dr.NextResult();
while (dr.Read())
cms_expoSet.PageIndex.Add(dr[0], dr[1]);
} dr.Close();
myConnection.Close();
cms_expoSet.TotalRecords = (int)command.Parameters["@TotalRecords"].Value;
} return cms_expoSet;
}
}
}public override CMS_ExpoCollection GetCMS_ExpoSet 这种事如何定义的呢? 做项目是 只知道调整,到不知道这个是如何定义做的?哪位高手能做个简单例子说明一下 谢谢。
/// 根据sql语句获取news收集
/// </summary>
/// <param name="sql">注意:这里sql语句只能选择主键一个字段。 如: select ExpoID from CMS_Expo</param>
/// <param name="pageIndex">当前页码</param>
/// <param name="pageSize">每页显示的条数</param>
/// <param name="includePageIndex">是否包含分页信息</param>
/// <param name="returnFullThread">是否分页</param>
/// <returns>CMS_Expo的集合</returns>
public override CMS_ExpoCollection GetCMS_ExpoSet(string sql, int pageIndex, int pageSize, bool includePageIndex, bool returnFullThread)
{
using (SqlConnection myConnection = new SqlConnection(this.connectionString))
{
using (SqlCommand command = new SqlCommand("dbo.[RS_Get_CMS_ExpoSet]", myConnection))
{
command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@PageIndex", SqlDbType.Int, 4).Value = pageIndex;
command.Parameters.Add("@PageSize", SqlDbType.Int, 4).Value = pageSize;
command.Parameters.Add("@sqlPopulate", SqlDbType.NText).Value = sql;
command.Parameters.Add("@IncludePageIndex", SqlDbType.Bit).Value = includePageIndex;
command.Parameters.Add("@ReturnFullThread", SqlDbType.Bit).Value = returnFullThread;
command.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction = ParameterDirection.Output; CMS_ExpoCollection cms_expoSet = new CMS_ExpoCollection(); // Execute the command
myConnection.Open();
using (SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read())
{
cms_expoSet.Add(PopulateCMS_ExpoEntryFromIDataReader(dr));
} if (includePageIndex)
{
dr.NextResult();
while (dr.Read())
cms_expoSet.PageIndex.Add(dr[0], dr[1]);
} dr.Close();
myConnection.Close();
cms_expoSet.TotalRecords = (int)command.Parameters["@TotalRecords"].Value;
} return cms_expoSet;
}
}
}public override CMS_ExpoCollection GetCMS_ExpoSet 这种事如何定义的呢? 做项目是 只知道调整,到不知道这个是如何定义做的?哪位高手能做个简单例子说明一下 谢谢。
/// <summary>
/// CMS_ExpoCollection 的摘要说明。
/// </summary>
public class CMS_ExpoCollection : CollectionBase
{
public CMS_ExpoCollection()
{
//
// TODO: 在此处添加构造函数逻辑
//
} SortedList pageIndex = new SortedList();
int totalRecords = 0; //CMS_Expo的数目 public int TotalRecords
{
get
{
return totalRecords;
}
set
{
totalRecords = value;
}
} public bool HasResults
{
get
{
if (this.Count > 0)
return true;
return false;
}
} public SortedList PageIndex
{
get
{
return pageIndex;
}
set
{
pageIndex = value;
}
} public CMS_Expo this[int index]
{
get { return ((CMS_Expo)List[index]); }
set { List[index] = value; }
} public int Add(CMS_Expo value)
{
return (List.Add(value));
} public int IndexOf(CMS_Expo value)
{
return (List.IndexOf(value));
} public void Insert(int index, CMS_Expo value)
{
List.Insert(index, value);
} public void Remove(CMS_Expo value)
{
List.Remove(value);
} public bool Contains(CMS_Expo value)
{
// If value is not of type Int16, this will return false.
return (List.Contains(value));
} protected override void OnInsert(int index, Object value)
{
if (value.GetType() != Type.GetType("Fastener.Component.CMS_Expo"))
throw new ArgumentException("value must be of type Fastener.Component.CMS_Expo.", "value");
} protected override void OnRemove(int index, Object value)
{
if (value.GetType() != Type.GetType("Fastener.Component.CMS_Expo"))
throw new ArgumentException("value must be of type Fastener.Component.CMS_Expo.", "value");
} protected override void OnSet(int index, Object oldValue, Object newValue)
{
if (newValue.GetType() != Type.GetType("Fastener.Component.CMS_Expo"))
throw new ArgumentException("newValue must be of type Fastener.Component.CMS_Expo.", "newValue");
} protected override void OnValidate(Object value)
{
if (value.GetType() != Type.GetType("Fastener.Component.CMS_Expo"))
throw new ArgumentException("value must be of type Fastener.Component.CMS_Expo.");
}
}
{
public class PersonCollection : CollectionBase
{
public int Add(Person value)
{
return this.List.Add(value);
} public bool Contains(Person value)
{
return this.List.Contains(value);
} public int IndexOf(Person value)
{
return this.List.IndexOf(value);
} public void Insert(int index, Person value)
{
List.Insert(index, value);
} public void Remove(Person value)
{
List.Remove(value);
}
}}namespace Happy
{
public class Element
{
public int Number = 10;
}
public class Person
{
public string _Name = "";
public string _Sex = "";
public string _xuexiao = "";
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public string Sex
{
get { return _Sex; }
set { _Sex = value; }
}
public string xuexiao
{
get { return _xuexiao; }
set { _xuexiao = value; }
}
public Person(){}
public Person(string strname,string sex,string xuexiao)
{
this._Name = strname;
this._Sex = sex;
this._xuexiao = xuexiao;
}
}
public class Test
{
public static Element Change(Element s)
{
Element r = new Element();
r.Number = 100;
return r;
}
public ArrayList alist()
{ Person p = new Person();
p.Name = "廖hongchu";
p.Sex = "男";
p.xuexiao = "梧州学院";
Person p2 = new Person("诸葛亮","男","奇才学校");
ArrayList toReturn = new ArrayList();
toReturn.Add(p);
toReturn.Add(p2);
return toReturn;
}
public PersonCollection PersonSet()
{
Person p3 = new Person("曹操", "男", "奇才学校");
Person p4 = new Person("周瑜", "男", "江东学校");
PersonCollection personset = new PersonCollection();
personset.Add(p3);
personset.Add(p4);
return personset;
}
}
}public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Happy.Element ey = new Happy.Element();
Response.Write(ey.Number + "<br/> ");
//Test.Change(ey);
//Response.Write(ey.Number);
Happy.Element eyTest = Test.Change(ey);
Response.Write(eyTest.Number);
arraylist();
}
protected void arraylist()
{
Test test = new Test();
ArrayList alis = test.alist();
foreach (Person st in alis)
{
Label1.Text += st.Name + " " + st.Sex + " " + st.xuexiao+"<br>";
}
PersonCollection personcoll=test.PersonSet(); foreach (Person p in personcoll)
{
Label2.Text += p.Name + " " + p.Sex + " " + p.xuexiao + "<br>";
}
}
}自己弄了个 了解了 一点。