Exemple #1
0
        private void btnImportData_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog theDialog = new OpenFileDialog();

            theDialog.Title  = "Open Excel File";
            theDialog.Filter = "Excel files (.xls)|*.xls";
            ChangeStatusText("Importing data. Please wait...");
            if (theDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try {
                    var softText = File.ReadAllText(theDialog.FileName);
                    CaselyData.SoftPathExcelConvert sc = new SoftPathExcelConvert();
                    var importedData = sc.importSoftPathCSVData(theDialog.FileName);

                    var caselyUserDataEntriesToAdd = new List <CaseEntry>();
                    int casesImportedCount         = 0;
                    int casesAlreadImported        = 0;
                    foreach (var d in importedData)
                    {
                        // Import the cases only if there is not already a report version by both the attending and the resident.
                        if (!(SqliteDataAcces.HasMultipleAuthorEntries(d.CaseNumber)))
                        {
                            caselyUserDataEntriesToAdd.Add(d);
                            casesImportedCount++;
                        }
                        else
                        {
                            casesAlreadImported++;
                        }
                    }
                    SqliteDataAcces.BatchInsertNewCaseEntry(caselyUserDataEntriesToAdd);


                    System.Windows.Forms.MessageBox.Show($"{casesImportedCount/2} cases imported. {casesAlreadImported} already existed in Casely.");
                } catch (Exception ex) {
                    System.Windows.MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
                ChangeStatusText("");
            }
        }