private bool IsOneSection(HalfCell thisCell, HalfCell nextCell) { if (thisCell == null || nextCell == null) { return(false); } if (thisCell.CellNumber.X == nextCell.CellNumber.X) { if (thisCell.CellNumber.Y == nextCell.CellNumber.Y) { if (thisCell.half != nextCell.half) { return(true); } } if (thisCell.CellNumber.Y + 1 == nextCell.CellNumber.Y) { if (thisCell.half == Half.Bottom && nextCell.half == Half.Top) { return(true); } } } return(false); }
private void ActivateOrDeactivateHalfCell(HalfCell cell, DrawState action) { if (action == DrawState.Nothing) { return; } if (CellIsHeader(cell)) { return; } HalfCell ahc = activeHalfCells.FirstOrDefault(ac => ac.Equals(cell)); if (action == DrawState.Draw) { if (ahc == null) { activeHalfCells.Add(cell); } } if (action == DrawState.Erase) { if (ahc != null) { activeHalfCells.Remove(ahc); } } this.QueueDraw(); }
public IList <EmployeeWorkChart> GetWorkChart() { activeHalfCells.Sort(); IList <EmployeeWorkChart> ewcList = new List <EmployeeWorkChart>(); EmployeeWorkChart tempEWC = new EmployeeWorkChart(); HalfCell prevCell = null; HalfCell thisCell = null; HalfCell nextCell = null; for (int i = 0; i < activeHalfCells.Count; i++) { thisCell = activeHalfCells[i]; if (i + 1 < activeHalfCells.Count) { nextCell = activeHalfCells[i + 1]; } tempEWC.Date = new DateTime(this.Date.Year, this.Date.Month, thisCell.CellNumber.X); if (prevCell == null) { double timeToAdd = 0; timeToAdd = activeHalfCells[i].CellNumber.Y - topHeadersCount; if (activeHalfCells[i].half == Half.Bottom) { timeToAdd += 0.5; } tempEWC.StartTime = TimeSpan.FromHours(timeToAdd); } prevCell = thisCell; if (!IsOneSection(thisCell, nextCell)) { double timeToAdd = 0; //Плюсуем половину, для того, чтобы в базу записывался весь промежуток timeToAdd = activeHalfCells[i].CellNumber.Y - topHeadersCount + 0.5; if (activeHalfCells[i].half == Half.Bottom) { timeToAdd += 0.5; } tempEWC.EndTime = TimeSpan.FromHours(timeToAdd); ewcList.Add(tempEWC); prevCell = null; tempEWC = new EmployeeWorkChart(); } } return(ewcList); }
protected override bool OnMotionNotifyEvent(Gdk.EventMotion evnt) { HalfCell hc = GetHalfCell((int)evnt.X, (int)evnt.Y); if (!mouseOnCell.Equals(hc)) { mouseOnCell = hc; ActivateOrDeactivateHalfCell(GetHalfCell((int)evnt.X, (int)evnt.Y), isDraw); this.QueueDraw(); } return(base.OnMotionNotifyEvent(evnt)); }
protected override bool OnButtonPressEvent(Gdk.EventButton ev) { // Insert button press handling code here. HalfCell cell = activeHalfCells.FirstOrDefault(ahc => ahc.Equals(GetHalfCell((int)ev.X, (int)ev.Y))); if (cell == null) { isDraw = DrawState.Draw; } else { isDraw = DrawState.Erase; } ActivateOrDeactivateHalfCell(GetHalfCell((int)ev.X, (int)ev.Y), isDraw); return(base.OnButtonPressEvent(ev)); }
private void FillHalf(HalfCell cell, Cairo.Color color) { PointD coord = GetCellCoordinates(cell.CellNumber.Y, cell.CellNumber.X); if (cell.half == Half.Bottom) { coord.Y += cellHeight / 2; } using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { g.SetSourceRGBA(color.R, color.G, color.B, color.A); g.MoveTo(coord); g.Rectangle(coord, cellWidth, cellHeight / 2); g.Fill(); g.GetTarget().Dispose(); } }
private bool CellIsHeader(HalfCell cell) { if (cell.CellNumber.X >= 0 && cell.CellNumber.X < leftHeadersCount) { return(true); } if (cell.CellNumber.Y >= 0 && cell.CellNumber.Y < topHeadersCount) { return(true); } if (cell.CellNumber.X >= totalColums) { return(true); } if (cell.CellNumber.Y >= totalRows) { return(true); } return(false); }
public void SetWorkChart(IList <EmployeeWorkChart> data) { activeHalfCells.Clear(); if (data == null) { return; } foreach (var item in data) { TimeSpan tempTime = item.StartTime; TimeSpan endTime = item.EndTime.Add(TimeSpan.FromHours(-0.5)); while (tempTime <= endTime) { HalfCell hc = new HalfCell { CellNumber = new CellNumber { X = item.Date.Day, Y = tempTime.Hours + topHeadersCount } }; if (tempTime.Minutes >= 0 && tempTime.Minutes < 30) { hc.half = Half.Top; } if (tempTime.Minutes >= 30 && tempTime.Minutes < 60) { hc.half = Half.Bottom; } activeHalfCells.Add(hc); tempTime = tempTime.Add(TimeSpan.FromMinutes(30)); } } }
public int CompareTo(object obj) { HalfCell cell = obj as HalfCell; if (this.CellNumber.X > cell.CellNumber.X) { return(1); } if (this.CellNumber.X < cell.CellNumber.X) { return(-1); } if (this.CellNumber.X == cell.CellNumber.X) { if (this.CellNumber.Y > cell.CellNumber.Y) { return(1); } if (this.CellNumber.Y < cell.CellNumber.Y) { return(-1); } if (this.CellNumber.Y == cell.CellNumber.Y) { if (this.half > cell.half) { return(1); } if (this.half < cell.half) { return(-1); } } } return(0); }
protected override bool OnMotionNotifyEvent(Gdk.EventMotion evnt) { HalfCell hc = GetHalfCell((int)evnt.X, (int)evnt.Y); if (!mouseOnCell.Equals(hc)) { mouseOnCell = hc; ActivateOrDeactivateHalfCell(GetHalfCell((int)evnt.X, (int)evnt.Y), isDraw); this.QueueDraw(); } return base.OnMotionNotifyEvent(evnt); }
public bool Equals(HalfCell cell) { return (this.CellNumber.Equals(cell.CellNumber) && this.half == cell.half); }
private bool IsOneSection(HalfCell thisCell, HalfCell nextCell) { if (thisCell == null || nextCell == null) return false; if (thisCell.CellNumber.X == nextCell.CellNumber.X) { if (thisCell.CellNumber.Y == nextCell.CellNumber.Y) if (thisCell.half != nextCell.half) return true; if (thisCell.CellNumber.Y + 1 == nextCell.CellNumber.Y) if (thisCell.half == Half.Bottom && nextCell.half == Half.Top) return true; } return false; }
private void FillHalf(HalfCell cell,Cairo.Color color) { PointD coord = GetCellCoordinates(cell.CellNumber.Y, cell.CellNumber.X); if (cell.half == Half.Bottom) coord.Y += cellHeight / 2; using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { g.SetSourceColor(color); g.MoveTo(coord); g.Rectangle(coord, cellWidth, cellHeight / 2); g.Fill(); g.GetTarget().Dispose(); } }
private bool CellIsHeader(HalfCell cell) { if (cell.CellNumber.X >= 0 && cell.CellNumber.X < leftHeadersCount) return true; if (cell.CellNumber.Y >= 0 && cell.CellNumber.Y < topHeadersCount) return true; if (cell.CellNumber.X >= totalColums) return true; if (cell.CellNumber.Y >= totalRows) return true; return false; }
private void ActivateOrDeactivateHalfCell(HalfCell cell, DrawState action) { if (action == DrawState.Nothing) return; if (CellIsHeader(cell)) return; HalfCell ahc = activeHalfCells.FirstOrDefault(ac => ac.Equals(cell)); if (action == DrawState.Draw) { if (ahc == null) activeHalfCells.Add(cell); } if(action == DrawState.Erase) { if (ahc != null) activeHalfCells.Remove(ahc); } this.QueueDraw(); }
public bool Equals(HalfCell cell) { return(this.CellNumber.Equals(cell.CellNumber) && this.half == cell.half); }
public void SetWorkChart(IList<EmployeeWorkChart> data) { activeHalfCells.Clear(); if (data == null) return; foreach (var item in data) { TimeSpan tempTime = item.StartTime; TimeSpan endTime = item.EndTime.Add(TimeSpan.FromHours(-0.5)); while (tempTime <= endTime) { HalfCell hc = new HalfCell { CellNumber = new CellNumber { X = item.Date.Day, Y = tempTime.Hours + topHeadersCount } }; if (tempTime.Minutes >= 0 && tempTime.Minutes < 30) hc.half = Half.Top; if (tempTime.Minutes >= 30 && tempTime.Minutes < 60) hc.half = Half.Bottom; activeHalfCells.Add(hc); tempTime = tempTime.Add(TimeSpan.FromMinutes(30)); } } }