Dev Express SchedulerControl 实现自定义排期

实现效果图:

整理下需要实现的目标:

1.三种颜色:当前时间之前 灰色; 当天 淡蓝色;当前时间之后,淡绿色,日期格式重写

2.appointment左对齐

3.右键appointment 弹出自定义菜单

4.鼠标移到appointment上,自定义Tooltip

5.禁用双击appointment弹出默认appointment界面,且appointment无法编辑,拖拽

代码

//1.禁用双击appointment弹出默认appointment界面,且appointment无法编辑,拖拽

this.OptionsCustomization.AllowAppointmentCreate = DevExpress.XtraScheduler.UsedAppointmentType.None;
this.OptionsCustomization.AllowAppointmentDelete = DevExpress.XtraScheduler.UsedAppointmentType.None;
this.OptionsCustomization.AllowAppointmentEdit = DevExpress.XtraScheduler.UsedAppointmentType.None;
this.OptionsCustomization.AllowAppointmentDrag = DevExpress.XtraScheduler.UsedAppointmentType.None;
this.OptionsCustomization.AllowAppointmentMultiSelect = false;
this.OptionsRangeControl.AllowChangeActiveView = false;
this.Views.MonthView.CompressWeekend = false;
this.OptionsBehavior.ShowRemindersForm = false;

//2.右键菜单--自定义

private void scheduleControl_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{

DXMenuItem item= new DXMenuItem("菜单项");;
if (scheduleControl.ActiveViewType == SchedulerViewType.Day)//不同view展示不同菜单项
{
}
if (e.Menu.Id == SchedulerMenuItemId.DefaultMenu)//右键空白处
{
e.Menu.Items.Clear();

}
e.Menu.Items.Add(item);

}
if (e.Menu.Id == SchedulerMenuItemId.AppointmentMenu)//appointment 上右键
{
e.Menu.Items.Clear();
e.Menu.Items.Add(item);
}
}

//3.自定义Tooltip

ToolTipController toolTipController1=new ToolTipController ();

this.toolTipController1.AllowHtmlText = true;
this.toolTipController1.ShowBeak = true;
this.toolTipController1.BeforeShow += new DevExpress.Utils.ToolTipControllerBeforeShowEventHandler(this.toolTipController1_BeforeShow);

this.scheduleControl.ToolTipController = this.toolTipController1;//与schedule绑定

private void toolTipController1_BeforeShow(object sender, DevExpress.Utils.ToolTipControllerShowEventArgs e)
{
ToolTipController controller = sender as ToolTipController;
AppointmentViewInfo aptViewInfo = controller.ActiveObject as AppointmentViewInfo;
if (aptViewInfo == null) return;

e.IconType = ToolTipIconType.Information;
e.Title = e.ToolTip;
e.ToolTip = “自定义tip内容” ;
}

//4.Appointment颜色设置

private void scheduleControl_AppointmentViewInfoCustomizing(object sender, AppointmentViewInfoCustomizingEventArgs e)
{
DevExpress.XtraScheduler.Drawing.AppointmentViewInfo viewInfo = e.ViewInfo as DevExpress.XtraScheduler.Drawing.AppointmentViewInfo;
TeamAppointment app = viewInfo.Appointment as TeamAppointment;
if (app == null)
return;

Brush backbr =GetBrush(viewInfo.Interval.Start,datetime.Now());//自定义颜色
Color forecolor = viewInfo.Appearance.ForeColor;

viewInfo.Appearance.BackColor = ((System.Drawing.SolidBrush)(backbr)).Color;//背景色
viewInfo.Appearance.BackColor2 = ((System.Drawing.SolidBrush)(backbr)).Color;
viewInfo.Appearance.ForeColor = forecolor;//前景色
viewInfo.Appearance.TextOptions.HAlignment = HorzAlignment.Near;//左对齐
viewInfo.Appearance.Options.UseBackColor = true;
viewInfo.Appearance.Options.UseForeColor = true;
viewInfo.Appearance.Options.UseTextOptions = true;
}

//5.重绘appointment内容

private void scheduleControl_CustomDrawAppointment(object sender, CustomDrawObjectEventArgs e)
{
try
{
if (e.ObjectInfo.GetType() != typeof(DevExpress.XtraScheduler.Drawing.AppointmentViewInfo) && e.ObjectInfo.GetType() != typeof(DevExpress.XtraScheduler.Drawing.HorizontalAppointmentViewInfo))
return;
DevExpress.XtraScheduler.Drawing.AppointmentViewInfo viewInfo = e.ObjectInfo as DevExpress.XtraScheduler.Drawing.AppointmentViewInfo;
TeamAppointment app = viewInfo.Appointment as TeamAppointment;
if (app == null)
return;

e.Cache.DrawString(Truncate(viewInfo.Appointment, viewInfo.Appearance.Font, viewInfo.Bounds.Width), viewInfo.Appearance.Font, new SolidBrush(viewInfo.Appearance.ForeColor), viewInfo.Bounds, viewInfo.Appearance.TextOptions.GetStringFormat());//超出部分,做处理
e.Handled = true;//不会执行默认操作
}
catch (Exception ex)
{
throw ex;
}
}

//重绘Header部分

private void scheduleControl_CustomDrawDayHeader(object sender, CustomDrawObjectEventArgs e)
{
try
{
if (e.ObjectInfo.GetType() != typeof(DevExpress.XtraScheduler.Drawing.MonthViewTimeCellHeader))
return;
DevExpress.XtraScheduler.Drawing.MonthViewTimeCellHeader header = (DevExpress.XtraScheduler.Drawing.MonthViewTimeCellHeader)e.ObjectInfo;
SelectableIntervalViewInfo viewInfo = e.ObjectInfo as SelectableIntervalViewInfo;

Brush br = QueryHelper.GetBrush(header.Interval.Start, currentYerestday);
if (viewInfo.Selected)
{
br = selectedColor;//设置被选中时颜色
}
e.Cache.FillRectangle(br, new Rectangle(e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 1));//填充header部分
StringFormat sf = header.Appearance.HeaderCaption.TextOptions.GetStringFormat(TextOptions.DefaultOptionsCenteredWithEllipsis);
e.Cache.DrawString(header.Interval.Start.ToString("MM月dd日"), scheduleControl.MonthView.Appearance.HeaderCaption.Font, Brushes.Black, e.Bounds, sf);//自定义日期格式
e.Handled = true; 
}
catch (Exception ex)
{
throw ex;
}
}

private void scheduleControl_CustomDrawTimeCell(object sender, CustomDrawObjectEventArgs e)
{
try
{
if (e.ObjectInfo.GetType() != typeof(DevExpress.XtraScheduler.Drawing.MonthSingleWeekCell))
return;
DevExpress.XtraScheduler.Drawing.MonthSingleWeekCell cell = ((DevExpress.XtraScheduler.Drawing.MonthSingleWeekCell)(e.ObjectInfo));

SelectableIntervalViewInfo selcell = e.ObjectInfo as SelectableIntervalViewInfo;
Brush br = QueryHelper.GetBrush(cell.Interval.Start,currentYerestday);
if (selcell.Selected)
{
 br =selectedColor;
}
e.Cache.FillRectangle(br, new Rectangle(e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 1));//填充图示2部分
e.Handled = true;
}
catch (Exception ex)
{
throw ex;
}
}

//自定义颜色

public static Brush GetBrush(DateTime inDate, DateTime currentYerestday)
{
Brush result = null;
if (inDate <= currentYerestday)
{
result = Brushes.LightGray;
}
else if (inDate > currentYerestday && inDate < currentYerestday.AddHours(24))
{
result = Brushes.LightBlue;
}
else
{
result = Brushes.LightGreen;
}

return result;

}

时间: 2024-10-08 20:50:22

Dev Express SchedulerControl 实现自定义排期的相关文章

Dev Express Report 学习总结(一) 基础知识总结

Dev Express,一个非常优秀的报表控件.像其他报表一样,该报表也包括几个主要部分:Report Header,Page Header,Group Header,Detail,Group Footer,Page Footer和Report Footer共7个部分.,除此之外,我们还可以添加Detail Report,并同时添加与此相对应的Report Header/Footer.借助此功能可以实现多个Heaer与多个Detail相互交叉的效果! 一. 常见总结 CalculatedFile

Dev Express 安装

Dev Express 安装 点击DevExpressUniversalTrialComplete-20151209.exe开始安装 选择需要安装的产品 选择需要安装的产品目录,这里设置为D盘 开始安装  等待安装完成,约为5分钟左右 完成提示帮助页面  安装完DevExpress程序后开始破解过程.双击[DevExpress.Patch 7.0-by dimaster]的程序包,弹出[DevExpress.Patch by dimaster]的窗体,直接点击[Apply patch]按钮就开始

app 耗电优化之三 使用JobSchedule对任务进行合理排期

JobSchedule 是Android5.0之后添加进去的,之前的版本没有.JobSchedule 原理是一种将任务安排在恰当的实际进行操作一种方案机制.具体提供了那些可选的时机,如下:1 在可用网络下执行.在7.0 之前,应用可以通过监听网络变化来执行任务,当然了前提是应用必须存活.到7.0之后这类API已经失效,但是JobSchedule机制提供了网络变化的监听.进一步可以在网络变化的情况下执行某些操作.例如在wifi环境下执行下载任务等.2 设备在充电或者空闲时执行一些任务.3 设定执行

项目经理排期的几个tip

互联网敏捷开发的流程可以演绎出很多玩法,但最好都遵循以下几个tip: 1, 对项目经理最重要的一条是,通读所有需求文档,跟相关PM进行彻底沟通,把需求都搞熟搞透,防止漏排任务: 2, Stroy拆分要细,每个任务都是可单独验收的: 3, 一个Stroy的排期最长不要超过三天,不然无法及时验收,会存在风险:如果Stroy很大,则继续往下拆,拆成最多三天的多个Stroy: 4, 与其他team的排期要咬合,比如第一天是server和UI,第二天的客户端,第三天是QA,要遵循这个顺序并且仅仅咬住: 5

DEV Express

记录在使用DEV Express中遇到的所有问题及解决方案 问题1:将Dev11升级到Dev14 解决方案:将解决方案中原有Dev引用删除,重新添加必须的Dev14引用,问题解决: 问题2:LC.exe已退出,代码-1 原因:在升级dev组件时,产生的错误,组件错误 解决方案:删除properties文件夹下的License文件,重新生成,问题解决:

Dev Express之ImageComboBoxEdit,RepositoryItemImageComboBox使用方式

 Dev Express之ImageComboBoxEdit,RepositoryItemImageComboBox使用方式 1.使用ImageComboBoxEdit实现下拉框键值数据函数 public static void InitCmb(ImageComboBoxEdit cmb, DataTable source, string value, string text, bool isDefaultNull) { ImageComboBoxItem[] items = new Image

不加班的项目从排期开始

什么是合理的开发排期?我个人以为合理的开发排期是一个项目不延期,少加班的时间管理. 在目前接触的各种项目开发中,开始时觉得时间很充足,但是后面做着做着,就变成苦逼开发加班加点赶工期,甚至项目延期.不仅仅是毕业两三年的同学,甚至有工作近十年的老司机,也会经常遇到这种情况.出现这种情况大家很自然的想到是因为项目过程中各种不确定的事情发生,导致原本预感足够的时间变得紧张起来.所以在项目进行的前期,作为开发需要给自己定一个合理的开发排期. 那么如何来做一个合理的开发排期? 一.梳理时间分布 作为主要工作

需求排期的深坑

为什么要有排期? 需求被计划以后, 需要产出合理的排期.其实个人也不喜欢排期这回事情,需求做就行了,要啥排期?要! 排期是对工作量的评估,是对资源的消耗的评估--相关人员.场地.时间都是资源.乃至个人项目,自娱自乐的需求,个人的时间不也是一种资源吗? 需求设计需要考虑排期.需求阶段就应该开始考虑排期,这样能有完整的思考脉络,需求设计方在设计的时候同事考虑排期,这样也没有人员切换和交流导致的损耗. 排期是项目管理的重要一部分.项目管理的时候,往往排期和延期比对,是一个项目施工进度的很好的参照物,也

Dev Express Report 学习总结(六)Dev Express Reports自定义Summary

在我们使用DevExpress开发报表的过程中,对于页面中复杂的数据合计,我们可能会使用到自定义Summary.下面通过一个例子来进行说明: 首先,我建立了如上图所示的报表页面,其中的数据源来自class列表,其中处的lbST使用了对当前Group的Sum,处的XRLabel控件使用了对整个Report的Sum.为了测试的方便,该例子使用汇总lbCP的值与位于Group列表中lbST的值来进行演示,其中,GroupField为MedinineName,lbGrandTotal为总计.具体操作如下