private void btnImport_Click(object sender, EventArgs e) { string recordTypeName = null; if (comboImportOptions.SelectedIndex == 0) { recordTypeName = txtRecordTypeName.Text; } else if (comboImportOptions.SelectedIndex == 1) { recordTypeName = comboRecordTypeSelector.SelectedText; } var selectedHeaders = new Dictionary <int, string>(); foreach (DataGridViewRow row in gridFieldAssignment.Rows) { if (row.Cells[0].Value != null && ValidRow(row)) { var colIndex = Convert.ToInt32(row.Cells[0].Value); var attrName = row.Cells[1].Value.ToString(); selectedHeaders.Add(colIndex, attrName); } } StatusObject importStatus = null; if (comboImportOptions.SelectedIndex == 0) { RecordType rT = null; using (var oH = new ObjectHelper(_dbSettings, _user)) { var addRecordTypeStatus = oH.AddRecordType(recordTypeName, selectedHeaders.Values.ToList(), true); if (addRecordTypeStatus.Success) { var fetchRecordType = oH.GetRecordTypeById((int)addRecordTypeStatus.Result); if (fetchRecordType.Success) { rT = (RecordType)fetchRecordType.Result; } } } if (rT != null) { var records = _dP.GetRecordsFromSheet(rT, selectedHeaders, _fileImportPath); if (records.Length > 0) { using (var oH = new ObjectHelper(_dbSettings, _user)) { importStatus = oH.AddRecords(records, rT); } } } } else { var rT = _recordTypes.First(x => x.Name.Equals(comboRecordTypeSelector.SelectedItem)); var records = _dP.GetRecordsFromSheet(rT, selectedHeaders, _fileImportPath); if (records.Length > 0) { using (var oH = new ObjectHelper(_dbSettings, _user)) { importStatus = oH.AddRecords(records, rT); } } } if (importStatus != null && importStatus.Success) { NotificationHelper.ShowNotification(this, NotificationHelper.NotificationType.Information, "Successfully imported " + (int)importStatus.Result + " records!"); } else { NotificationHelper.ShowNotification(this, NotificationHelper.NotificationType.Error, "Failed to import records. Please try again."); } }