private void btnDone1_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you have completed the assessment ?", "Message", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (isPrescriptionWritten(patient_username1, 1)) { errorProvider1.Clear(); StreamWriter sw = null; StreamReader sr = null; int EmptyLines; EmptyLines = readEmptyLines(Doc_username, 0); string line; //useful string try { sw = new StreamWriter(Doctor_path + "temp.txt"); sr = new StreamReader(Doctor_path + Doc_username + ".txt"); } catch { MessageBox.Show("Unable to Open File"); } while (true) { line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) //first patient is written after one space { break; } sw.WriteLine(line); } line = sr.ReadLine(); while (true) { line = sr.ReadLine(); if (line == null) { break; } sw.WriteLine(line); } sr.Close(); sw.Close(); File.Delete(Doctor_path + Doc_username + ".txt"); File.Move(Doctor_path + "temp.txt", Doctor_path + Doc_username + ".txt"); MessageBox.Show("Assessment done", "MESSAGE", MessageBoxButtons.OK, MessageBoxIcon.Information); AssessmentDone done = new AssessmentDone(Patient_path, this.patient_username1); done.ShowDialog(); clearTextBoxes(); manageTextBoxes(); } } }
private void btnDone2_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you have completed the assessment ?", "Message", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (isPrescriptionWritten(patient_username2, 2)) { errorProvider1.Clear(); StreamReader sr = null; StreamWriter sw = null; string line; int count = 0; try { sw = new StreamWriter(Doctor_path + "temp.txt"); sr = new StreamReader(Doctor_path + Doc_username + ".txt"); } catch { MessageBox.Show("Unable to Open File"); } while (true) { line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) //beacause second patient is written after 2 spaces { count += 1; if (count == 2) { break; } } sw.WriteLine(line); } line = sr.ReadLine(); while ((line = sr.ReadLine()) != null) { sw.WriteLine(line); } sr.Close(); sw.Close(); File.Delete(Doctor_path + Doc_username + ".txt"); File.Move(Doctor_path + "temp.txt", Doctor_path + Doc_username + ".txt"); AssessmentDone done = new AssessmentDone(Patient_path, this.patient_username2); done.ShowDialog(); clearTextBoxes(); manageTextBoxes(); } } }//Done 2 bracket