private void scrollToSelectedDay(DayEVM day) { // hack for scrolling to the selected day scrollViewer.ScrollToHome(); workingDaysDataGrid.UpdateLayout(); workingDaysDataGrid.ScrollIntoView(workingDaysDataGrid.SelectedItem); }
private void scrollToSelectedDay(DayEVM day) { // hack for scrolling to the selected day scrollViewer.ScrollToHome(); workingDaysDataGrid.UpdateLayout(); workingDaysDataGrid.ScrollIntoView(workingDaysDataGrid.SelectedItem); // scroll down for centering in the middle of the grid the selected day workingDaysDataGrid.UpdateLayout(); scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + 15); }
private void scrollToFirstDayInMonth(DayEVM day) { // hack for scrolling to the first day in month displaying the group header scrollViewer.ScrollToBottom(); workingDaysDataGrid.UpdateLayout(); workingDaysDataGrid.ScrollIntoView(workingDaysDataGrid.SelectedItem); // scroll 1 unit up for showing current group header workingDaysDataGrid.UpdateLayout(); scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - 1); }
private bool CompileHourTable() { bool result = false; if (stopImport) { return(result); } StatusChanged("Importing Hours..."); try { using (DBArchive db = new DBArchive()) { //Get enumerable rows fron datatable IEnumerable <DataRow> collection = dtHours.Rows.Cast <DataRow>(); foreach (DataRow r in collection) { if (stopImport) { break; } DayEVM d = new DayEVM(); try { d.Timestamp = r.Field <DateTime>("Dbf_Data").ToUnixTimestamp(); d.Type = r.Field <byte>("dbf_Tipo_Giorno"); if (d.Type != 3 && d.Type != 6) { d.Type = 0; } else if (d.Type == 3) { d.Type = 1; } else if (d.Type == 6) { d.Type = 2; } d.Save(db); //t = new Timesheet(); long timestamp = r.Field <DateTime>("Dbf_Data").ToUnixTimestamp(); //Add office hours if ( r.Field <Int16>("Dbf_Uff_Inizio_AM") != 0 | r.Field <Int16>("Dbf_Uff_Fine_AM") != 0 | r.Field <Int16>("Dbf_Uff_Inizio_PM") != 0 | r.Field <Int16>("Dbf_Uff_Fine_PM") != 0) { TimesheetEVM office = new TimesheetEVM(); office.Timestamp = timestamp; office.TravelStartTimeAM = null; office.WorkStartTimeAM = r.Field <Int16>("Dbf_Uff_Inizio_AM") > 0 ? (long?)TimeSpan.FromMinutes(r.Field <Int16>("Dbf_Uff_Inizio_AM")).TotalSeconds : null; office.WorkEndTimeAM = r.Field <Int16>("Dbf_Uff_Fine_AM") > 0 ? (long?)TimeSpan.FromMinutes(r.Field <Int16>("Dbf_Uff_Fine_AM")).TotalSeconds : null; office.TravelEndTimeAM = null; office.TravelStartTimePM = null; office.WorkStartTimePM = r.Field <Int16>("Dbf_Uff_Inizio_PM") > 0 ? (long?)TimeSpan.FromMinutes(r.Field <Int16>("Dbf_Uff_Inizio_PM")).TotalSeconds : null; office.WorkEndTimePM = r.Field <Int16>("Dbf_Uff_Fine_PM") > 0 ? (long?)TimeSpan.FromMinutes(r.Field <Int16>("Dbf_Uff_Fine_PM")).TotalSeconds : null; office.TravelEndTimePM = null; if (db.Timesheets.Where(x => x.Timestamp == office.Timestamp && office.FDL == string.Empty).Count() == 0) { office.Save(db); } } // Factory association short? factoryId = r.Field <short?>("Dbf_Impianto"); string fdlId = FormatFDL(r.Field <string>("Dbf_Foglio")); if (factoryId.HasValue && _factories.ContainsKey(factoryId.Value) && !string.IsNullOrEmpty(fdlId)) { FDL fdl = db.FDLs.SingleOrDefault(f => f.Id == fdlId); if (fdl != null) { if (!fdl.Factory.HasValue) { fdl.Factory = _factories[factoryId.Value]; db.FDLs.AddOrUpdate(fdl); db.SaveChanges(); } } else { Warning($"The FDL {fdlId} is missing on database. Impossible to assign the factory to the current timesheet. Day: {d.Date.ToShortDateString()}"); } } short? factory2Id = r.Field <short?>("Dbf_SecondoImpianto"); string fdl2Id = FormatFDL(r.Field <string>("Dbf_SecondoFoglio")); if (factory2Id.HasValue && _factories.ContainsKey(factory2Id.Value) && !string.IsNullOrEmpty(fdl2Id)) { FDL fdl = db.FDLs.SingleOrDefault(f => f.Id == fdl2Id); if (fdl != null && !fdl.Factory.HasValue) { fdl.Factory = _factories[factory2Id.Value]; db.FDLs.AddOrUpdate(fdl); db.SaveChanges(); } else { Warning($"The second FDL {fdlId} is missing on database. Impossible to assign the factory to the current timesheet. Day: {d.Date.ToShortDateString()}"); } } Message($"Day {d.Date.ToShortDateString()} OK"); } catch (Exception ex) { Error($"Failed to import the Timesheet {d.Date.ToShortDateString()}. {ex}", ex); } } db.SaveChanges(); result = true; } } catch (Exception ex) { Error($"Failed importing the timesheets. {ex}", ex); } return(result); }