public bool WriteToFile(ScheduleSlot slot) { string relativePath = filePath + @"Resources\Registry\"; string fileName; string text = ""; bool success; try { fileName = relativePath + slot.Dia + ".txt"; text = Convert.ToString(slot.ServiceId) + ";" + Convert.ToString(slot.AnimalId) + ";" + Convert.ToString(slot.VeterinaryId) + ";" + slot.Dia + ";" + slot.HoraInicio + ";" + slot.HoraFim + ";"; using (StreamWriter sw = File.AppendText(fileName)) { sw.WriteLine(text); } Console.WriteLine(text); success = true; } catch (Exception e) { Console.WriteLine(e.ToString()); success = false; } return(success); }
public static int CompareSlots(ScheduleSlot A, ScheduleSlot B) { string[] firstDate = A.Dia.Split("-"); string[] secondDate = B.Dia.Split("-"); DateTime day1 = new DateTime(int.Parse(firstDate[2]), int.Parse(firstDate[1]), int.Parse(firstDate[0]), A.HoraInicio / 100, A.HoraInicio % 100, 0); DateTime day2 = new DateTime(int.Parse(secondDate[2]), int.Parse(secondDate[1]), int.Parse(secondDate[0]), B.HoraInicio / 100, B.HoraInicio % 100, 0); if (day1 <= day2) { return(-1); } else { return(1); } }
public List <ScheduleSlot> GetSortedOwnerAppointments(List <int> ownerAnimalIds) { string[] dirs = Directory.GetFiles(@"..\..\..\Resources\Registry"); List <ScheduleSlot> scheduleSlotList = new List <ScheduleSlot>(); foreach (string file in dirs) { string[] lines = File.ReadAllLines(file); foreach (string fileLine in lines) { string[] atributes = fileLine.Split(';'); if (ownerAnimalIds.Contains(int.Parse(atributes[1]))) { ScheduleSlot scheduleSlot = new ScheduleSlot(int.Parse(atributes[0]), int.Parse(atributes[1]), int.Parse(atributes[2]), atributes[3], int.Parse(atributes[4]), int.Parse(atributes[5])); scheduleSlotList.Add(scheduleSlot); } } } scheduleSlotList.Sort(ScheduleSlot.CompareSlots); return(scheduleSlotList); }
public List <ScheduleSlot> ReadScheduleSlot(string date) { string[] dirs = Directory.GetFiles(@"..\..\..\Resources\Registry"); List <ScheduleSlot> scheduleSlotList = new List <ScheduleSlot>(); foreach (string file in dirs) { if (Path.GetFileName(file).Equals(date + ".txt")) { string[] lines = File.ReadAllLines(file); foreach (string line in lines) { string[] atributes = line.Split(';'); ScheduleSlot scheduleSlot = new ScheduleSlot(int.Parse(atributes[0]), int.Parse(atributes[1]), int.Parse(atributes[2]), atributes[3], int.Parse(atributes[4]), int.Parse(atributes[5])); scheduleSlotList.Add(scheduleSlot); } } } return(scheduleSlotList); }