private void butExportMedications_Click(object sender, EventArgs e) { if (!Security.IsAuthorized(Permissions.Setup)) { return; } int countExportedMeds = 0; string fileName; if (ODBuild.IsWeb()) { fileName = "ExportedMedications.txt"; } else { //Prompt for file. fileName = GetFilenameFromUser(false); } if (string.IsNullOrEmpty(fileName)) { return; } try { Cursor = Cursors.WaitCursor; countExportedMeds = MedicationL.ExportMedications(fileName, Medications.GetList()); } catch (Exception ex) { Cursor = Cursors.Default; string msg = Lans.g(this, "Error: "); MessageBox.Show(this, msg + ": " + ex.Message); } Cursor = Cursors.Default; MessageBox.Show(this, POut.Int(countExportedMeds) + " " + Lan.g(this, "medications exported to:") + " " + fileName); }
///<summary>Attempts to download the default medication list from HQ. ///If there is an exception returns an empty list after showing the user an error prompt.</summary> private List <ODTuple <Medication, string> > DownloadDefaultMedications() { List <ODTuple <Medication, string> > listMedsNew = new List <ODTuple <Medication, string> >(); string tempFile = ""; try { tempFile = MedicationL.DownloadDefaultMedicationsFile(); listMedsNew = MedicationL.GetMedicationsFromFile(tempFile, true); } catch (Exception ex) { MessageBox.Show(Lan.g(this, "Failed to download medications.") + "\r\n" + ex.Message); } return(listMedsNew); }
private void butImportMedications_Click(object sender, EventArgs e) { if (!Security.IsAuthorized(Permissions.Setup)) { return; } List <ODTuple <Medication, string> > listImportMeds = new List <ODTuple <Medication, string> >(); //Leaving code here to include later when we have developed a default medications list available for download. //if(MsgBox.Show(this,MsgBoxButtons.YesNo,"Click Yes to download and import default medication list.\r\nClick No to import from a file.")) { // Cursor=Cursors.WaitCursor; // listImportMeds=DownloadDefaultMedications();//Import from OpenDental.com //} //else {//Prompt for file. string fileName = GetFilenameFromUser(true); if (string.IsNullOrEmpty(fileName)) { return; } try { Cursor = Cursors.WaitCursor; listImportMeds = MedicationL.GetMedicationsFromFile(fileName); } catch (Exception ex) { Cursor = Cursors.Default; string msg = Lans.g(this, "Error accessing file. Close all programs using file and try again."); MessageBox.Show(this, msg + "\r\n: " + ex.Message); return; } //} int countImportedMedications = MedicationL.ImportMedications(listImportMeds, Medications.GetList()); int countDuplicateMedications = listImportMeds.Count - countImportedMedications; DataValid.SetInvalid(InvalidType.Medications); Cursor = Cursors.Default; MessageBox.Show(this, POut.Int(countDuplicateMedications) + " " + Lan.g(this, "duplicate medications found.") + "\r\n" + POut.Int(countImportedMedications) + " " + Lan.g(this, "medications imported.")); FillTab(); }