private void SaveButton_Click(object sender, RoutedEventArgs e) { List <Items> wrList = (List <Items>)lessonGrid.ItemsSource; for (int column = 1; column < DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month) + 1; column++) { DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, column); LessonEvent lsnEvent = new LessonEvent(); if (!lessonRepository.IsExist(p => p.Date == dt)) { lsnEvent.Date = dt; lessonRepository.Insert(lsnEvent); lessonRepository.AddToCache(lsnEvent, lsnEvent.ID); } else { lsnEvent = lessonRepository.GetAllFromCache().Where(d => d.Date == dt).First(); } for (int row = 0; row < workerRepository.GetAllFromCache(1).Count(); row++) { Worker wr = wrList[row].wrk; DataGridRow r = lessonGrid.GetRow(row); CheckBox ch = (CheckBox)lessonGrid.GetCell(r, column).Content; if (!lessonMarkRepository.IsExist(p => p.WorkerID == wr.ID && p.LessonEventID == lsnEvent.ID)) { LessonMarks lsnMark = new LessonMarks(); lsnMark.IsVisited = ch.IsChecked.Value; lsnMark.WorkerID = wr.ID; lsnMark.LessonEventID = lsnEvent.ID; lessonMarkRepository.Insert(lsnMark); } else { LessonMarks lsnMark = lessonMarkRepository.Get(p => p.WorkerID == wr.ID && p.LessonEventID == lsnEvent.ID).First(); lsnMark.IsVisited = ch.IsChecked.Value; lessonMarkRepository.Update(lsnMark); } } SetCellColor(false); SetChanged(false); //lessonRepository.ClearAll(); } }
public void SetValue(bool clear = true) { List <Items> wrList = (List <Items>)lessonGrid.ItemsSource; for (int column = 1; column < DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month) + 1; column++) { DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, column); LessonEvent lsnEvent = new LessonEvent(); if (lessonRepository.IsExist(p => p.Date == dt)) { lsnEvent = lessonRepository.GetAllFromCache().Where(d => d.Date == dt).First(); } else { lsnEvent.Date = dt; lessonRepository.Insert(lsnEvent); lessonRepository.AddToCache(lsnEvent, lsnEvent.ID); } for (int row = 0; row < workerRepository.GetAllFromCache(1).Count(); row++) { Worker wr = wrList[row].wrk; DataGridRow r = lessonGrid.GetRow(row); var s = lessonGrid.GetCell(r, column).Content; CheckBox ch = (CheckBox)s; if (lessonMarkRepository.IsExist(p => p.LessonEventID == lsnEvent.ID && p.WorkerID == wr.ID)) { //if (lessonRepository.IsExist(p => p.Date == dt)) ch.IsChecked = clear ? lessonMarkRepository.Get(p => p.WorkerID == wr.ID && p.LessonEventID == lsnEvent.ID).First().IsVisited : false; } else { ch.IsChecked = false; } s = ch; lessonGrid.GetCell(r, column).Content = ch; } } GridCount(); }
public void SetValue() { List <Items> wrList = (List <Items>)lessonGrid.ItemsSource; for (int column = 1; column < DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month) + 1; column++) { DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, column); LessonEvent lsnEvent = new LessonEvent(); if (lessonRepository.IsExist(p => p.Date == dt)) { lsnEvent = lessonRepository.GetAllFromCache().Where(d => d.Date == dt).First(); } //lsnEvent = lessonRepository.Get(d => d.Date == dt).First(); ConcertEvent concEvent = new ConcertEvent(); if (concertRepository.IsExist(p => dt >= p.BeginningDate && dt <= p.EndDate)) { concEvent = concertRepository.GetListFromCache().Where(p => dt >= p.BeginningDate && dt <= p.EndDate).First(); //concEvent = concertRepository.Get(p => dt >= p.BeginningDate && dt <= p.EndDate).First(); } for (int row = 0; row < workerRepository.GetAllFromCache(1).Count(); row++) { int wrId = wrList[row].wrk.ID; DataGridRow r = lessonGrid.GetRow(row); if (lessonMarkRepository.IsExist(p => p.LessonEventID == lsnEvent.ID && p.IsVisited == true && p.WorkerID == wrId)) { lessonGrid.GetCell(r, column).Background = new SolidColorBrush(Colors.Red); } if (concertMarkRepository.IsExist(p => p.ConcertEventID == concEvent.ID && p.WorkerID == wrId)) { lessonGrid.GetCell(r, column).Background = new SolidColorBrush(Colors.Green); } } } GridSum(wrList); }
private void SaveExelButton_Click(object sender, RoutedEventArgs e) { List <Items> wrList = (List <Items>)lessonGrid.ItemsSource; Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Visible = true; Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Add(System.Reflection.Missing.Value); Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1]; for (int j = 0; j < lessonGrid.Columns.Count; j++) { Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[1, j + 1]; sheet1.Cells[1, j + 1].Font.Bold = true; sheet1.Columns[j + 1].ColumnWidth = 15; myRange.Value2 = lessonGrid.Columns[j].Header; } for (int i = 0; i < lessonGrid.Columns.Count; i++) { DateTime dt; ConcertEvent concEvent = new ConcertEvent(); LessonEvent lsnEvent = new LessonEvent(); if (i != 0 && i != lessonGrid.Columns.Count && i != lessonGrid.Columns.Count - 1) { dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, i); concEvent = new ConcertEvent(); if (concertRepository.IsExist(p => dt >= p.BeginningDate && dt <= p.EndDate)) { concEvent = concertRepository.GetListFromCache().Where(p => dt >= p.BeginningDate && dt <= p.EndDate).First(); } lsnEvent = lessonRepository.GetAllFromCache().Where(d => d.Date == dt).First(); } for (int j = 0; j < lessonGrid.Items.Count; j++) { int wrId = wrList[j].wrk.ID; DataGridRow r = lessonGrid.GetRow(j); TextBlock b = lessonGrid.Columns[i].GetCellContent(lessonGrid.Items[j]) as TextBlock; Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[j + 2, i + 1]; if (lessonMarkRepository.IsExist(p => p.LessonEventID == lsnEvent.ID && p.IsVisited == true && p.WorkerID == wrId)) { lessonGrid.GetCell(r, i).Background = new SolidColorBrush(Colors.Red); myRange.Value2 = 1.ToString(); } else if (concertMarkRepository.IsExist(p => p.ConcertEventID == concEvent.ID && p.WorkerID == wrId)) { lessonGrid.GetCell(r, i).Background = new SolidColorBrush(Colors.Green); double mark = concertMarkRepository.Get(p => p.ConcertEventID == concEvent.ID && p.WorkerID == wrId).First().NumOfMarks; TimeSpan d1 = concEvent.EndDate.Value - concEvent.BeginningDate.Value; myRange.Value2 = "(концерт)" + Math.Round((mark / (double)d1.Days), 2).ToString(); } else { myRange.Value2 = b.Text; } } } workbook.SaveAs("отчёт за " + DateTime.Now.Month + " месяц"); excel.Quit(); }