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: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms;
namespace TestResourcePlanningCtrl { public partial class ResourcePlanningCtrl : UserControl { public DateTime Date { get; set; }
public ResourceOccupation SelectedOccupation { get; set; }
private Pen mySelectionPen = new Pen(Brushes.Blue); private int orX; private int orY;
private List<Resource> _Resources = null; public List<Resource> Resources { get {return _Resources; } set { _Resources = value;
if (splitContainer1 != null) { if (splitContainer1.Panel1 != null) splitContainer1.Panel1.Refresh(); } if (splitContainer2 != null) { if (splitContainer2.Panel1 != null) splitContainer2.Panel1.Refresh();
if (splitContainer2.Panel2 != null) splitContainer2.Panel2.Refresh(); } } }
private Dictionary<ResourceOccupation, Rectangle> lastPaintPositions = new Dictionary<ResourceOccupation, Rectangle>();
public ResourcePlanningCtrl() { Date = DateTime.Now; Resources = new List<Resource>();
InitializeComponent(); }
private void panelMainArea_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Rectangle rectClient = splitContainer2.Panel2.ClientRectangle;
g.FillRectangle(Brushes.White, rectClient);
lastPaintPositions.Clear();
for (int i = 0; i < Resources.Count; i++) { Resource res = Resources[i];
g.DrawLine(Pens.Black, new Point(rectClient.Left, rectClient.Top + i * 30), new Point(rectClient.Right, rectClient.Top + i * 30));
foreach (ResourceOccupation resocc in res.Occupations) { int deltaDaysFrom = (resocc.DateFrom - Date).Days; int deltaDaysTill = (resocc.DateTill - Date).Days; Rectangle rectOccupation = new Rectangle(rectClient.Left + deltaDaysFrom * 20, rectClient.Top + i * 30, (deltaDaysTill - deltaDaysFrom) * 20, 30); rectOccupation.Inflate(-5, -5);
if (resocc == SelectedOccupation) g.FillRectangle(Brushes.Red, rectOccupation); else g.DrawRectangle(Pens.Green, rectOccupation);
lastPaintPositions.Add(resocc, rectOccupation);
} } }
private void panelTimeLine_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Rectangle rectClient = splitContainer2.Panel1.ClientRectangle;
g.FillRectangle(Brushes.White, rectClient);
DateTime currentDate = Date;
for (int i = 0; i < 300; i++) { g.DrawLine(Pens.Black, new Point(rectClient.Left + i * 20, rectClient.Top), new Point(rectClient.Left + i * 20, rectClient.Bottom)); g.DrawString(currentDate.Day.ToString(), this.Font, Brushes.Blue, new Point(rectClient.Left + i * 20, rectClient.Top));
currentDate = currentDate.AddDays(1);
} }
private void panelResources_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Rectangle rectClient = splitContainer1.Panel1.ClientRectangle;
g.FillRectangle(Brushes.White, rectClient); for (int i = 0; i < Resources.Count; i++) { Resource res = Resources[i]; g.DrawString(res.Caption, this.Font, Brushes.Blue, new Point(rectClient.Left, rectClient.Top + i * 30)); }
}
private void panelMainArea_MouseDown(object sender, MouseEventArgs e) { foreach (ResourceOccupation resocc in lastPaintPositions.Keys) { Rectangle rectOcc = lastPaintPositions[resocc]; Graphics gr = this.CreateGraphics();
if (rectOcc.Contains(e.Location)) { SelectedOccupation = resocc; orX = e.X; orY = e.Y; Refresh(); return; }
}
SelectedOccupation = null; Refresh();
}
private void panelMainArea_MouseMove(object sender, MouseEventArgs e) {
} } } |