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. 【百度地图API】如何给自定义覆盖物添加事件

    原文:[百度地图API]如何给自定义覆盖物添加事件 摘要: 给marker.lable.circle等Overlay添加事件很简单,直接addEventListener即可.那么,自定义覆盖物的事件应 ...

  2. NEFUOJ 500 二分法+最大流量

    http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=500 description 在这个信息化的时代.网购成为了最流行的购物方 ...

  3. GitBook配置

    GitBook 是一个通过 Git 和 Markdown 来撰写书籍的工具.生成格式有:JSON.ePub.PDF.Website ! ================================ ...

  4. OracleServiceORCL服务不见了怎么办

    用管理员身份运行命令提示符(CMD) 然后输入“oradim -new -sid orcl”即可

  5. 高性能双端js模板---simplite

    simplite是一款js实现的模板引擎,它能够完成浏览器端js模版和node服务器端js模板的数据渲染,渲染性能达到引擎的极限. 渲染性能十分突出. 支持浏览器端和node服务器端模板渲染. 它简单 ...

  6. .NET:从 Mono、.NET Core 说起

    魅力 .NET:从 Mono..NET Core 说起 前段时间,被问了这样一个问题:.NET 应用程序是怎么运行的? 当时大概愣了好久,好像也没说出个所以然,得到的回复是:这是 .NET 程序员最基 ...

  7. JVM监控概述(图文)

    JVM内存分配概述 Jvm 内存分为:堆.非堆及直接内存三大块. 堆区分为年轻代和老年代,永生代属于非堆内存. 对象优先在Eden区分配 大对象直接进入老年代 长期存活的对象将进入老年代 class. ...

  8. WP 开发中.xaml 与.xaml.cs

    关于 WP 开发中.xaml 与.xaml.cs 的关系   今天我们先来看一下在WP8.1开发中最长见到的几个文件之间的关系.比较论证,在看这个问题之前我们简单看看.NET平台其他两个不同的框架: ...

  9. ubuntu安装nVidia驱动,遇到终端闪砾问题并解决

    安装nvidia的官方驱动之后,比起nouvean来说感觉速度快了不少. 安装该驱动很简单,但选择哪个驱动是要注意的.因为今天我试了nvidia的多个驱动后都在ubuntu下用起来并不好. 我现在的环 ...

  10. 经典的SQL语句面试题

    Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...