public abstract partial class TListPager<TEntity, TRepository, TSqlStrConstruct> : UserControl
where TEntity:Yom.Extend.Entity.EntityBase
where TRepository : Yom.Extend.Repository.RepositoryBaseRepository<TEntity, TSqlStrConstruct>
where TSqlStrConstruct : Huawei.Data.SqlStrConstruct
{
protected TRepository repository = System.Activator.CreateInstance<TRepository>();
ToolTip toolTip;
TSqlStrConstruct sqlStrConstruct;
public TListPager()
{
InitializeComponent();
if (this.IsContextMenu)
{
this.lvList.ContextMenuStrip = this.cmsOperation;
}
this.wfpPager.PageSize = ;
this.wfpPager.PageChanged += new WinFormPager.PageChangeDelegate(
() =>
{
DataBind();
}
);
this.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvList.Dock = System.Windows.Forms.DockStyle.Top;
this.lvList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lvList.ItemMouseHover += new ListViewItemMouseHoverEventHandler((object o, ListViewItemMouseHoverEventArgs ea) => {
if (!string.IsNullOrEmpty(ea.Item.ToolTipText)) {
if (this.toolTip == null) {
this.toolTip = new ToolTip();
}
this.toolTip.SetToolTip(this.lvList, ea.Item.ToolTipText);
}
});
this.cSearcher = this.CSearcher;
if (this.cSearcher == null)
{
this.pSearchContainer.Visible = false;
this.lvList.Location = new Point(, );
//this.lvList.Height += this.pSearchContainer.Height;
}
else {
if (this.cSearcher.SearchAction == null)
{
this.cSearcher.SearchAction = (SearchArgs sa) =>
{
if (sa != null)
{
if (sa.Params != null)
{
this.SearchParams = sa.Params.ToArray();
}
string whereStr = sa.SearchStr.ToString();
if (!string.IsNullOrEmpty(whereStr))
{
if (string.IsNullOrEmpty(this.Where))
{
this.where = sa.SearchStr.ToString();
}
else
{
this.where = string.Format("{0} AND {1}", this.Where, sa.SearchStr.ToString());
}
} }
TListPager_Load(null, null);
};
}
this.cSearcher.Dock = DockStyle.Fill;
this.pSearchContainer.Height = this.cSearcher.Height;
this.pSearchContainer.Controls.Add(this.cSearcher);
this.lvList.Location = new Point(, this.pSearchContainer.Height);
this.lvList.Height = this.Height - this.cSearcher.Height - this.wfpPager.Height;
}
editor = this.Editor;
Init();
}
protected virtual void Init(){ }
protected TEditorBase<TEntity, TRepository, TSqlStrConstruct> editor;
protected abstract TEditorBase<TEntity, TRepository, TSqlStrConstruct> Editor
{
get;
}
protected void TListPager_Load(object sender, EventArgs e)
{
this.wfpPager.CurrentPage = ;
DataBind();
}
protected abstract string Order
{
get; }
protected bool IsContextMenu {
get {
return true;
}
}
protected string where;
protected abstract string Where
{
get;
}
protected virtual System.Data.IDataParameter[] SearchParams
{
get;
set;
}
protected abstract ColumnHeader[] Columns
{
get;
}
protected Type EntityType {
get {
return typeof(TEntity);
}
}
protected virtual bool EnabledPage
{
get {
return true;
}
}
public virtual void DataBind(int pageIndex) {
this.wfpPager.CurrentPage = pageIndex;
DataBind();
}
private void DataBind()
{
int count = ;
TEntity[] tes;
if (string.IsNullOrEmpty(this.where)) {
this.where = this.Where;
}
if (EnabledPage)
{
tes = this.repository.FindAll(this.wfpPager.CurrentPage, this.wfpPager.PageSize, this.where, string.IsNullOrEmpty(this.Order)?string.Empty:this.Order, SearchParams, out count) as TEntity[];
}
else {
tes = this.repository.FindAll(where, Order, this.SearchParams) as TEntity[];
}
this.lvList.Columns.Clear();
this.lvList.Items.Clear();
this.lvList.Columns.Add(new ColumnHeader(){ Text="序号",Width= }); this.lvList.Columns.AddRange(this.Columns);
this.lvList.ShowItemToolTips = true;
int baseNo = this.wfpPager.PageSize * (this.wfpPager.CurrentPage - );
string[] itemArr ;
object propertyValue;
int columnIndexRecord;
ListViewItem toAdditem;
foreach (TEntity te in tes)
{
itemArr = new string[this.Columns.Length + ];
itemArr[] = (++baseNo).ToString();
columnIndexRecord = ;
foreach (ColumnHeader ch in this.Columns) {
columnIndexRecord++;
if (string.IsNullOrEmpty(ch.Name)) {
continue;
}
try
{
propertyValue = EntityType.GetProperty(ch.Name).GetValue(te, null);
}
catch {
continue;
}
if (propertyValue is DateTime)
{
itemArr[columnIndexRecord] = DateTimeAction(ch.Name, (DateTime)propertyValue);
}
else
{
itemArr[columnIndexRecord] = propertyValue.ToString();
} } toAdditem = new ListViewItem(itemArr) { Name = EntityType.GetProperty(this.repository.GetEntityKeyName()).GetValue(te, null).ToString() };
if (!string.IsNullOrEmpty(this.ItemTooltipFiledName))
{
toAdditem.ToolTipText = EntityType.GetProperty(this.ItemTooltipFiledName).GetValue(te, null).ToString();
}
toAdditem.Tag = te;
ItemBeforeAdd(toAdditem); this.lvList.Items.Add(toAdditem); }
if (EnabledPage)
{
this.wfpPager.RecordCount = count;
if (this.wfpPager.PageTotal.Equals() || count <= )
{ this.wfpPager.Visible = false;
if (this.cSearcher == null)
{
this.lvList.Height = this.Height;
}
else
{
this.lvList.Height = this.Height - this.cSearcher.Height;
}
}
else {
this.wfpPager.Visible = true;
if (this.cSearcher == null)
{
this.lvList.Height = this.Height - this.wfpPager.Height;
}
else
{
this.lvList.Height = this.Height - this.cSearcher.Height -this.wfpPager.Height;
}
}
}
else {
this.wfpPager.Visible = false;
if (this.cSearcher == null)
{
this.lvList.Height = this.Height;
}
else
{
this.lvList.Height = this.Height - this.cSearcher.Height;
} }
}
protected virtual void ItemBeforeAdd(ListViewItem toAdditem)
{ }
protected virtual string ItemTooltipFiledName
{
get;
set;
} protected virtual string DateTimeAction(string propertyName,DateTime dt) {
try
{
if (dt.Equals(DateTime.MinValue)) {
return string.Empty;
}
return dt.ToString("yyyy-MM-dd HH:mm");
}
catch {
try
{
return dt.ToString();
}
catch
{
return string.Empty;
}
//return string.Empty;
}
} protected virtual void cmsOperation_Opening(object sender, CancelEventArgs e)
{
if (this.editor == null && this.cmsOperation.Items.Count.Equals()) {
this.cmsOperation.Items.RemoveAt();
this.cmsOperation.Items.RemoveAt();
this.cmsOperation.Items.RemoveAt();
}
if (this.cmsOperation.Items.Count.Equals())
{
if (this.lvList.SelectedItems.Count <= )
{
this.cmsOperation.Items[].Enabled = this.cmsOperation.Items[].Enabled = false;
}
else
{
this.cmsOperation.Items[].Enabled = this.cmsOperation.Items[].Enabled = true;
}
}
else {
if (this.lvList.SelectedItems.Count <= )
{
this.cmsOperation.Items[].Enabled = false;
}
else
{
this.cmsOperation.Items[].Enabled = true;
}
}
}
protected virtual bool DeleteValid(out string msg) {
msg = string.Empty;
return true;
}
protected virtual void cmsOperation_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
this.cmsOperation.Visible = false;
string key = e.ClickedItem.Tag == null ? e.ClickedItem.Text : e.ClickedItem.Tag.ToString();
switch (key)
{
case "添加":
//if (this.cmsOperation.Tag != null)
//{
// (this.cmsOperation.Tag as Button).PerformClick();
//}
//else
//{
// (this.Parent.Parent.Controls.Find("Edit", true)[0] as Button).PerformClick();
//}
editor = this.Editor;
if (this.editor == null) {
return;
} this.Hide();
this.Parent.Controls.Add(this.editor);
break;
case "编辑":
//Button b;;
//if (this.cmsOperation.Tag != null)
//{
// b = this.cmsOperation.Tag as Button;
//}
//else
//{
// b = (this.Parent.Parent.Controls.Find("Edit", true)[0] as Button);
//}
//b.Tag = this.lvList.FocusedItem.Name;
//b.PerformClick();
editor = this.Editor;
if (this.Editor == null)
{
return;
} if (this.lvList.SelectedItems.Count > ) {
MessageBox.Show("只能选择一项!");
return;
}
if (this.lvList.SelectedItems.Count < )
{
MessageBox.Show("至少选择一项!");
return;
}
this.Hide();
this.Parent.Controls.Add(this.editor);
this.editor.Key = this.lvList.SelectedItems[].Name;
break;
case "删除":
try
{
if (!Huawei.PortableComputer.Log.LogVar.UserName.Equals("admin"))
{
MessageBox.Show("只有超级管理员才有删除记录的权限。");
return;
}
}
catch { }
string msg;
if (!DeleteValid(out msg)) {
if (!string.IsNullOrEmpty(msg)) {
MessageBox.Show(msg);
return;
}
}
if (DialogResult.OK.Equals(MessageBox.Show("确定要删除吗?", "通知", MessageBoxButtons.OKCancel)))
{
TEntity entity;//= System.Activator.CreateInstance<TEntity>();
if (sqlStrConstruct == null)
{
sqlStrConstruct = System.Activator.CreateInstance<TSqlStrConstruct>();
}
foreach (ListViewItem item in this.lvList.SelectedItems)
{
//this.EntityType.GetProperty(this.repository.GetEntityKeyName()).SetValue(entity, item.Name, null);
entity = this.repository.FindBy(item.Name) as TEntity;
this.repository.Delete(entity);
if (sqlStrConstruct.TableName.Equals("TB_SYS_LOG"))
{
continue;
}
Log.LogWriter.Write(string.Format("删除了信息,表为{0},主键为:{1}", sqlStrConstruct.TableName, item.Name));
}
TListPager_Load(sender, e);
}
break;
}
}
CSearcher cSearcher;
protected abstract CSearcher CSearcher
{
get;
}
}

【NET】Winform用户控件的初步封装之列表页控件的更多相关文章

  1. 【NET】Winform用户控件的初步封装之编辑控件

    编辑控件 public abstract partial class TEditorBase <TEntity, TRepository, TSqlStrConstruct> : User ...

  2. VS2010/MFC编程入门之二十四(常用控件:列表框控件ListBox)

    前面两节讲了比较常用的按钮控件,并通过按钮控件实例说明了具体用法.本文要讲的是列表框控件(ListBox)及其使用实例. 列表框控件简介 列表框给出了一个选项清单,允许用户从中进行单项或多项选择,被选 ...

  3. VS2010-MFC(常用控件:列表框控件ListBox)

    转自:http://www.jizhuomi.com/software/186.html 列表框控件简介 列表框给出了一个选项清单,允许用户从中进行单项或多项选择,被选中的项会高亮显示.列表框可分为单 ...

  4. MFC常用控件之列表视图控件(List Control)

    近期学习了鸡啄米大神的博客,对其中的一些知识点做了一些自己的总结.不过,博客内容大部分来自鸡啄米.因此,这个博客算是转载博客,只是加了一些我自己的理解而已.若想学习鸡啄米大神的博客总结,请点击连接:h ...

  5. winform用户控件

    用途用户控件包含Time控件和一个lable控件,一个ToolStrip控件,每隔一秒显示一次时间     1. 生成用户控件   新建一个项目类型为用户控件   注意定义类名,此类名为以后工具箱中显 ...

  6. WinForm用户控件、动态创建添加控件、timer控件--2016年12月12日

    好文要顶 关注我 收藏该文 徐淳 关注 - 1 粉丝 - 3       0 0     用户控件: 通过布局将多个控件整合为一个控件,根据自己的需要进行修改,可对用户控件内的所有控件及控件属性进行修 ...

  7. winform用户控件、动态创建添加控件、timer控件、控件联动

    用户控件: 相当于自定义的一个panel 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...

  8. FileUpload控件使用初步

    FileUpload控件使用初步   FileUpload控件使用初步: 1.实现文件上传 protected void btnSubmit_click(object sender, EventArg ...

  9. Winform开发中如何将数据库字段绑定到ComboBox控件

    最近开始自己动手写一个财务分析软件,由于自己也是刚学.Net不久,所以自己写的的时候遇到了很多问题,希望通过博客把一些印象深刻的问题记录下来. Winform开发中如何将数据库字段绑定到ComboBo ...

随机推荐

  1. android 编译共享ccache的缓存

    1. android自带的ccache版本号(2.4版本号)过低,是无法支持以上的功能的,须要使用新版ccache. 2. 最新的ccache请到http://ccache.samba.org/dow ...

  2. [CLR via C#]1.4 执行程序集的代码

    原文:[CLR via C#]1.4 执行程序集的代码 1. 托管程序集同时包含元数据和IL.IL是与CPU无关的机器语言.可将IL是为一种面向对象的机器语言. 2. IL也是能使用汇编语言来写的,M ...

  3. CSS3 制作向左、向右及关闭图标的效果

    先看一下效果 1.鼠标移入前的效果 2.鼠标移入的效果 3.制作步骤如下: 轮廓的CSS,就是利用圆角和宽度高度,制作出一个圆: <style> /*显示方式为 inline-block* ...

  4. UI 收集

    semantic http://www.semantic-ui.com.cn/modules/reveal.html sbadmin http://startbootstrap.com/templat ...

  5. SEO 优化,网站推广优化教程100条(SEO,网站关键字优化,怎么优化网站,如何优化网站关键字)

    这篇文章不错.  http://www.cnblogs.com/zangdalei/archive/2010/08/31/1814047.html 看了一半之后的,觉得不太靠谱,很多都不懂. 于是 找 ...

  6. Redis MSET的极限在哪里

    ·背景 Redis以"快.准.狠"而著称,除了其主-从模式略失光彩(主从模式更多是被以讹传讹,3.0依旧在测试中),大部分的应用可谓尖兵利器.在一些常规写的时候,MSET和HMSE ...

  7. 在SQL Server中对视图进行增删改

    原文:在SQL Server中对视图进行增删改 Lesktop开源IM发布以后,有一些网友问及如何在嵌入IM后与自己网站的用户系统整合(即如何让嵌入的IM直接使用网站原有的用户数据库,而不需要将已有的 ...

  8. Ubuntu 14.04 关机键无效解决方法

         这几天開始研究ubuntu 14.04软件,安装Cairo-Dock后发现右上角的关机.重新启动.注销菜单点击都没了反应仅仅能通过命令实现,后来经过研究,发现仅仅要设置了 Cairo-Doc ...

  9. C语言库函数大全及应用实例十四

    原文:C语言库函数大全及应用实例十四                                       [编程资料]C语言库函数大全及应用实例十四 函数名: strset 功 能: 将一个串 ...

  10. NM常用网络命令

    Ipconfig命令 Ipconfig命令可以被用来显示机器当前TCP/IP配置信息. 当使用Ipconfig时不带不论什么參数选项,那么它为每一个已经配置好的接口显示IP地址.子网掩码和默认网关值. ...