private async void btnSave_Click(object sender, EventArgs e) { if (IsValidForm()) { try { string fileName = null; if (txtPdfName.Text.Trim() != string.Empty) { fileName = PdfName(); } //Try to save pdf to folder if (fileName != null) { if (File.Exists(txtPdfName.Text.Trim())) { _pdfSettings.CreateFile(fileName, txtPdfName.Text.Trim()); } else { MessageBox.Show($"The pdf you want to save has been \n moved from the location {txtPdfName.Text.Trim()}\n Please check the file again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } //Save the file to the database string[] regNo = txtRegistryNumber.Text.Split('-'); IncomingFileModel fileModel = new IncomingFileModel() { RegistryNumber = int.Parse(regNo[2]), DateReceived = dtpDateReceived.Value, PersonSent = txtPersonSent.Text.Trim().ToLower(), DateOfLetter = dtpDateofLetter.Value, Subject = txtSubject.Text.Trim().ToLower(), DepartmentSent = txtFromDepartment.Text.Trim().ToLower(), Department = (DepartmentModel)cboDepartment.SelectedItem, FileName = fileName }; MessageBox.Show(fileModel.RegistryNumber.ToString()); if (txtReferenceNumber.Text.Trim() != string.Empty) { fileModel.ReferenceNumber = txtReferenceNumber.Text.Trim(); } if (txtRemarks.Text.Trim() != string.Empty) { fileModel.Remarks = txtRemarks.Text.Trim(); } //Save the file to the database await _incomingFile.CreateIncomingFile(fileModel); Logger.WriteToFile(Logger.FullName, "successfully registered a file"); LoadAllFiles(); ResetControls(); if (MessageBox.Show("File information has been successfully saved.\n Do you want to perform another save?", "Save File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { this.Close(); } } catch (Exception ex) { MessageBox.Show($"Sorry an error occured. \n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }