重写DEV的DateEdit控件的类只选择年月

摘要:
最新在做CRM的报表,查询条件只需要年月,DateEdit以及几个时间控件都用的不顺,强迫症犯了一怒之下起了重写DateEdit的想法新建一个类CXDateEditusingDevExpress.XtraEditors;usingDevExpress.XtraEditors.Calendar;usingDevExpress.XtraEditors.Controls;usingDevExpress.

最新在做CRM的报表,查询条件只需要年月,DateEdit 以及几个时间控件都用的不顺,强迫症犯了一怒之下起了重写DateEdit的想法

重写DEV的DateEdit控件的类只选择年月第1张

新建一个类

CXDateEdit

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Calendar;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Popup;
using DevExpress.XtraEditors.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MLTY.Business.Report
{
   public class CXDateEdit : DateEdit
    {
        public CXDateEdit()
        {
            Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True;
            Properties.DisplayFormat.FormatString = "yyyy-MM";
            Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            Properties.Mask.EditMask = "yyyy-MM";
            Properties.ShowToday = false;
        }
 
        protected override PopupBaseForm CreatePopupForm()
 
        {
 
            if (Properties.VistaDisplayMode == DevExpress.Utils.DefaultBoolean.True)
 
                return new CustomVistaPopupDateEditForm(this);
 
            return new PopupDateEditForm(this);
 
        }
 
        private DateResultModeEnum _dateMode = DateResultModeEnum.FirstDayOfMonth;
 
        public DateResultModeEnum DateMode
 
        {
 
            get { return _dateMode; }
 
            set { _dateMode = value; }
 
        }
 
 
 
        public enum DateResultModeEnum : int
 
        {
 
            //虽然是年月控件,但日期Datetime肯定是2012-01-01这种格式
 
            //所以,这个枚举定义了年月控件返回本月的第一天,还是本月的最后一天作为DateEditEx的值
 
            FirstDayOfMonth = 1,
 
            LastDayOfMonth = 2
 
        } 
 
 
 
    }
 
    public class CustomVistaPopupDateEditForm : VistaPopupDateEditForm
 
    {
 
        public CustomVistaPopupDateEditForm(DateEdit ownerEdit) : base(ownerEdit) { }
 
        protected override DateEditCalendar CreateCalendar()
 
        {
 
            return new CustomVistaDateEditCalendar(OwnerEdit.Properties, OwnerEdit.EditValue);
 
        }
 
    }
 
    public class CustomVistaDateEditCalendar : VistaDateEditCalendar
 
    {
 
        public CustomVistaDateEditCalendar(RepositoryItemDateEdit item, object editDate) : base(item, editDate) { }
 
 
 
        protected override void Init()
 
        {
 
            base.Init();
 
            this.View = DateEditCalendarViewType.YearInfo;
 
        }
 
        public CXDateEdit.DateResultModeEnum DateMode
 
        {
 
            get { return ((CXDateEdit)this.Properties.OwnerEdit).DateMode; }
 
        }
 
        protected override void OnItemClick(DevExpress.XtraEditors.Calendar.CalendarHitInfo hitInfo)
 
        {
 
            DayNumberCellInfo cell = hitInfo.HitObject as DayNumberCellInfo;
 
            if (View == DateEditCalendarViewType.YearInfo)
 
            {
 
                DateTime dt = new DateTime(DateTime.Year, cell.Date.Month, 1, 0, 0, 0);
 
                if (DateMode == CXDateEdit.DateResultModeEnum.FirstDayOfMonth)
 
                {
 
                    
 
                    OnDateTimeCommit(dt, false);
 
                }
 
                else
 
                {
 
                    DateTime tempDate = dt.AddMonths(1).AddDays(-1);
 
                    tempDate = new DateTime(tempDate.Year, tempDate.Month, tempDate.Day, 23, 59, 59);
 
                    OnDateTimeCommit(tempDate, false);
 
                }
 
            }
 
            else
 
                base.OnItemClick(hitInfo);
 
        }
 
    }
 
}

然后在窗体xxx上拖一个dateedit ,进入xxx.Designer.cs 将设计器代码 this.dateedit =new DevExpress.XtraEditors.DateEdit();

改成 重写的类重写DEV的DateEdit控件的类只选择年月第2张

原博地址:http://www.cnblogs.com/axing/p/3201066.html

免责声明:文章转载自《重写DEV的DateEdit控件的类只选择年月》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SpringCloud zuul 网关限流分析midway mysql egg-mysql 配置 基础操作 增删改查下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

react 简单搭建

1.新建一个文件夹 2.执行npm init 3.整理新建工程目录结构,包含必要文件index.html 和 index.js 4.安装react 、react-dom 5. 安装webpack(穿件webpack.config.js文件) npm install --save-dev webpack 6.安装Babel编译器(创建babel.confi...

转://Linux MultiPath多路径软件实施说明

Multipath的工作原理 当multipath启动的时候,它通过系统命令scsi_id -eg -s /block/sdX得到proc/partitions 里面所有块设备的 UUID(universally unique identify),然后把所有具有同一个UUID的块设备组成一个Group,在/dev/mapper 生产一个对应的单独的设备。当...

解析 Linux 中的 VFS 文件系统机制(根文件系统的由来)

http://os.51cto.com/art/200803/67283_4.htm ◆1. 摘要 本文阐述 Linux 中的文件系统部分,源代码来自基于 IA32 的 2.4.20 内核。总体上说 Linux 下的文件系统主要可分为三大块:一是上层的文件系统的系统调用,二是虚拟文件系统 VFS(Virtual Filesystem Switch),三是...

合并分支到master上

版权声明:如果觉的本文好的话,点个赞,您的鼓励是我最大的动力。 https://blog.csdn.net/boysky0015/article/details/78185879假如我们现在在dev分支上,可以用下面命令查看当前分支 git branch1刚开发完项目,执行了下列命令 git add .git commit -m ‘dev'git push...

sgdisk基本用法

简介 sgdisk是Linux下操作GPT分区的工具,就像fdisk是操作MBR分区的工具。关于GPT和MBR的区别请参考: http://www.anchor.com.au/blog/2012/10/the-difference-between-booting-mbr-and-gpt-with-grub/ 使用 新建分区 root@ceph1:~...

npm run dev时 一堆报错 (node:37693) Warning: Accessing nonexistent property 'chmod' of module exports inside circular dependency

(node:37693) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency(Use `node --trace-warnings ...` to show where the warning was created)(nod...