public static string ConvertPulseAndOxygenToString(PulseAndOxygen pulseAndOxygen, char delim) { string result = ""; StringBuilder sb = null; if (pulseAndOxygen != null) { sb = new StringBuilder(); sb.Append(pulseAndOxygen.Type); sb.Append(delim); sb.Append(pulseAndOxygen.Id.ToString()); sb.Append(delim); sb.Append(pulseAndOxygen.PII_ID.ToString()); sb.Append(delim); sb.Append(pulseAndOxygen.Pulse.ToString()); sb.Append(delim); sb.Append(pulseAndOxygen.Oxygen.ToString()); sb.Append(delim); sb.Append(pulseAndOxygen.DateRead.ToString("MM/dd/yyyy")); sb.Append(delim); sb.Append(pulseAndOxygen.TimeRead.ToString("HH:mm:ss tt")); result = sb.ToString(); } return(result); }
private void addButton_Click(object sender, EventArgs e) { string path = MS539_final_project_roderick_devalcourt.Properties.Settings.Default.DefaultPath; string fileName = MS539_final_project_roderick_devalcourt.Properties.Settings.Default.FileName; pulseAndOxygenForm dlg = null; PulseAndOxygen pulseAndOxygen = null; WriteFileLogic writeFileLogic = null; string pathFileName = ""; dlg = new pulseAndOxygenForm(); dlg.ShowDialog(this); if (dlg.DialogResult == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; //save here pulseAndOxygen = new PulseAndOxygen(dlg.pulseAndOxygen); pulseAndOxygen.PII_ID = readFileLogic.personallyIdentifiableInformation.Id; writeFileLogic = new WriteFileLogic(); writeFileLogic.listPulseAndOxygen.Add(pulseAndOxygen); writeFileLogic.personallyIdentifiableInformation = new PersonallyIdentifiableInformation(readFileLogic.personallyIdentifiableInformation); foreach (BloodGlucose bloodGlucose1 in readFileLogic.listBloodGlucose) { writeFileLogic.listBloodGlucose.Add(new BloodGlucose(bloodGlucose1)); } foreach (PulseAndOxygen pulseAndOxygen1 in readFileLogic.listPulseAndOxygen) { writeFileLogic.listPulseAndOxygen.Add(new PulseAndOxygen(pulseAndOxygen1)); } writeFileLogic.PathName = path; writeFileLogic.FileName = fileName; pathFileName = writeFileLogic.GetFormattedFileName(); writeFileLogic.WriteFile(); LoadChart(); this.Cursor = Cursors.Default; } }
public static PulseAndOxygen ConvertPulseAndOxygen(string line, char delim) { PulseAndOxygen pulseAndOxygen = null; string[] words = null; Guid id = Guid.Empty; DateTime dt = DateTime.MinValue; Int32 val = 0; Decimal dv = 0M; CultureInfo culture; DateTimeStyles styles = DateTimeStyles.None; culture = CultureInfo.CreateSpecificCulture("en-US"); if (string.IsNullOrEmpty(line) == false) { words = line.Split(delim); if (words != null) { if (words.Length == 7) { pulseAndOxygen = new PulseAndOxygen(); pulseAndOxygen.Type = words[0]; if (Guid.TryParse(words[1], out id) == true) { pulseAndOxygen.Id = id; } if (Guid.TryParse(words[2], out id) == true) { pulseAndOxygen.PII_ID = id; } if (Int32.TryParse(words[3], out val) == true) { pulseAndOxygen.Pulse = val; } if (Decimal.TryParse(words[4], out dv) == true) { pulseAndOxygen.Oxygen = dv; } if (DateTime.TryParse(words[5], culture, styles, out dt) == true) { pulseAndOxygen.DateRead = dt; } if (DateTime.TryParse(words[6], culture, styles, out dt) == true) { pulseAndOxygen.TimeRead = dt; } } } } return(pulseAndOxygen); }
private bool checkInputs() { bool result = false; int pulse = 0; decimal oxygen = 0M; int count = 0; pulseAndOxygen = new PulseAndOxygen(); if (string.IsNullOrEmpty(pulseTextbox.Text) == true) { count++; this.errorProvider1.SetError(pulseTextbox, "Pulse is a required input!"); } else { if (Int32.TryParse(pulseTextbox.Text, out pulse) == false) { count++; this.errorProvider1.SetError(pulseTextbox, "Pulse is a integer (0-200)!"); } else { if ((pulse < 0) || (pulse > 200)) { count++; this.errorProvider1.SetError(pulseTextbox, "Pulse is a integer (0-200)!"); } else { pulseAndOxygen.Pulse = pulse; } } } if (string.IsNullOrEmpty(oxygenTextbox.Text) == true) { count++; this.errorProvider1.SetError(oxygenTextbox, "Oxygen is a required input!"); } else { if (decimal.TryParse(oxygenTextbox.Text, out oxygen) == false) { count++; this.errorProvider1.SetError(oxygenTextbox, "Oxygen is a decimal % (0-100)!"); } else { if ((oxygen < 0) || (oxygen > 200)) { count++; this.errorProvider1.SetError(oxygenTextbox, "Oxygen is a decimal % (0-100)!"); } else { pulseAndOxygen.Oxygen = oxygen; } } } if (string.IsNullOrEmpty(datePicker1.Text) == true) { count++; this.errorProvider1.SetError(datePicker1, "Date is a required input!"); } else { pulseAndOxygen.DateRead = datePicker1.Value; } if (string.IsNullOrEmpty(timePicker1.Text) == true) { count++; this.errorProvider1.SetError(timePicker1, "Time is a required input!"); } else { pulseAndOxygen.TimeRead = timePicker1.Value; } if (count == 0) { result = true; } else { pulseAndOxygen = null; } return(result); }
public void ReadFile() { StringBuilder stringBuilder = null; string messageText = ""; Exception exceptionDetails = null; StreamReader streamReader = null; string line = ""; BloodGlucose bloodGlucose = null; PulseAndOxygen pulseAndOxygen = null; try { SetupLists(); GetFormattedFileName(); if (File.Exists(FilePathName) == true) { streamReader = new StreamReader(FilePathName, Encoding.ASCII); while (streamReader.EndOfStream == false) { line = streamReader.ReadLine(); if (string.IsNullOrEmpty(line) == false) { if (line.StartsWith("PII") == true) { this.personallyIdentifiableInformation = ConvertLogic.ConvertPersonallyIdentifiableInformation(line, '|'); } if (line.StartsWith("PO") == true) { pulseAndOxygen = ConvertLogic.ConvertPulseAndOxygen(line, '|'); if (pulseAndOxygen != null) { this.listPulseAndOxygen.Add(pulseAndOxygen); } } if (line.StartsWith("BG") == true) { bloodGlucose = ConvertLogic.ConvertBloodGlucose(line, '|'); if (bloodGlucose != null) { this.listBloodGlucose.Add(bloodGlucose); } } } } } } catch (Exception exception) { stringBuilder = new StringBuilder(); exceptionDetails = exception; while (exceptionDetails != null) { messageText = "\r\nMessage: " + exceptionDetails.Message + "\r\nSource: " + exceptionDetails.Source + "\r\nStack Trace: " + exceptionDetails.StackTrace + "\r\n----------\r\n"; stringBuilder.Append(messageText); exceptionDetails = exceptionDetails.InnerException; } messageText = stringBuilder.ToString(); throw new Exception(messageText); } finally { if (streamReader != null) { streamReader.Close(); streamReader = null; } } }