Dev 甘特图
Posted 陈-chen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dev 甘特图相关的知识,希望对你有一定的参考价值。
date1.EditValue = DateTime.Now.Date.AddDays(0).AddHours(0).AddMinutes(0).AddSeconds(0); scLd1.PopupMenuShowing += schedulerControl1_PopupMenuShowing; scLd1.EditAppointmentFormShowing += schedulerControl1_EditAppointmentFormShowing; ///增加额外字段 如备注 AppointmentCustomFieldMappingCollection appointCust = schedulerStorage1.Appointments.CustomFieldMappings; appointCust.Add(new AppointmentCustomFieldMapping("Note", "Note")); scLd1.GanttView.ResourcesPerPage = 6; //设置资源个数 scLd1.InitAppointmentDisplayText += scLd1_InitAppointmentDisplayText; //自定义显示提示 SetToolTipControl(scLd1); SetLabeColor(scLd1.Storage); InitGrantView(scLd1); } /// <summary> /// 设置提示 /// </summary> /// <param name="sc"></param> private void SetToolTipControl(DevExpress.XtraScheduler.SchedulerControl sc) { ToolTipController toolTipController1 = new ToolTipController(); toolTipController1.AllowhtmlText = true; toolTipController1.BeforeShow += toolTipController1_BeforeShow; sc.ToolTipController = toolTipController1; } /// <summary> /// 设置Appointment颜色 /// </summary> /// <param name="ss"></param> private void SetLabeColor(DevExpress.XtraScheduler.SchedulerStorage ss) { ///设置块的颜色 ss.Appointments.Labels.Clear(); ss.Appointments.Labels.Add(new DevExpress.XtraScheduler.AppointmentLabel(Color.Yellow, "生产中")); ss.Appointments.Labels.Add(new DevExpress.XtraScheduler.AppointmentLabel(Color.LightBlue, "生产完成")); ss.Appointments.Labels.Add(new DevExpress.XtraScheduler.AppointmentLabel(Color.Red, "回炉")); ss.Appointments.Labels.Add(new DevExpress.XtraScheduler.AppointmentLabel(Color.Maroon, "其它")); } /// <summary> /// 初始化设置 /// </summary> /// <param name="sc"></param> private void InitGrantView(DevExpress.XtraScheduler.SchedulerControl sc) { //设置资源 sc.GroupType = SchedulerGroupType.Resource; //设置甘特图 sc.ActiveViewType = SchedulerViewType.Gantt; //设置资源+-按钮不可见 sc.ResourceNavigator.Visibility = ResourceNavigatorVisibility.Auto; //设置Resource 字体不旋转 sc.OptionsView.ResourceHeaders.RotateCaption = false; sc.OptionsView.ResourceHeaders.Height = 60; sc.OptionsView.ShowOnlyResourceAppointments = true; //行为设置 sc.OptionsBehavior.MouseWheelScrollAction = MouseWheelScrollAction.Auto; sc.OptionsBehavior.RecurrentAppointmentDeleteAction = RecurrentAppointmentAction.Cancel; sc.OptionsBehavior.RecurrentAppointmentEditAction = RecurrentAppointmentAction.Cancel; sc.OptionsBehavior.RemindersFormDefaultAction = RemindersFormDefaultAction.DismissAll; //自定义动作设置 //禁止块冲突 sc.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Allowed; //不允许复制 sc.OptionsCustomization.AllowAppointmentCopy = UsedAppointmentType.None; //不允许创建 sc.OptionsCustomization.AllowAppointmentCreate = UsedAppointmentType.None; //不允许删除 sc.OptionsCustomization.AllowAppointmentDelete = UsedAppointmentType.None; //不允许拖到 sc.OptionsCustomization.AllowAppointmentDrag = UsedAppointmentType.None; //不允许不同资源间创建 sc.OptionsCustomization.AllowAppointmentDragBetweenResources = UsedAppointmentType.None; //允许编辑 sc.OptionsCustomization.AllowAppointmentEdit = UsedAppointmentType.All; //不允许多个选择 sc.OptionsCustomization.AllowAppointmentMultiSelect = false; //不允许改变大小 sc.OptionsCustomization.AllowAppointmentResize = UsedAppointmentType.None; //不允许依赖窗体弹出 sc.OptionsCustomization.AllowDisplayAppointmentDependencyForm = AllowDisplayAppointmentDependencyForm.Never; //允许Appointment窗体弹出 sc.OptionsCustomization.AllowDisplayAppointmentForm = AllowDisplayAppointmentForm.Auto; //不允许编辑文字 sc.OptionsCustomization.AllowInplaceEditor = UsedAppointmentType.None; //GrantView sc.Views.GanttView.CellsAutoHeightOptions.Enabled = true;//设置单元格不自适应高度 sc.Views.GanttView.CellsAutoHeightOptions.MinHeight = 0;//设置最小高度 //设置Appointment 的高度不自适应 sc.Views.GanttView.AppointmentDisplayOptions.AppointmentAutoHeight = true; sc.Views.GanttView.AppointmentDisplayOptions.AppointmentHeight = 0; sc.Views.GanttView.AppointmentDisplayOptions.AppointmentInterspacing = 1; sc.Views.GanttView.AppointmentDisplayOptions.ContinueArrowDisplayType = AppointmentContinueArrowDisplayType.Never; //不显示开始时间 sc.Views.GanttView.AppointmentDisplayOptions.StartTimeVisibility = AppointmentTimeVisibility.Never; //不显示结束时间 sc.Views.GanttView.AppointmentDisplayOptions.EndTimeVisibility = AppointmentTimeVisibility.Never; //不显示进度条 sc.Views.GanttView.AppointmentDisplayOptions.PercentCompleteDisplayType = PercentCompleteDisplayType.None; //不显示恢复 sc.Views.GanttView.AppointmentDisplayOptions.ShowRecurrence = false; //不显示提醒 sc.Views.GanttView.AppointmentDisplayOptions.ShowReminder = false; sc.Views.GanttView.AppointmentDisplayOptions.SnapToCellsMode = AppointmentSnapToCellsMode.Never; //不显示状态 sc.Views.GanttView.AppointmentDisplayOptions.StatusDisplayType = AppointmentStatusDisplayType.Never; //显示样式 sc.Views.GanttView.AppointmentDisplayOptions.TimeDisplayType = AppointmentTimeDisplayType.Text; //显示颜色 sc.Views.GanttView.Appearance.Dependency.ForeColor = Color.Red; sc.Views.GanttView.Appearance.SelectedDependency.ForeColor = Color.Blue; sc.Views.GanttView.Scales.Clear();//清空 DevExpress.XtraScheduler.TimeScaleDay td = new TimeScaleDay(); td.DisplayFormat = "yyyy-MM-dd"; td.Enabled = true; DevExpress.XtraScheduler.TimeScale15Minutes tm = new TimeScale15Minutes(); tm.Enabled = true; sc.Views.GanttView.Scales.Add(td); sc.Views.GanttView.Scales.Add(tm); } void scLd1_InitAppointmentDisplayText(object sender, AppointmentDisplayTextEventArgs e) { Appointment apt = e.Appointment; e.Text = GetCustomSubject(apt); } string GetCustomSubject(Appointment apt) { string s = apt.Subject; if (apt.Location.Length > 0) { s += String.Format("\r\n[{0}]", apt.Location); } return s; } void toolTipController1_BeforeShow(object sender, ToolTipControllerShowEventArgs e) { ToolTipController controller = sender as ToolTipController; AppointmentViewInfo aptViewInfo = controller.ActiveObject as AppointmentViewInfo; if (aptViewInfo == null) return; var app = aptViewInfo.Appointment; e.IconType = ToolTipIconType.Information; e.Title = app.Subject; e.ToolTip = string.Format("{0},{1}", app.Location, app.CustomFields["Note"]); } /// <summary> /// 清空菜单,自定义菜单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void schedulerControl1_PopupMenuShowing(object sender, DevExpress.XtraScheduler.PopupMenuShowingEventArgs e) { //DXMenuItem item = new DXMenuItem("菜单项"); if (scLd1.ActiveViewType == DevExpress.XtraScheduler.SchedulerViewType.Day)//不同view展示不同菜单项 { } if (e.Menu.Id == DevExpress.XtraScheduler.SchedulerMenuItemId.DefaultMenu)//右键空白处 { e.Menu.Items.Clear(); } if (e.Menu.Id == DevExpress.XtraScheduler.SchedulerMenuItemId.AppointmentMenu)//appointment 上右键 { e.Menu.Items.Clear(); //e.Menu.Items.Add(item); } } private void schedulerControl1_EditAppointmentFormShowing(object sender, DevExpress.XtraScheduler.AppointmentFormEventArgs e) { DevExpress.XtraScheduler.SchedulerControl scheduler = ((DevExpress.XtraScheduler.SchedulerControl)(sender)); using( AppiontmentForm form = new AppiontmentForm(scheduler, e.Appointment, e.OpenRecurrenceForm)) { form.ShowDialog(); e.Handled = true; } }
设置绑定数据资源类 ,设置Appointment类,设置依赖关系类。具体字体参考Mapping的设置。
以上是关于Dev 甘特图的主要内容,如果未能解决你的问题,请参考以下文章