private void Export_Click(object sender, EventArgs e) { ExportType E = new ExportType(); if (SzCount.Checked) E.Sz = true; if (PelletCount.Checked) E.Pellet = true; if (MedCount.Checked) E.Med = true; if (MealCheck.Checked) E.Meal = true; if (SzTimes.Checked) E.SzTime = true; if (DetailList.Checked) E.DetailList = true; if (Notes.Checked) E.Notes = true; if (SzSvBox.Checked) E.SeverityIndx = true; SaveFileDialog F = new SaveFileDialog(); F.DefaultExt = ".pjt"; F.InitialDirectory = "D:\\"; if (F.ShowDialog() == DialogResult.OK) { pjt.ExportData(F.FileName, E); } }
public void ExportData(string Fname, ExportType E) { //Open File StreamWriter F = new StreamWriter(Fname); F.AutoFlush = true; // Sort(); int c; string st, st2, st3; DateTime Earliest = Files[0].Start.Date; DateTime Latest = Files[Files.Count - 1].Start.Date; if (E.DetailList) { foreach (AnimalType A in Animals) { F.WriteLine(A.ID); DateTime LastDate = Earliest; foreach (SeizureType S in A.Sz) { foreach (ImportantDateType I in A.ImportantDates) { if ((DateTime.Compare(I.Date, LastDate) > 0) && (DateTime.Compare(I.Date, S.d) <= 0)) { F.WriteLine(I.Date.ToShortDateString() + ", " + I.LabelID); } } F.WriteLine(S.d.ToShortDateString() + ", " + S.t.ToString() + ", " + S.Notes); LastDate = S.d; } foreach (ImportantDateType I in A.ImportantDates) { if ((DateTime.Compare(I.Date, LastDate) > 0)) { F.WriteLine(I.Date.ToShortDateString() + ", " + I.LabelID.ToString()); } } } F.Close(); return; } st = "Animal"; for (DateTime i = Earliest; i <= Latest; i=i.AddDays(1)) { st += "," + i.ToShortDateString(); Console.WriteLine(st); } F.WriteLine(st); foreach (AnimalType A in Animals) { if (E.Sz) //Add up daily seizure count. { st = A.ID; for (DateTime i = Earliest; i <= Latest; i=i.AddDays(1)) { c = 0; foreach (SeizureType S in A.Sz) { if (DateTime.Compare(i.Date, S.d.Date) == 0) c++; } st += "," + c; } F.WriteLine(st); } if (E.SzTime) { st = A.ID; foreach (SeizureType S in A.Sz) { //Create a timestamp based on the earliest hour in the file. st += ", " + Math.Round(S.d.Subtract(Earliest).TotalHours + S.t.Subtract(S.d.TimeOfDay).TotalHours,2).ToString(); } F.WriteLine(st); } if (E.SeverityIndx) st = A.ID; foreach (SeizureType S in A.Sz) { st += ", " + S.Severity.ToString(); } F.WriteLine(st); if (E.Notes) { st = A.ID; foreach (SeizureType S in A.Sz) { st += "," + S.Notes; } F.WriteLine(st); } if (E.Meal) { st = A.ID; st2 = A.ID; st3 = A.ID; foreach (MealType M in A.Meals) { st += ", " + Math.Floor(M.d.Subtract(Earliest).TotalHours).ToString(); if (M.type == "M") { st2 += ", 1"; } else { st2 += ", 0"; } if (E.Pellet) { st3 += ", " + M.pelletcount.ToString(); } } F.WriteLine(st); F.WriteLine(st2); F.WriteLine(st3); } /*if (E.Pellet) { st = A.ID; for (DateTime i = Earliest; i <= Latest; i=i.AddDays(1)) { c = 0; foreach (MealType M in A.Meals) { if (DateTime.Compare(i.Date, M.d.Date) == 0) { if (M.type == "M") { c+= M.pelletcount; } else { c-= M.pelletcount; } } } st += "," + c; } F.WriteLine(st); } */ } F.Close(); }