This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
64 lines (57 loc) · 2.41 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraScheduler.Drawing;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Native;
using DevExpress.XtraScheduler.Tools;
namespace DayHeaderStatistics
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataFiller.FillResources(schedulerControl1.Storage, 2);
DataFiller.GenerateAppointments(schedulerControl1.Storage);
schedulerControl1.GroupType = SchedulerGroupType.Resource;
schedulerControl1.Start = DateTime.Now;
}
private void schedulerControl1_CustomDrawDayViewAllDayArea(object sender, DevExpress.XtraScheduler.CustomDrawObjectEventArgs e)
{
if (schedulerStorage1.Appointments != null)
{
AllDayAreaCell cell = (AllDayAreaCell)e.ObjectInfo;
Resource resource = cell.Resource;
TimeInterval interval = cell.Interval;
AppointmentBaseCollection apts = ((SchedulerControl)sender).Storage.GetAppointments(interval);
float percent = CalcCurrentWorkTimeLoad(apts, interval, resource);
Brush brush;
if (percent == 0.0)
brush = Brushes.LightYellow;
else if (percent < 0.5)
brush = Brushes.LightBlue;
else brush = Brushes.LightCoral;
e.Cache.FillRectangle(brush, e.Bounds);
e.Cache.DrawString(string.Format("{0:P}", percent), cell.Appearance.Font, Brushes.Black, e.Bounds, cell.Appearance.TextOptions.GetStringFormat());
e.Handled = true;
}
}
private float CalcCurrentWorkTimeLoad(AppointmentBaseCollection apts, TimeInterval interval, Resource resource)
{
AppointmentBaseCollection aptsByResource = new AppointmentBaseCollection();
var aptQuery = apts.Where(a => a.ResourceId.Equals(resource.Id));
aptsByResource.AddRange(aptQuery.ToList());
IntervalLoadRatioCalculator calc = new IntervalLoadRatioCalculator(interval, aptsByResource);
return calc.Calculate();
}
}
}