private static void SaveGridGanttSettings(SPList list, string internalName, string total) { var gridGanttSettings = new GridGanttSettings(list); var output = new StringBuilder(); var fieldList = gridGanttSettings.TotalSettings.Split('\n'); foreach (var field in fieldList) { if (!string.IsNullOrWhiteSpace(field)) { var fieldData = field.Split('|'); if (fieldData[0] != internalName) { output.Append("\n") .Append(field); } } } output.Append("\n") .Append(internalName) .Append("|") .Append(total); gridGanttSettings.TotalSettings = output.ToString().Trim('\n'); gridGanttSettings.SaveSettings(list); }
private void SaveGridGantSettings(SPList list, string internalName, string advancedLookup, int messageId) { var gSettings = new GridGanttSettings(list); var LookupArray = gSettings.Lookups.Split('|'); var output = new StringBuilder(); foreach (var sLookup in LookupArray) { if (!string.IsNullOrWhiteSpace(sLookup)) { var sLookupInfo = sLookup.Split('^'); if (sLookupInfo[0] != internalName) { output.Append("|") .Append(sLookup); } } } output.Append("|") .Append(internalName) .Append("^") .Append(advancedLookup); gSettings.Lookups = output.ToString().Trim('|'); gSettings.SaveSettings(list); addMessage(ErrorLevels.NoError, "Enabled Advanced Lookup", string.Empty, messageId); }
public override bool Perform() { try { using (var spSite = new SPSite(Web.Site.ID)) { using (SPWeb spWeb = spSite.OpenWeb()) { LogTitle(GetWebInfo(spWeb), 1); SPList spList = spWeb.Lists.TryGetList("Project Center"); if (spList != null) { LogTitle(GetListInfo(spList), 2); var settings = new GridGanttSettings(spList) { EnableRequests = true }; settings.SaveSettings(spList); LogMessage(string.Empty, MessageKind.SUCCESS, 3); } else { LogMessage("Cannot find the Project Center list.", MessageKind.FAILURE, 2); } } } } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 2); } return(true); }
protected void Button1_Click(object sender, EventArgs e) { SPWeb web = SPContext.Current.Web; { StringBuilder sb = new StringBuilder(); SPList list = web.Lists[new Guid(Request.QueryString["List"])]; foreach (Control ctl in pnlFields.Controls) { if (ctl.GetType().ToString() == "System.Web.UI.WebControls.DropDownList") { System.Web.UI.WebControls.DropDownList ddl = (System.Web.UI.WebControls.DropDownList)ctl; if (ddl.SelectedValue != "") { sb.Append(ddl.ID.Substring(3) + "|" + ddl.SelectedValue + "\n"); } } } //if (web.Properties.ContainsKey("epmlivelisttotals-" + System.IO.Path.GetDirectoryName(list.DefaultView.Url))) // web.Properties["epmlivelisttotals-" + System.IO.Path.GetDirectoryName(list.DefaultView.Url)] = sb.ToString(); //else // web.Properties.Add("epmlivelisttotals-" + System.IO.Path.GetDirectoryName(list.DefaultView.Url), sb.ToString()); //web.Properties.Update(); //web.Update(); GridGanttSettings gSettings = new GridGanttSettings(list); gSettings.TotalSettings = sb.ToString(); gSettings.SaveSettings(list); //CoreFunctions.setListSetting(list, "TotalSettings", sb.ToString()); Microsoft.SharePoint.Utilities.SPUtility.Redirect("listedit.aspx?List=" + list.ID.ToString(), Microsoft.SharePoint.Utilities.SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current); } }
protected void Button1_Click(object sender, EventArgs e) { SPList list = Web.Lists[new Guid(Request["List"])]; GridGanttSettings gSettings = new GridGanttSettings(list); string[] LookupArray = gSettings.Lookups.Split('|'); string output = ""; foreach (string sLookup in LookupArray) { if (sLookup != "") { string[] sLookupInfo = sLookup.Split('^'); if (sLookupInfo[0] != Request["field"]) { output += "|" + sLookup; } } } if (chkEnabled.Checked) { output += "|" + Request["field"] + "^" + ddlStyle.SelectedValue + "^" + ddlParentLookup.SelectedValue + "^" + ddlParentLookupField.SelectedValue + "^" + chkSecurity.Checked.ToString().ToLower(); } gSettings.Lookups = output.Trim('|'); gSettings.SaveSettings(list); string lookups = gSettings.Lookups; EnhancedLookupConfigValuesHelper x = new EnhancedLookupConfigValuesHelper(lookups); List <string> lsSecFields = x.GetSecuredFields(); if (lsSecFields.Count > 0) { string assemblyName = "EPM Live Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"; string className = "EPMLiveCore.ItemSecurityEventReceiver"; var evts = CoreFunctions.GetListEvents( list, assemblyName, className, new [] { SPEventReceiverType.ItemAdded, SPEventReceiverType.ItemUpdated, SPEventReceiverType.ItemDeleting }); foreach (SPEventReceiverDefinition evt in evts) { evt.Delete(); } list.EventReceivers.Add(SPEventReceiverType.ItemAdded, assemblyName, className); list.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assemblyName, className); list.EventReceivers.Add(SPEventReceiverType.ItemDeleting, assemblyName, className); list.Update(); } else if (!gSettings.BuildTeamSecurity) { string assemblyName = "EPM Live Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"; string className = "EPMLiveCore.ItemSecurityEventReceiver"; var evts = CoreFunctions.GetListEvents( list, assemblyName, className, new [] { SPEventReceiverType.ItemAdded, SPEventReceiverType.ItemUpdated, SPEventReceiverType.ItemDeleting }); foreach (SPEventReceiverDefinition evt in evts) { evt.Delete(); } list.Update(); } Microsoft.SharePoint.Utilities.SPUtility.Redirect("epmlive/ListLookupConfig.aspx?List=" + Request["List"], Microsoft.SharePoint.Utilities.SPRedirectFlags.RelativeToLayoutsPage, System.Web.HttpContext.Current); }
private void UpdateUI(Guid siteId, Guid webId) { SPWebCollection webCollection; using (SPSite spSite = new SPSite(siteId)) { using (SPWeb spWeb = spSite.OpenWeb(webId)) { LogTitle(GetWebInfo(spWeb), 1); try { string masterUrl = spWeb.MasterUrl; string fileName = Path.GetFileName(masterUrl).ToLower(); if (!fileName.Equals("uplandv5.master")) { var masterpages = new[] { "epmlive", "epmlivemasterv5blue", "masterv43lightbluetop", "masterv43lightbluews", "wetoplevel", "weworkspace", "weworkspacetopnav" }; bool contains = false; foreach (string masterpage in masterpages.Where(mp => (mp + ".master").Equals(fileName))) { contains = true; } if (contains) { ResetFeature(new Guid("046f0200-30e5-4545-b00f-c8c73aef9f0e"), "EPM Live Upland UI", spWeb); ChangeMasterPage("UplandV5", spWeb); } else { LogMessage("The current default MasterPage is not one of EPM Live MasterPage.", MessageKind.SKIPPED, 2); } } else { LogMessage("The default MasterPage is already set to UplandV5.", MessageKind.SKIPPED, 2); } SPList spList = spWeb.Lists.TryGetList("Team"); if (spList != null) { var settings = new GridGanttSettings(spList) { HideNewButton = true }; settings.SaveSettings(spList); } } catch (Exception exception) { LogMessage(exception.Message, MessageKind.FAILURE, 3); } finally { webCollection = spWeb.Webs; } } } if (webCollection == null) { return; } foreach (SPWeb spWeb in webCollection) { try { UpdateUI(siteId, spWeb.ID); } catch (Exception ex) { LogMessage(ex.Message, MessageKind.FAILURE, 3); } finally { if (spWeb != null) { spWeb.Dispose(); } } } }
public override bool Perform() { try { using (var spSite = new SPSite(Web.Site.ID)) { using (SPWeb spWeb = spSite.OpenWeb()) { LogTitle(GetWebInfo(spWeb), 1); var queryExecutor = new QueryExecutor(spWeb); foreach (Guid listId in queryExecutor.GetMappedListIds()) { SPList spList = null; try { spList = spWeb.Lists.GetList(listId, true); } catch { } if (spList == null) { continue; } LogTitle(GetListInfo(spList), 2); var settings = new GridGanttSettings(spList); string reason = string.Empty; switch ((int)spList.BaseTemplate) { case (int)EPMLiveLists.ProjectCenter: reason = "List Definition: Project Center."; break; case (int)EPMLiveLists.TaskCenter: reason = "List Definition: Task Center."; break; default: if (settings.EnableWorkList) { reason = "Work List."; } break; } if (!string.IsNullOrEmpty(reason)) { settings.EnableContentReporting = true; settings.SaveSettings(spList); LogMessage(reason, MessageKind.SUCCESS, 3); } else { LogMessage("List is not a Project Center, Task Center or a Work list.", MessageKind.SKIPPED, 3); } } } } } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 2); } return(true); }
// Private Methods (1) private void UpdateListIcon(Guid siteId, Guid webId) { SPWebCollection webCollection; using (var spSite = new SPSite(siteId)) { using (SPWeb spWeb = spSite.OpenWeb(webId)) { LogTitle(GetWebInfo(spWeb), 1); foreach (var listIcon in _listIcons) { try { SPList spList = spWeb.Lists.TryGetList(listIcon.Key); if (spList != null) { LogTitle(GetListInfo(spList), 2); LogTitle("Icon: " + listIcon.Value, 3); var settings = new GridGanttSettings(spList); if (string.IsNullOrEmpty(settings.ListIcon) || settings.ListIcon.Equals("icon-square")) { settings.ListIcon = listIcon.Value; if (settings.SaveSettings(spList)) { LogMessage(string.Empty, MessageKind.SUCCESS, 4); } else { LogMessage("Could not save the icon.", MessageKind.FAILURE, 4); } } else { LogMessage("The icon is already set to: " + settings.ListIcon, MessageKind.SKIPPED, 4); } } else { LogMessage("The list " + listIcon.Key + " does not exists.", MessageKind.SKIPPED, 3); } } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 2); } } webCollection = spWeb.Webs; } } if (webCollection == null) { return; } foreach (SPWeb spWeb in webCollection) { try { UpdateListIcon(siteId, spWeb.ID); } catch (Exception ex) { LogMessage(ex.ToString(), MessageKind.FAILURE, 2); } finally { if (spWeb != null) { spWeb.Dispose(); } } } }
// Public Methods (1) public override bool Perform() { LogMessage("Loading Resource Pool List"); SPList oResourcePool = SPWeb.Lists.TryGetList("Resources"); SPList oRoles = SPWeb.Lists.TryGetList("Roles"); SPList oDepartments = SPWeb.Lists.TryGetList("Departments"); SPList oHolidaySchedule = SPWeb.Lists.TryGetList("Holiday Schedules"); SPList oWorkHours = SPWeb.Lists.TryGetList("Work Hours"); if (oResourcePool == null) { LogMessage("", "Resources list missing", 3); } else if (oRoles == null) { LogMessage("", "Roles list missing", 3); } else if (oDepartments == null) { LogMessage("", "Departments list missing", 3); } else if (oHolidaySchedule == null) { LogMessage("", "HolidaySchedules list missing", 3); } else if (oWorkHours == null) { LogMessage("", "WorkHours list missing", 3); } else { try { DataTable dtRoles = oRoles.Items.GetDataTable(); DataTable dtDepartments = oDepartments.Items.GetDataTable(); #region Add Temp fields try { if (!oResourcePool.Fields.ContainsFieldWithInternalName("TempRole")) { LogMessage("\tAdding TempRole field"); oResourcePool.Fields.Add("TempRole", SPFieldType.Text, false); SPField oField = oResourcePool.Fields.GetFieldByInternalName("TempRole"); oField.ShowInDisplayForm = false; oField.ShowInEditForm = false; oField.ShowInNewForm = false; oField.Update(); } } catch (Exception ex) { LogMessage("\t", "Adding TempRole field: " + ex.Message, 3); } try { if (!oResourcePool.Fields.ContainsFieldWithInternalName("TempDept")) { LogMessage("\tAdding TempDept field"); oResourcePool.Fields.Add("TempDept", SPFieldType.Text, false); SPField oField = oResourcePool.Fields.GetFieldByInternalName("TempDept"); oField.ShowInDisplayForm = false; oField.ShowInEditForm = false; oField.ShowInNewForm = false; oField.Update(); } } catch (Exception ex) { LogMessage("\t", "Adding TempDept field: " + ex.Message, 3); } oResourcePool.Update(); #endregion #region Process Role and Departments bool bProcessRole = false; bool bProcessDept = false; try { if (oResourcePool.Fields.GetFieldByInternalName("Role").Type == SPFieldType.Choice) { bProcessRole = true; } } catch { } try { if (oResourcePool.Fields.GetFieldByInternalName("Department").Type == SPFieldType.Choice) { bProcessDept = true; } } catch { } SPField oFieldRole; SPField oFieldDept; try { oFieldRole = oResourcePool.Fields.GetFieldByInternalName("Role"); } catch { SPField newField = oResourcePool.Fields.CreateNewField(SPFieldType.Choice.ToString(), "Role"); oResourcePool.Fields.Add(newField); oResourcePool.Update(); oFieldRole = oResourcePool.Fields.GetFieldByInternalName("Role"); } try { oFieldDept = oResourcePool.Fields.GetFieldByInternalName("Department"); } catch { SPField newField = oResourcePool.Fields.CreateNewField(SPFieldType.Choice.ToString(), "Department"); oResourcePool.Fields.Add(newField); oResourcePool.Update(); oFieldDept = oResourcePool.Fields.GetFieldByInternalName("Department"); } if (bProcessRole || bProcessDept) { LogMessage("\tCopying Temporary Data"); foreach (SPListItem li in oResourcePool.Items) { try { if (bProcessDept && li[oFieldDept.Id] != null && oFieldDept.Type == SPFieldType.Choice) { li["TempDept"] = li[oFieldDept.Id].ToString(); } if (bProcessDept && li[oFieldRole.Id] != null && oFieldRole.Type == SPFieldType.Choice) { li["TempRole"] = li[oFieldRole.Id].ToString(); } li.Update(); } catch (Exception ex) { LogMessage("\t", "Error (" + li.Title + "): " + ex.Message, 3); } } } Thread.Sleep(5000); #endregion ProcessFields(ref oResourcePool); oFieldRole = oResourcePool.Fields.GetFieldByInternalName("Role"); oFieldDept = oResourcePool.Fields.GetFieldByInternalName("Department"); LogMessage("\tUpdating Role, Department, Holiday Schedule and Work Hours"); EnumerableRowCollection <DataRow> resourceHSWS = null; EnumerableRowCollection <DataRow> holidaySchedules = null; EnumerableRowCollection <DataRow> workHours = null; try { var dtResourceHSWS = new DataTable(); string connectionString = GetConnectionString(); if (string.IsNullOrEmpty(connectionString)) { throw new Exception("PFE DB connection string is empty."); } using (var sqlConnection = new SqlConnection(connectionString)) { using (var sqlCommand = new SqlCommand(SQL, sqlConnection)) { sqlConnection.Open(); using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) { dtResourceHSWS.Load(sqlDataReader); } } } resourceHSWS = dtResourceHSWS.AsEnumerable(); if (resourceHSWS.Any()) { holidaySchedules = oHolidaySchedule.Items.GetDataTable().AsEnumerable(); workHours = oWorkHours.Items.GetDataTable().AsEnumerable(); } } catch (Exception ex) { LogMessage("\t", "(Get PFE DB ConnectionString): " + ex.Message, 3); } foreach (SPListItem li in oResourcePool.Items) { try { #region Copy Department and Roles if (li["TempDept"] != null && !li["TempDept"].ToString().Contains(";#") && oFieldDept.Type == SPFieldType.Lookup) { DataRow[] dr = dtDepartments.Select("DisplayName='" + li["TempDept"] + "'"); if (dr.Length > 0) { var lv = new SPFieldLookupValue(int.Parse(dr[0]["ID"].ToString()), li["TempDept"].ToString()); li[oFieldDept.Id] = lv; } } if (li["TempRole"] != null && !li["TempRole"].ToString().Contains(";#") && oFieldRole.Type == SPFieldType.Lookup) { DataRow[] dr = dtRoles.Select("Title='" + li["TempRole"] + "'"); if (dr.Length > 0) { var lv = new SPFieldLookupValue(int.Parse(dr[0]["ID"].ToString()), li["TempRole"].ToString()); li[oFieldRole.Id] = lv; } } #endregion string spAccount = string.Empty; var resAcct = li["SharePointAccount"] as string; if (!string.IsNullOrEmpty(resAcct)) { var uv = new SPFieldUserValue(SPWeb, resAcct); if (uv.User != null) { spAccount = uv.User.LoginName.ToLower(); } } string extId = (li["EXTID"] ?? string.Empty).ToString(); if (resourceHSWS != null && resourceHSWS.Any() && !string.IsNullOrEmpty(spAccount)) { try { if (string.IsNullOrEmpty(extId)) { foreach (DataRow row in resourceHSWS) { object acct = row["Account"]; if (acct != null && acct != DBNull.Value) { if (acct.ToString().ToLower().Equals(spAccount)) { li["EXTID"] = (row["ResourceId"] ?? string.Empty).ToString(); break; } } } } } catch (Exception ex) { LogMessage("\t", "(" + li.Title + "): Not setting EXTID. " + ex.Message, 3); } try { foreach (object schedule in from hs in resourceHSWS let account = hs["Account"] where account != null && account != DBNull.Value where account.ToString().ToLower().Equals(spAccount) select hs["HolidaySchedule"] into schedule where schedule != null && schedule != DBNull.Value select schedule) { foreach (DataRow s in holidaySchedules) { object sch = s["Title"]; if (sch == null || sch == DBNull.Value) { continue; } string hsch = sch.ToString(); if (!hsch.ToLower().Equals(schedule.ToString().ToLower())) { continue; } li["HolidaySchedule"] = new SPFieldLookupValue(Convert.ToInt32(s["ID"].ToString()), hsch); break; } } } catch (Exception ex) { LogMessage("\t", "(" + li.Title + "): Not setting Holiday Schedule. " + ex.Message, 3); } try { foreach (object hours in from wh in resourceHSWS let account = wh["Account"] where account != null && account != DBNull.Value where account.ToString().ToLower().Equals(spAccount) select wh["WorkHours"] into hours where hours != null && hours != DBNull.Value select hours) { foreach (DataRow h in workHours) { object hr = h["Title"]; if (hr == null || hr == DBNull.Value) { continue; } string whr = hr.ToString(); if (!whr.ToLower().Equals(hours.ToString().ToLower())) { continue; } li["WorkHours"] = new SPFieldLookupValue( Convert.ToInt32(h["ID"].ToString()), whr); break; } } } catch (Exception ex) { LogMessage("\t", "(" + li.Title + "): Not setting Work Hours. " + ex.Message, 3); } } else { LogMessage("\t", "(" + li.Title + "): Not setting Holiday Schedule and Work Hours. Cannot load from PFE.", 3); } li.Update(); LogMessage("\t\t" + li.Title); } catch (Exception ex) { LogMessage("\t", "(" + li.Title + "): " + ex.Message, 3); } } if (bIsPfe) { using (var workEngineAPI = new WorkEngineAPI()) { LogMessage("Installing PfE Resource Events"); WorkEngineAPI.AddRemoveFeatureEvents( @"<AddRemoveFeatureEvents><Data><Feature Name=""pferesourcemanagement"" Operation=""ADD""/></Data></AddRemoveFeatureEvents>", SPWeb); } } LogMessage("Enabling New Button"); using (var spSite = new SPSite(oResourcePool.ParentWeb.Site.ID)) { using (SPWeb spWeb = spSite.OpenWeb(oResourcePool.ParentWeb.ID)) { SPList resourcePool = spWeb.Lists.GetList(oResourcePool.ID, false); var gSettings = new GridGanttSettings(resourcePool) { HideNewButton = false }; gSettings.SaveSettings(resourcePool); } } LogMessage("Processing Editable Fields"); UpdateField("Generic", true, false, true, ref oResourcePool); UpdateField("FirstName", true, true, true, ref oResourcePool); UpdateField("LastName", true, true, true, ref oResourcePool); UpdateField("Email", true, false, true, ref oResourcePool); UpdateField("ResourceLevel", true, true, true, ref oResourcePool); UpdateField("Permissions", true, true, true, ref oResourcePool); UpdateField("StandardRate", true, true, true, ref oResourcePool); UpdateField("Department", true, true, true, ref oResourcePool); UpdateField("Role", true, true, true, ref oResourcePool); UpdateField("HolidaySchedule", true, true, true, ref oResourcePool); UpdateField("WorkHours", true, true, true, ref oResourcePool); UpdateField("AvailableFrom", true, true, true, ref oResourcePool); UpdateField("AvailableTo", true, true, true, ref oResourcePool); UpdateField("Disabled", false, true, true, ref oResourcePool); } catch (Exception ex) { LogMessage("", "General: " + ex.Message, 3); } } return(true); }
public override bool Perform() { try { using (var spSite = new SPSite(Web.Site.ID)) { foreach (SPWeb spWeb in spSite.AllWebs) { using (SPWeb web = spSite.OpenWeb(spWeb.ID)) { LogTitle(GetWebInfo(web), 1); for (int i = 0; i < web.Lists.Count; i++) { SPList list = web.Lists[i]; if (list.Hidden) { continue; } LogTitle(GetListInfo(list), 2); var settings = new GridGanttSettings(list); try { LogMessage("Enabling fancy forms", 3); ListCommands.EnableFancyForms(list); settings.EnableFancyForms = true; settings.SaveSettings(list); } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 4); } try { LogMessage("Configuring ribbon", 3); settings.RibbonBehavior = list.Title.Equals("Resources") ? "2" : "1"; settings.SaveSettings(list); } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 4); } try { LogMessage("Enabling reporting", 3); if (!SocialEngine.Core.Utilities.IsDefaultIgnoredList(list.Title)) { ListCommands.MapListToReporting(list); } } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 4); } } } } } } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 2); } return(true); }