Commit fe97d256 HZH

增加分页控件2

1 个父辈 c49b6bac
...@@ -48,5 +48,8 @@ namespace HZH_Controls.Controls ...@@ -48,5 +48,8 @@ namespace HZH_Controls.Controls
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
List<object> GetCurrentSource(); List<object> GetCurrentSource();
int PageCount { get; set; }
int PageIndex { get; set; }
} }
} }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace HZH_Controls.Controls.List
{
[ToolboxItem(true)]
public partial class UCPagerControl2 : UCPagerControlBase
{
public UCPagerControl2()
{
InitializeComponent();
txtPage.txtInput.KeyDown += txtInput_KeyDown;
}
void txtInput_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btnToPage_BtnClick(null, null);
txtPage.InputText = "";
}
}
public override event PageControlEventHandler ShowSourceChanged;
private List<object> m_dataSource;
public override List<object> DataSource
{
get
{
return m_dataSource;
}
set
{
m_dataSource = value;
if (m_dataSource == null)
m_dataSource = new List<object>();
ResetPageCount();
}
}
private int m_intPageSize = 0;
public override int PageSize
{
get
{
return m_intPageSize;
}
set
{
m_intPageSize = value;
ResetPageCount();
}
}
public override void FirstPage()
{
PageIndex = 1;
StartIndex = (PageIndex - 1) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
public override void PreviousPage()
{
PageIndex--;
StartIndex = (PageIndex - 1) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
public override void NextPage()
{
PageIndex++;
StartIndex = (PageIndex - 1) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
public override void EndPage()
{
PageIndex = PageCount;
StartIndex = (PageIndex - 1) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
private void ResetPageCount()
{
if (PageSize > 0)
{
PageCount = m_dataSource.Count / m_intPageSize + (m_dataSource.Count % m_intPageSize > 0 ? 1 : 0);
}
txtPage.MaxValue = PageCount;
txtPage.MinValue = 1;
ReloadPage();
}
private void ReloadPage()
{
try
{
ControlHelper.FreezeControl(tableLayoutPanel1, true);
List<int> lst = new List<int>();
if (PageCount > 0)
{
if (PageCount <= 7)
{
for (int i = 0; i < PageCount; i++)
{
lst.Add(i + 1);
}
}
else
{
int start = PageIndex; //开始按钮数字
int end = 1; //结束按钮数字
int pageCount = PageCount; //总页数
int offset = 3; //偏移量
start -= offset;//计算左偏移量
start = start < 1 ? 1 : start;//限定最小页码
end = start + 7 - 1;//根据偏移计算结束按钮
end = end > pageCount ? pageCount : end;//限定最大页码
start = end - 7 + 1;//根据偏移计算开始页码
start = start < 1 ? 1 : start;//限定最小页码
for (int i = start; i <= end; i++)
{
lst.Add(i);
}
}
}
for (int i = 0; i < 7; i++)
{
UCBtnExt c = (UCBtnExt)this.tableLayoutPanel1.Controls.Find("p" + (i + 1), false)[0];
if (i >= lst.Count)
{
c.Visible = false;
}
else
{
c.BtnText = lst[i].ToString();
c.Visible = true;
if (lst[i] == PageIndex)
{
c.RectColor = Color.FromArgb(255, 77, 59);
}
else
{
c.RectColor = Color.FromArgb(223, 223, 223);
}
}
}
}
finally
{
ControlHelper.FreezeControl(tableLayoutPanel1, false);
}
}
private void page_BtnClick(object sender, EventArgs e)
{
PageIndex = (sender as UCBtnExt).BtnText.ToInt();
StartIndex = (PageIndex - 1) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
protected override void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{
btnFirst.Enabled = btnPrevious.Enabled = blnLeftBtn;
btnNext.Enabled = btnEnd.Enabled = blnRightBtn;
}
private void btnFirst_BtnClick(object sender, EventArgs e)
{
FirstPage();
}
private void btnPrevious_BtnClick(object sender, EventArgs e)
{
PreviousPage();
}
private void btnNext_BtnClick(object sender, EventArgs e)
{
NextPage();
}
private void btnEnd_BtnClick(object sender, EventArgs e)
{
EndPage();
}
private void btnToPage_BtnClick(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtPage.InputText))
{
PageIndex = txtPage.InputText.ToInt();
StartIndex = (PageIndex - 1) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file \ No newline at end of file
...@@ -53,12 +53,28 @@ namespace HZH_Controls.Controls ...@@ -53,12 +53,28 @@ namespace HZH_Controls.Controls
#endregion #endregion
#endregion #endregion
/// <summary>
/// 总页数
/// </summary>
public virtual int PageCount
{
get;
set;
}
private int m_pageIndex = 1;
/// <summary>
/// 当前页码
/// </summary>
public virtual int PageIndex
{
get { return m_pageIndex; }
set { m_pageIndex = value; }
}
/// <summary> /// <summary>
/// 关联的数据源 /// 关联的数据源
/// </summary> /// </summary>
public virtual List<object> DataSource { get; set; } public virtual List<object> DataSource { get; set; }
public event PageControlEventHandler ShowSourceChanged; public virtual event PageControlEventHandler ShowSourceChanged;
private int m_pageSize = 1; private int m_pageSize = 1;
/// <summary> /// <summary>
/// 每页显示数量 /// 每页显示数量
...@@ -85,7 +101,6 @@ namespace HZH_Controls.Controls ...@@ -85,7 +101,6 @@ namespace HZH_Controls.Controls
} }
} }
public UCPagerControlBase() public UCPagerControlBase()
{ {
InitializeComponent(); InitializeComponent();
...@@ -230,7 +245,5 @@ namespace HZH_Controls.Controls ...@@ -230,7 +245,5 @@ namespace HZH_Controls.Controls
/// <param name="blnRightBtn">是否显示下一页,最后一页</param> /// <param name="blnRightBtn">是否显示下一页,最后一页</param>
protected virtual void ShowBtn(bool blnLeftBtn, bool blnRightBtn) protected virtual void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{ } { }
} }
} }
...@@ -66,6 +66,12 @@ ...@@ -66,6 +66,12 @@
<Compile Include="Controls\List\UCPagerControl.Designer.cs"> <Compile Include="Controls\List\UCPagerControl.Designer.cs">
<DependentUpon>UCPagerControl.cs</DependentUpon> <DependentUpon>UCPagerControl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\List\UCPagerControl2.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\List\UCPagerControl2.Designer.cs">
<DependentUpon>UCPagerControl2.cs</DependentUpon>
</Compile>
<Compile Include="Controls\Menu\IMenuItem.cs" /> <Compile Include="Controls\Menu\IMenuItem.cs" />
<Compile Include="Controls\Menu\MenuItemEntity.cs" /> <Compile Include="Controls\Menu\MenuItemEntity.cs" />
<Compile Include="Controls\Menu\UCMenu.cs"> <Compile Include="Controls\Menu\UCMenu.cs">
...@@ -369,6 +375,9 @@ ...@@ -369,6 +375,9 @@
<EmbeddedResource Include="Controls\List\UCPagerControl.resx"> <EmbeddedResource Include="Controls\List\UCPagerControl.resx">
<DependentUpon>UCPagerControl.cs</DependentUpon> <DependentUpon>UCPagerControl.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Controls\List\UCPagerControl2.resx">
<DependentUpon>UCPagerControl2.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\List\UCPagerControlBase.resx"> <EmbeddedResource Include="Controls\List\UCPagerControlBase.resx">
<DependentUpon>UCPagerControlBase.cs</DependentUpon> <DependentUpon>UCPagerControlBase.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
......
...@@ -89,6 +89,15 @@ namespace Test ...@@ -89,6 +89,15 @@ namespace Test
} }
this.ucMenu1.MenuStyle = MenuStyle.Top; this.ucMenu1.MenuStyle = MenuStyle.Top;
this.ucMenu1.DataSource = lstMenu; this.ucMenu1.DataSource = lstMenu;
List<object> lstPage2 = new List<object>();
for (int i = 0; i < 1000; i++)
{
lstPage2.Add(i);
}
ucPagerControl21.PageSize = 10;
ucPagerControl21.DataSource = lstPage2;
} }
private void timer1_Tick(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!