private bool Filter(RecordUserProfile record, string filter) { string strFilter = filter.Trim().ToLower(); if (filter.Length < 1) { return(true); } if (record.LastName.ToLower().Contains(strFilter)) { return(true); } if (record.FirstName.ToLower().Contains(strFilter)) { return(true); } if (record.EmailWork.ToLower().Contains(strFilter)) { return(true); } if (record.SeparateDivision.ToLower().Contains(strFilter)) { return(true); } if (record.Position.ToLower().Contains(strFilter)) { return(true); } // Check phone string strPhoneFilter = filter.Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", ""); string strPhone = record.PhoneWork.Trim().ToLower().Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", ""); if (strPhone.Contains(strPhoneFilter)) { return(true); } return(false); }
private object OrderBy(string sortKey, RecordUserProfile record) { if (sortKey == "ID") { return(record.ID); } else if (sortKey == "AccountName") { return(record.AccountName); } else if (sortKey == "LastName") { return(record.LastName); } else if (sortKey == "FirstName") { return(record.FirstName); } else if (sortKey == "MiddleName") { return(record.MiddleName); } else if (sortKey == "Birthday") { return(record.BirthdayDT); } else if (sortKey == "SSN") { return(record.SSN); } else if (sortKey == "INN") { return(record.INN); } else if (sortKey == "Organization") { return(record.Organization); } else if (sortKey == "SubDivision") { return(record.SubDivision); } else if (sortKey == "SeparateDivision" || sortKey == "Office") { return(record.SeparateDivision); } else if (sortKey == "Position" || sortKey == "JobPosition" || sortKey == "Title" || sortKey == "JobTitle") { return(record.Position); } else if (sortKey == "EmailWork" || sortKey == "WorkEmail") { return(record.EmailWork); } else if (sortKey == "EmailHome" || sortKey == "HomeEmail") { return(record.EmailHome); } else if (sortKey == "PhoneWork" || sortKey == "WorkPhone") { return(record.PhoneWork); } else if (sortKey == "PhoneHome" || sortKey == "HomePhone") { return(record.PhoneHome); } else if (sortKey == "EmploymentDate" || sortKey == "Employed" || sortKey == "DateOfEmployment") { return(record.EmploymentDate); } else if (sortKey == "Merit" || sortKey == "Merits") { return(record.BestWorkerMerit); } else { return(""); } }
public void ReadSqlSPProfiles(string strConnectionString, string strSiteProfiles) { this.Clear(); SqlConnection sqlConnection = new SqlConnection(strConnectionString); SqlDataAdapter daProfiles = new SqlDataAdapter("SELECT [RecordID], [UserID], [NTName], [PreferredName], [Email], [Manager], [PictureUrl] " + "FROM dbo.UserProfile_Full " + "WHERE [bDeleted] = 0", sqlConnection); SqlDataAdapter daPropertyValues = new SqlDataAdapter("SELECT [RecordID], [PropertyName], [PropertyVal] " + "FROM dbo.PropertyList AS pl, dbo.UserProfileValue AS pv " + "WHERE pv.PropertyID = pl.PropertyID", sqlConnection); DataTable tableProfiles = new DataTable(); DataTable tablePropertyValues = new DataTable(); sqlConnection.Open(); daProfiles.Fill(tableProfiles); daPropertyValues.Fill(tablePropertyValues); sqlConnection.Close(); // Read data foreach (DataRow rowProfile in tableProfiles.Rows) { long id = 0; try { id = Convert.ToInt64(rowProfile["RecordID"]); } catch { continue; } DataRow[] rowPropValues = tablePropertyValues.Select("RecordID = " + id.ToString()); RecordUserProfile rp = new RecordUserProfile(); string strDisplayName = rowProfile["PreferredName"].ToString(); rp.AccountName = rowProfile["NTName"].ToString(); foreach (DataRow rowValue in rowPropValues) { if (rowValue["PropertyName"] == null || rowValue["PropertyName"] == DBNull.Value) { continue; } if (rowValue["PropertyVal"] == null || rowValue["PropertyVal"] == DBNull.Value) { continue; } string strName = rowValue["PropertyName"].ToString().Trim(); string strVal = rowValue["PropertyVal"].ToString(); rp.SetProperty(strName, strVal); } if (rp.AccountName == null || rp.AccountName.ToUpper().IndexOf("\\SM_") >= 0 || rp.AccountName.ToUpper().IndexOf("\\SP_") >= 0 || rp.AccountName == strDisplayName || rp.LastName.Trim().Length < 1) { continue; } rp.ProfileURL = strSiteProfiles + "/" + "Person.aspx?accountname=" + System.Web.HttpUtility.UrlEncode(rp.AccountName); Add(rp); } this._bEmpty = false; }
public void Add(RecordUserProfile recordUserProfile) { recordUserProfile._ID = ++_ulID; userProfiles.Add(recordUserProfile); }
public void Add(UserProfile userProfile) { RecordUserProfile record = new RecordUserProfile(userProfile); Add(record); }
private bool Filter(RecordUserProfile record, string filter) { string strFilter = filter.Trim().ToLower(); if (filter.Length < 1) return true; if (record.LastName.ToLower().Contains(strFilter)) return true; if (record.FirstName.ToLower().Contains(strFilter)) return true; if (record.EmailWork.ToLower().Contains(strFilter)) return true; if (record.SeparateDivision.ToLower().Contains(strFilter)) return true; if (record.Position.ToLower().Contains(strFilter)) return true; // Check phone string strPhoneFilter = filter.Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", ""); string strPhone = record.PhoneWork.Trim().ToLower().Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", ""); if (strPhone.Contains(strPhoneFilter)) return true; return false; }
private object OrderBy(string sortKey, RecordUserProfile record) { if (sortKey == "ID") return record.ID; else if (sortKey == "AccountName") return record.AccountName; else if (sortKey == "LastName") return record.LastName; else if (sortKey == "FirstName") return record.FirstName; else if (sortKey == "MiddleName") return record.MiddleName; else if (sortKey == "Birthday") return record.BirthdayDT; else if (sortKey == "SSN") return record.SSN; else if (sortKey == "INN") return record.INN; else if (sortKey == "Organization") return record.Organization; else if (sortKey == "SubDivision") return record.SubDivision; else if (sortKey == "SeparateDivision" || sortKey == "Office") return record.SeparateDivision; else if (sortKey == "Position" || sortKey == "JobPosition" || sortKey == "Title" || sortKey == "JobTitle") return record.Position; else if (sortKey == "EmailWork" || sortKey == "WorkEmail") return record.EmailWork; else if (sortKey == "EmailHome" || sortKey == "HomeEmail") return record.EmailHome; else if (sortKey == "PhoneWork" || sortKey == "WorkPhone") return record.PhoneWork; else if (sortKey == "PhoneHome" || sortKey == "HomePhone") return record.PhoneHome; else if (sortKey == "EmploymentDate" || sortKey == "Employed" || sortKey == "DateOfEmployment") return record.EmploymentDate; else if (sortKey == "Merit" || sortKey == "Merits") return record.BestWorkerMerit; else return ""; }
public void ReadSqlSPProfiles(string strConnectionString, string strSiteProfiles) { this.Clear(); SqlConnection sqlConnection = new SqlConnection(strConnectionString); SqlDataAdapter daProfiles = new SqlDataAdapter("SELECT [RecordID], [UserID], [NTName], [PreferredName], [Email], [Manager], [PictureUrl] " + "FROM dbo.UserProfile_Full " + "WHERE [bDeleted] = 0", sqlConnection); SqlDataAdapter daPropertyValues = new SqlDataAdapter("SELECT [RecordID], [PropertyName], [PropertyVal] " + "FROM dbo.PropertyList AS pl, dbo.UserProfileValue AS pv " + "WHERE pv.PropertyID = pl.PropertyID", sqlConnection); DataTable tableProfiles = new DataTable(); DataTable tablePropertyValues = new DataTable(); sqlConnection.Open(); daProfiles.Fill(tableProfiles); daPropertyValues.Fill(tablePropertyValues); sqlConnection.Close(); // Read data foreach (DataRow rowProfile in tableProfiles.Rows) { long id = 0; try { id = Convert.ToInt64(rowProfile["RecordID"]); } catch { continue; } DataRow[] rowPropValues = tablePropertyValues.Select("RecordID = " + id.ToString()); RecordUserProfile rp = new RecordUserProfile(); string strDisplayName = rowProfile["PreferredName"].ToString(); rp.AccountName = rowProfile["NTName"].ToString(); foreach (DataRow rowValue in rowPropValues) { if (rowValue["PropertyName"] == null || rowValue["PropertyName"] == DBNull.Value) continue; if (rowValue["PropertyVal"] == null || rowValue["PropertyVal"] == DBNull.Value) continue; string strName = rowValue["PropertyName"].ToString().Trim(); string strVal = rowValue["PropertyVal"].ToString(); rp.SetProperty(strName, strVal); } if (rp.AccountName == null || rp.AccountName.ToUpper().IndexOf("\\SM_") >= 0 || rp.AccountName.ToUpper().IndexOf("\\SP_") >= 0 || rp.AccountName == strDisplayName || rp.LastName.Trim().Length < 1) continue; rp.ProfileURL = strSiteProfiles + "/" + "Person.aspx?accountname=" + System.Web.HttpUtility.UrlEncode(rp.AccountName); Add(rp); } this._bEmpty = false; }
/// <summary> /// Creates new SharePoint user profile record /// </summary> /// <param name="site">SPSite object</param> /// <param name="upm">UserProfileManager object</param> /// <param name="profile">Profile record (imported from 1C) to be added</param> /// <param name="subType">Type of UserProfile</param> /// <returns>true on success, false on failed</returns> bool CreateUserProfile(SPSite site, UserProfileManager upm, RecordUserProfile profile, ProfileSubtype subType) { UserProfile p = null; string strAccountName = ""; string strDisplayName = ""; try { // create a user profile and set properties if (profile.AccountName.Trim().Length > 0) strAccountName = profile.AccountName; else strAccountName = string.Format("SqlMembershipProvider:imported1c{0}", ++nAccount); strDisplayName = string.Format("{0} {1}{2}", profile.FirstName.Trim(), (profile.MiddleName.Trim().Length > 0) ? (profile.MiddleName.Trim() + " ") : (""), profile.LastName); p = upm.CreateUserProfile(strAccountName); p.DisplayName = strDisplayName; WriteSPProfileField(ref p, "FirstName", profile.FirstName); WriteSPProfileField(ref p, "LastName", profile.LastName); WriteSPProfileField(ref p, "SPS-Birthday", profile.Birthday); WriteSPProfileField(ref p, "WorkPhone", profile.PhoneWork); WriteSPProfileField(ref p, "HomePhone", profile.PhoneHome); WriteSPProfileField(ref p, "WorkEmail", profile.EmailWork); WriteSPProfileField(ref p, "Office", profile.SeparateDivision); WriteSPProfileField(ref p, "Department", profile.SubDivision); WriteSPProfileField(ref p, "Title", profile.Position); WriteSPProfileField(ref p, "SPS-JobTitle", profile.Position); WriteSPProfileField(ref p, "SPS-HireDate", profile.DateOfEmployment); // Custom fields WriteSPProfileField(ref p, "Mr-MiddleName", profile.MiddleName); WriteSPProfileField(ref p, "Mr-Inn", profile.INN); WriteSPProfileField(ref p, "Mr-Ssn", profile.SSN); WriteSPProfileField(ref p, "Mr-Organization", profile.Organization); // Photos if (profile.Photo != null) { if (imageUploader != null) { imageUploader.UploadPhoto(p, profile.Photo); string pictureUrl = String.Format("{0}/{1}/{2}_MThumb.jpg", site.Url, imageUploader.GetSubfolderName(), imageUploader.GetFileNameFromAccount(p)); p["PictureUrl"].Value = pictureUrl; } } else { } p.ProfileSubtype = subType; p.Commit(); } catch (Exception ex) { string sError = string.Format("CreateUserProfile() The error was occured while updating profile:\nAccount name: {0}\nDisplayName: {1}\nError:\n\n{2}\n---\n", strAccountName, strDisplayName, ex.ToString()); TextWriter errorWriter = Console.Error; Console.WriteLine(sError); errorWriter.WriteLine(sError); return false; } return true; }
/// <summary> /// Updates existing SharePoint user profile /// </summary> /// <param name="site">SPSite objec</param> /// <param name="p">The existing SP profile to be updated</param> /// <param name="profile">Profile record, which is imported from 1C</param> /// <returns>true on success, false on failed</returns> bool UpdateUserProfile(SPSite site, UserProfile p, RecordUserProfile profile) { string strDisplayName = ""; try { strDisplayName = string.Format("{0} {1}{2}", profile.FirstName.Trim(), (profile.MiddleName.Trim().Length > 0) ? (profile.MiddleName.Trim() + " ") : (""), profile.LastName); if (Properties.Settings.Default.updateProfileDisplayName && p.DisplayName != strDisplayName) p.DisplayName = strDisplayName; if (Properties.Settings.Default.updateFirstName) UpdateSPStringProfileField(ref p, "FirstName", profile.FirstName); if (Properties.Settings.Default.updateLastName) UpdateSPStringProfileField(ref p, "LastName", profile.LastName); if (Properties.Settings.Default.updateBirthday) UpdateSPProfileField(ref p, "SPS-Birthday", profile.Birthday); if (Properties.Settings.Default.updatePhoneWork) UpdateSPStringProfileField(ref p, "WorkPhone", profile.PhoneWork); if (Properties.Settings.Default.updatePhoneHome) UpdateSPStringProfileField(ref p, "HomePhone", profile.PhoneHome); if (Properties.Settings.Default.updateEmailWork) UpdateSPStringProfileField(ref p, "WorkEmail", profile.EmailWork); if (Properties.Settings.Default.updateSeparateDivision) UpdateSPStringProfileField(ref p, "Office", profile.SeparateDivision); if (Properties.Settings.Default.updateSubDivision) UpdateSPStringProfileField(ref p, "Department", profile.SubDivision); if (Properties.Settings.Default.updatePosition) { UpdateSPStringProfileField(ref p, "Title", profile.Position); UpdateSPStringProfileField(ref p, "SPS-JobTitle", profile.Position); } if (Properties.Settings.Default.updateDateOfEmployment && profile.EmploymentDate != null) UpdateSPProfileField(ref p, "SPS-HireDate", profile.EmploymentDate); // Custom fields if (Properties.Settings.Default.updateMiddleName) UpdateSPStringProfileField(ref p, "Mr-MiddleName", profile.MiddleName); if (Properties.Settings.Default.updateINN) UpdateSPStringProfileField(ref p, "Mr-Inn", profile.INN); if (Properties.Settings.Default.updateSSN) UpdateSPStringProfileField(ref p, "Mr-Ssn", profile.SSN); if (Properties.Settings.Default.updateOrganization) UpdateSPStringProfileField(ref p, "Mr-Organization", profile.Organization); // Photos if (Properties.Settings.Default.updatePhoto && profile.Photo != null) { if (Properties.Settings.Default.forceUpdatePhoto == true || p["PictureUrl"].Value == null || p["PictureUrl"].Value.ToString().Length < 1) { if (imageUploader != null) { imageUploader.UploadPhoto(p, profile.Photo); string pictureUrl = String.Format("{0}/{1}/{2}_MThumb.jpg", site.Url, imageUploader.GetSubfolderName(), imageUploader.GetFileNameFromAccount(p)); WriteSPProfileField(ref p, "PictureUrl", pictureUrl); } } } else { if (Properties.Settings.Default.forceUpdatePhoto == true && p["PictureUrl"].Value != null && p["PictureUrl"].Value.ToString().Length > 0) { // TODO: Remove image? WriteSPProfileField(ref p, "PictureUrl", null); } } p.Commit(); } catch (Exception ex) { string sError = string.Format("UpdateUserProfile() The error was occured while updating profile:\nAccount name: {0}\nDisplayName: {1}\nError:\n\n{2}\n---\n", (p != null && p["AccountName"].Value != null) ? (" \"" + p["AccountName"].Value.ToString() + "\"") : (""), strDisplayName, ex.ToString()); TextWriter errorWriter = Console.Error; Console.WriteLine(sError); errorWriter.WriteLine(sError); return false; } return true; }
/// <summary> /// Finds SP UserProfile by: Last Name, First Name, Middle Nam and Birthday /// </summary> /// <param name="profile">RecordUserProfile record wich is imported from 1C</param> /// <returns>Returns RecordUserProfile (which is imported from SP) if found, otherwise returns null</returns> RecordUserProfile GetProfileByPersonName(RecordUserProfile profile) { foreach (RecordUserProfile profileRecord in usersExisting.GetProfiles()) { if (profileRecord.FirstName.Trim().ToLower() == profile.FirstName.Trim().ToLower() && profileRecord.MiddleName.Trim().ToLower() == profile.MiddleName.Trim().ToLower() && profileRecord.LastName.Trim().ToLower() == profile.LastName.Trim().ToLower() && DateTime.Compare(profileRecord.BirthdayDT, profile.BirthdayDT) == 0) return profileRecord; } return null; }
/// <summary> /// Finds SP UserProfile by INN /// </summary> /// <param name="profile">RecordUserProfile record wich is imported from 1C</param> /// <returns>Returns RecordUserProfile (which is imported from SP) if found, otherwise returns null</returns> RecordUserProfile GetProfileByINN(RecordUserProfile profile) { string sINN = profile.INN.Trim().ToLower(); foreach (RecordUserProfile profileRecord in usersExisting.GetProfiles()) { if (profileRecord.INN.Trim().ToLower() == sINN) return profileRecord; } return null; }