private static void CopyAndPasteCell(DataGridViewCell selectedCell, TimeSheetDay clipboarValue) { // Copy new TimeSheetDay selectedCellValue = selectedCell.Value as TimeSheetDay; var updateDay = DateTime.MinValue; if (selectedCellValue != null) { updateDay = selectedCellValue.Day; } else { var selectedColumn = selectedCell.OwningColumn as DataGridViewTimeSheetColumn; if (selectedColumn != null) { updateDay = selectedColumn.PresentDay; } } // Paste new if (updateDay > DateTime.MinValue) { var newTimeSheetDay = new TimeSheetDay(clipboarValue); newTimeSheetDay.Day = updateDay; selectedCell.Value = newTimeSheetDay; } }
/// <summary> /// Helper method to gets the content of a TimeSheetDay. /// Support for showing comment tooltip /// </summary> public static string GetContent(this TimeSheetDay tsDay) { StringBuilder sb = new StringBuilder(); if (tsDay.ShiftItems != null && tsDay.ShiftItems.Count > 0) { sb.AppendLine("Planned: "); for (int i = 0; i < tsDay.ShiftItems.Count; i++) { sb.AppendFormat("+ {0}", tsDay.ShiftItems[i]); sb.AppendLine(); } } if (tsDay.LeaveItems != null && tsDay.LeaveItems.Count > 0) { sb.AppendLine("Real time:"); for (int i = 0; i < tsDay.LeaveItems.Count; i++) { sb.AppendFormat("+ {0}", tsDay.LeaveItems[i]); sb.AppendLine(); } } return(sb.ToString()); }
public TimeSheetDay GenerateATimeSheetDay(DateTime initDay) { var tsday = new TimeSheetDay(); tsday.Day = initDay; tsday.Catalog = GetTimeSheetType(tsday.Day); // Generate Planned Items tsday.ShiftItems = new List <ShiftRecord>(); int plannedCount = rand.Next(3); for (int k = 0; k < plannedCount; k++) { ShiftRecord plannedItem = new ShiftRecord(); plannedItem.FromTime = k == 0 ? tsday.Day.AddHours(-tsday.Day.Hour + rand.Next(8)) : tsday.ShiftItems[k - 1].ToTime.AddHours(rand.Next(2)); plannedItem.ToTime = plannedItem.FromTime.AddHours(rand.Next(4) + 6); plannedItem.TimeSheetType = k == 0 ? SampleTimeSheetTypeList.RandomBelongsCatalogs(TimeSheetCatalog.Shift) : SampleTimeSheetTypeList.RandomBelongsCatalogs(TimeSheetCatalog.Shift, TimeSheetCatalog.Overtime); plannedItem.Status = GetTimeSheetStatus(plannedItem.TimeSheetType.Catalog); tsday.ShiftItems.Add(plannedItem); } // Generate RealTime Items tsday.LeaveItems = new List <LeaveRecord>(); int realTimeCount = plannedCount; for (int k = 0; k < realTimeCount; k++) { LeaveRecord realItem = new LeaveRecord(); realItem.FromTime = k == 0 ? tsday.ShiftItems[0].FromTime : tsday.LeaveItems[k - 1].ToTime.AddHours(rand.Next(3)); realItem.ToTime = realItem.FromTime.AddHours(rand.Next(4) + 6); realItem.TimeSheetType = SampleTimeSheetTypeList.RandomBelongsCatalogs(TimeSheetCatalog.Leave); realItem.Status = GetTimeSheetStatus(realItem.TimeSheetType.Catalog); tsday.LeaveItems.Add(realItem); } if (tsday.ShiftItems.Count > 0 || tsday.LeaveItems.Count > 0) { tsday.Status = rand.Next(2) == 0 ? TimeSheetStatus.None : TimeSheetStatus.Locked; } return(tsday); }
protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) { Bitmap resultImage = new Bitmap(this.OwningColumn.Width, this.OwningRow.Height); using (Graphics g = Graphics.FromImage(resultImage)) { var rect = new Rectangle(1, 1, resultImage.Width - 3, resultImage.Height - 3); TimeSheetDay data = value as TimeSheetDay; if (data != null && data != TimeSheetDay.Empty) { Color catColor = this.OwnTimeSheetGridView.GetColorByTimeSheetCatalog(data.Catalog); Color statusColor = this.OwnTimeSheetGridView.GetColorByTimeSheetStatus(data.Status); Renderer.DrawBox(g, rect, catColor, statusColor, 1, DashStyle.Solid); } } return(resultImage); }
public TimeSheetDay(TimeSheetDay tsDay) { // Copy status _status = tsDay.Status; _catalog = tsDay.Catalog; // Copy shifts if (tsDay.ShiftItems != null) { this.ShiftItems = new List <ShiftRecord>(); this.ShiftItems.AddRange(tsDay.ShiftItems); } // Copy leaves if (tsDay.LeaveItems != null) { this.LeaveItems = new List <LeaveRecord>(); this.LeaveItems.AddRange(tsDay.LeaveItems); } // Copy day _day = tsDay.Day; }
public CellPastingEventArgs(DataGridViewCell selectedCell, TimeSheetDay newValue) : this() { this.SelectedCell = selectedCell; this.NewValue = newValue; }
/// <summary> /// Helper method to gets the title of a TimeSheetDay. /// Support for showing comment tooltip /// </summary> public static string GetTitle(this TimeSheetDay tsDay) { return(string.Format("{0} [{1:yyyy/MM/dd}]", tsDay.Catalog, tsDay.Day)); }