public void FromCSV(CsvReader csv, SRMCImporter.fileTypes fileType) { switch (fileType) { case SRMCImporter.fileTypes.FT_PEOPLESOFT: FromPeopleSoftCSV(csv); break; case SRMCImporter.fileTypes.FT_PHYSICIANS: FromMDCSV(csv); break; case SRMCImporter.fileTypes.FT_VOLUNTEERS: FromVolCSV(csv); break; } }
/// <summary> /// Construct a record from a CSV reader /// </summary> /// <remarks>Assume that the reader is positioned on a valid record.</remarks> public UserRecord(CsvReader csv, SRMCImporter.fileTypes fileType) { FromCSV(csv, fileType); }
public bool ImportCSV(string path, bool reqApproval) { CsvReader rdr = new CsvReader(new StreamReader(path), false); int newCount = 0; int changeCount = 0; bool firstRecordSeen = false; bool skip = false; SRMCImporter.fileTypes fileType = fileTypes.FT_PEOPLESOFT; using (rdr) { while (rdr.ReadNextRecord()) { if (!firstRecordSeen) { // check the first line of the file to determine what kind of file it is firstRecordSeen = true; if (rdr.FieldCount == 12) { if (rdr[(int)UserRecord.PhyCSVColumns.Role1].StartsWith("All Medical Staff")) { fileType = fileTypes.FT_PHYSICIANS; skip = true; while (rdr[0] != "Last Name") { rdr.ReadNextRecord(); } } else { fileType = fileTypes.FT_PEOPLESOFT; } } else { fileType = fileTypes.FT_PEOPLESOFT; } //switch (rdr[0]) //{ // case "Last name, First name": // fileType = fileTypes.FT_VOLUNTEERS; // skip = true; // break; // case "lastname_of_providers": // break; // default: // fileType = fileTypes.FT_PEOPLESOFT; // break; //} } if (!skip) { UserRecord user = new UserRecord(rdr, fileType); int changeMask = 0; // First let's try to find the user Person person; try { person = (from p in db.Persons where p.EmployeeID == user.EmployeeID select p).First(); } catch (Exception) { person = null; } if (person != null) { // Now let's see if they've changed any of the key fields. if (person.DeptID != user.DeptID) { changeMask = (changeMask | (int)UserRecord.KeyColumnMask.DeptID); } if (person.JobCode != user.JobCode) { changeMask = (changeMask | (int)UserRecord.KeyColumnMask.JobCode); } if (person.Facility != user.Facility) { changeMask = (changeMask | (int)UserRecord.KeyColumnMask.Facility); } if (person.Active != user.Active) { changeMask = (changeMask | (int)UserRecord.KeyColumnMask.Status); } if (changeMask != 0) { changeCount++; } } else { person = new Person(); db.Persons.InsertOnSubmit(person); changeMask = (int)UserRecord.KeyColumnMask.Status; newCount++; } if (changeMask != 0) { person.LastUpdated = DateTime.Today; person.LastUpdateMask = changeMask; person.NeedsRulePass = true; person.NeedsApproval = reqApproval; } person.EmployeeID = user.EmployeeID; person.FirstName = user.FirstName; person.LastName = user.LastName; person.MiddleName = user.MiddleName; person.NickFirst = user.FirstName; person.DeptID = user.DeptID; person.DeptDescr = user.DeptDescription; person.JobCode = user.JobCode; person.JobDescr = user.JobDescription; person.BadgeNumber = user.BadgeNumber; person.Facility = user.Facility; person.Active = user.Active; person.Credentials = (user.HasCredentials && (user.Credentials.Length > 0)) ? user.Credentials : person.Credentials; try { db.SubmitChanges(); } catch (Exception e) { db.Syslog(RSMDataModelDataContext.LogSources.PSIMPORT, RSMDataModelDataContext.LogSeverity.ERROR, string.Format("Associate import failed on file {0}.", path), e.ToString()); return(false); } } else { skip = false; // Only skip the first row. } } } db.Syslog(RSMDataModelDataContext.LogSources.PSIMPORT, RSMDataModelDataContext.LogSeverity.INFO, string.Format("Imported {1} new, {2} changed associates from {0}.", path, newCount, changeCount), ""); return(true); }