private void SaveCfg() { if (ChangedWeekValue(week, weekLastSave)) { using (StreamWriter file = File.CreateText(saveFile)) { JsonSerializer serializer = new JsonSerializer(); //serialize object directly into file stream serializer.Serialize(file, week); } weekLastSave = new WeekData(week); } }
private void LoadCfg() { using (StreamReader file = File.OpenText(saveFile)) { JsonSerializer serializer = new JsonSerializer(); WeekData weekLoaded = (WeekData)serializer.Deserialize(file, typeof(WeekData)); if (ChangedWeekValue(weekLoaded, week)) { week = weekLoaded; hours = weekLoaded.hours; minutes = weekLoaded.minutes; } } }
public WeekData(WeekData weekData) { monWorkHour = weekData.monWorkHour; monWorkMinutes = weekData.monWorkMinutes; monPauseHour = weekData.monPauseHour; monPauseMinutes = weekData.monPauseMinutes; dieWorkHour = weekData.dieWorkHour; dieWorkMinutes = weekData.dieWorkMinutes; diePauseHour = weekData.diePauseHour; diePauseMinutes = weekData.diePauseMinutes; mitWorkHour = weekData.mitWorkHour; mitWorkMinutes = weekData.mitWorkMinutes; mitPauseHour = weekData.mitPauseHour; mitPauseMinutes = weekData.mitPauseMinutes; donWorkHour = weekData.donWorkHour; donWorkMinutes = weekData.donWorkMinutes; donPauseHour = weekData.donPauseHour; donPauseMinutes = weekData.donPauseMinutes; freWorkHour = weekData.freWorkHour; freWorkMinutes = weekData.freWorkMinutes; frePauseHour = weekData.frePauseHour; frePauseMinutes = weekData.frePauseMinutes; samWorkHour = weekData.samWorkHour; samWorkMinutes = weekData.samWorkMinutes; samPauseHour = weekData.samPauseHour; samPauseMinutes = weekData.samPauseMinutes; sonWorkHour = weekData.sonWorkHour; sonWorkMinutes = weekData.sonWorkMinutes; sonPauseHour = weekData.sonPauseHour; sonPauseMinutes = weekData.sonPauseMinutes; hours = weekData.hours; minutes = weekData.minutes; }
private bool ChangedWeekValue(WeekData week1, WeekData week2) { bool change = false; #region Check for a change if (week1.monWorkHour != week2.monWorkHour) { change = true; } else if (week1.monWorkMinutes != week2.monWorkMinutes) { change = true; } else if (week1.monPauseHour != week2.monPauseHour) { change = true; } else if (week1.monPauseMinutes != week2.monPauseMinutes) { change = true; } else if (week1.dieWorkHour != week2.dieWorkHour) { change = true; } else if (week1.dieWorkMinutes != week2.dieWorkMinutes) { change = true; } else if (week1.diePauseHour != week2.diePauseHour) { change = true; } else if (week1.diePauseMinutes != week2.diePauseMinutes) { change = true; } else if (week1.mitWorkHour != week2.mitWorkHour) { change = true; } else if (week1.mitWorkMinutes != week2.mitWorkMinutes) { change = true; } else if (week1.mitPauseHour != week2.mitPauseHour) { change = true; } else if (week1.mitPauseMinutes != week2.mitPauseMinutes) { change = true; } else if (week1.donWorkHour != week2.donWorkHour) { change = true; } else if (week1.donWorkMinutes != week2.donWorkMinutes) { change = true; } else if (week1.donPauseHour != week2.donPauseHour) { change = true; } else if (week1.donPauseMinutes != week2.donPauseMinutes) { change = true; } else if (week1.freWorkHour != week2.freWorkHour) { change = true; } else if (week1.freWorkMinutes != week2.freWorkMinutes) { change = true; } else if (week1.frePauseHour != week2.frePauseHour) { change = true; } else if (week1.frePauseMinutes != week2.frePauseMinutes) { change = true; } else if (week1.samWorkHour != week2.samWorkHour) { change = true; } else if (week1.samWorkMinutes != week2.samWorkMinutes) { change = true; } else if (week1.samPauseHour != week2.samPauseHour) { change = true; } else if (week1.samPauseMinutes != week2.samPauseMinutes) { change = true; } else if (week1.sonWorkHour != week2.sonWorkHour) { change = true; } else if (week1.sonWorkMinutes != week2.sonWorkMinutes) { change = true; } else if (week1.sonPauseHour != week2.sonPauseHour) { change = true; } else if (week1.sonPauseMinutes != week2.sonPauseMinutes) { change = true; } else if (week1.hours != week2.hours) { change = true; } else if (week1.minutes != week2.minutes) { change = true; } #endregion return(change); }