public static DayTotals LoadDay(string shift, int month, int day, int year) { string path_ = shift == "Day" ? $@"{Global.Strings.DayShiftDirectory}Totals/" : $@"{Global.Strings.SwingShiftDirectory}Totals/"; DayTotals dt = new DayTotals(); XmlSerializer formatter = new XmlSerializer(dt.GetType()); FileStream file = new FileStream($@"{path_}{month}-{day}-{year}.xml", FileMode.Open); byte[] buffer = new byte[file.Length]; file.Read(buffer, 0, (int)file.Length); MemoryStream stream = new MemoryStream(buffer); dt = (DayTotals)formatter.Deserialize(stream); file.Close(); file.Dispose(); return(dt); }
public static void SaveToday(DateTime dateTime, string shift) { if (shift == "Day") { string path = $@"{Global.Strings.DayShiftDirectory}Totals/{dateTime.Month}-{dateTime.Day}-{dateTime.Year}.xml"; FileStream outFile = File.Create(path); DayTotals dt = BuildTotalsData(dateTime); XmlSerializer formatter = new XmlSerializer(dt.GetType()); formatter.Serialize(outFile, dt); outFile.Close(); outFile.Dispose(); } if (shift == "Swing") { string path = $@"{Global.Strings.SwingShiftDirectory}Totals/{dateTime.Month}-{dateTime.Day}-{dateTime.Year}.xml"; FileStream outFile = File.Create(path); DayTotals dt = BuildTotalsData(dateTime); XmlSerializer formatter = new XmlSerializer(dt.GetType()); formatter.Serialize(outFile, dt); outFile.Close(); outFile.Dispose(); } }
public static List <DayTotals> LoadMonth(string shift, int monthNumber, int yearNumber) { string path_ = shift == "Day" ? $@"{Global.Strings.DayShiftDirectory}Totals/" : $@"{Global.Strings.SwingShiftDirectory}Totals/"; List <DayTotals> dtL = new List <DayTotals>(); for (int i = 1; i < 32; i++) { if (File.Exists($@"{path_}{monthNumber}-{i}-{yearNumber}.xml")) { DayTotals dt = new DayTotals(); XmlSerializer formatter = new XmlSerializer(dt.GetType()); FileStream file = new FileStream($@"{path_}{monthNumber}-{i}-{yearNumber}.xml", FileMode.Open); byte[] buffer = new byte[file.Length]; file.Read(buffer, 0, (int)file.Length); MemoryStream stream = new MemoryStream(buffer); dt = (DayTotals)formatter.Deserialize(stream); dtL.Add(dt); file.Close(); file.Dispose(); } } return(dtL); }
// build day file path public static void LoadMP() { System.Threading.Thread.Sleep(Ints.RTLoadSeed); string path_ = Strings.Shift == "Day" ? $@"{Global.Strings.DayShiftDirectory}Totals/" : $@"{Global.Strings.SwingShiftDirectory}Totals/"; if (File.Exists($@"{path_}{Other.CurrentDate.Month}-{Other.CurrentDate.Day}-{Other.CurrentDate.Year}.xml")) { Random r = new Random(); string tempFile = $"{r.Next(9999)}.xml"; File.Copy($@"{path_}{Other.CurrentDate.Month}-{Other.CurrentDate.Day}-{Other.CurrentDate.Year}.xml", $@"{tempFile}"); DayTotals dt = new DayTotals(); XmlSerializer formatter = new XmlSerializer(dt.GetType()); FileStream file = new FileStream($@"{tempFile}", FileMode.Open); byte[] buffer = new byte[file.Length]; file.Read(buffer, 0, (int)file.Length); MemoryStream stream = new MemoryStream(buffer); dt = (DayTotals)formatter.Deserialize(stream); Dec.ManPower = dt.Manpower; file.Close(); File.Delete($@"{tempFile}"); file.Dispose(); Forms.ClockOut.SetMP(); } }