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. 在Eclipse下导入vlc-android并编译

    在Ubuntu14.04下载好了VLC的源代码后,VLC的Eclipseproject存放在"vlc-android"文件夹 root@dzt-VirtualBox:/home/d ...

  2. &lt;C++ 实现设计模式&gt; 观察者模式

    观察者模式,又称公布--订阅,mvc模式等. 通俗点讲,比方股票来说,非常多人关注一支股票,派一个人去观察股票的情况,一有变化(观察),就通知全部的预定这个消息的人. 而我们常见的mvc模式,v是指v ...

  3. JQ优化性能

    一.注意定义jQuery变量的时候添加var关键字这个不仅仅是jQuery,所有javascript开发过程中,都需要注意,请一定不要定义成如下:$loading = $('#loading'); / ...

  4. [ACM] POJ 2506 Tiling (递归,睑板)

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7487   Accepted: 3661 Descriptio ...

  5. C# 如何生成CHM帮助文件

    原文:C# 如何生成CHM帮助文件 前一段时间应公司要求,让我开发一个数据库字段信息CHM帮助文件生成软件.结果当时我就二了,这个东西我只用过,不知道咋做啊.没想到老大很随意说一句:"没事, ...

  6. C语言运算符表(优先级)

    http://www.is.pku.edu.cn/~qzy/c/operator.htm

  7. 牛腩公布系统--HTTP 错误 403.14 - Forbidden

    忘了是谁说的"至理名言",做牛腩公布系统,不怕出错误,就怕出跟牛老师不一样的错误!! 刚做就開始出现各种错误了,只是话说错误越多,收获越多.把每次困难都当做历练成长的机会.不多说, ...

  8. mysql的事物

    所谓的事物就是一组原子性的SQL语句,或者说是一个独立的工作单元. 1.事物拥有四大特征: ①原子性(atomicity):一个事物必须被分为一个不可分割的的最小单元,整个事物中的所有操作要么全部提交 ...

  9. MVC 用扩展方法执行自定义视图,替代 UIHint

    MVC 用扩展方法执行自定义视图,替代 UIHint 项目中用了 Bootstrap , 这样就不用写太多的CSS了,省去很多事情.但是这个业务系统需要输入的地方很多,每个表都有100多个字段,每个页 ...

  10. C#边边角角(一)

    前言 此篇为在学习C#基础时,熟悉C#的语法和高级特性的一些小的尝试和笔记,记录一下以供分享 集合初始化器 集合必须实现System.Collections.IEnumerable接口 集合必须包含A ...