コード例 #1
0
        //Saves the medicalProfile in Form1.
        private void saveButton_Click(object sender, EventArgs e)
        {
            MedicalProfileReceived args = new MedicalProfileReceived(medicalProfile);

            ReceivedProfile(this, args);
            this.Dispose();
        }
コード例 #2
0
        //saveTransfer is used when transferForm is done with its work and the "Save" option is clicked.
        private void saveTransfer(object sender, MedicalProfileReceived e)
        {
            String savePath = ((String)Properties.Settings.Default["currentSaveDirectory"]);

            string[] securityDelimiter = new string[1];
            securityDelimiter[0] = "[END]";
            string[] getFixedMedicalProfile = e.medicalProfile.Split(securityDelimiter, System.StringSplitOptions.None);
            string   fixedMedicalProfile    = getFixedMedicalProfile[1];

            string[] delimiter = new string[1];
            delimiter[0] = "[INPUT]";
            string[] nameParsed = fixedMedicalProfile.Split(delimiter, System.StringSplitOptions.None);        //Parses name data to use as the transferred profile's name.
            string   saveFileName;
            int      month = calculateMonth(nameParsed[4]);

            if (nameParsed[1].Equals("[EMPTY]"))        //If no middle name is specified, it is saved as FIRST LAST, otherwise, it is FIRST MIDDLE LAST.
            {
                saveFileName = nameParsed[0] + " " + nameParsed[2] + "   " + month + "-" + nameParsed[5] + "-" + nameParsed[6];
            }
            else
            {
                saveFileName = nameParsed[0] + " " + nameParsed[1] + " " + nameParsed[2] + "   " + month + "-" + nameParsed[5] + "-" + nameParsed[6];
            }
            string nameWithoutExtension = saveFileName;

            saveFileName += ".txt";

            /*if (File.Exists(Path.Combine(savePath, saveFileName))) //TODO: Logic for repeat files. This code never runs.
             * {
             *  int fileExistCount = 1;
             *  string newFileName = saveFileName;
             *  while (File.Exists(savePath + newFileName))
             *  {
             *      newFileName = saveFileName + "(" + fileExistCount + ")";
             *  }
             *  saveFileName = newFileName;
             * }*/
            //Saves medical profile.
            string finalPath = Path.Combine(savePath, saveFileName);

            using (StreamWriter saveFile = File.CreateText(finalPath))
            {
                saveFile.WriteLine("[MEDICALFILETRANSFER][END]" + fixedMedicalProfile.Trim() + "[END]");
            }
            fillComponents();
            this.filesListBox.SetSelected(this.filesListBox.Items.IndexOf(nameWithoutExtension), true);
        }