Sie sind auf Seite 1von 7

using using using using using using using using using using using using using using using

using using

System; System.ComponentModel; System.ComponentModel.Design; System.Collections; System.Drawing; System.Linq; System.Workflow.ComponentModel.Compiler; System.Workflow.ComponentModel.Serialization; System.Workflow.ComponentModel; System.Workflow.ComponentModel.Design; System.Workflow.Runtime; System.Workflow.Activities; System.Workflow.Activities.Rules; Microsoft.SharePoint; Microsoft.SharePoint.Workflow; Microsoft.SharePoint.WorkflowActions; Microsoft.Office.Workflow.Utility;

namespace SolicitacaoMudanca34 { public sealed partial class Workflow1 : SequentialWorkflowActivity { public Workflow1() { InitializeComponent(); } public Guid workflowId = default(System.Guid); public SPWorkflowActivationProperties workflowProperties = new SPWorkflo wActivationProperties(); private void onWorkflowActivated1_Invoked(object sender, ExternalDataEve ntArgs e) { SPList myList = workflowProperties.List; SPField titleField = myList.Fields.GetField("Status"); titleField.ShowInEditForm = false; titleField.ShowInDisplayForm = true; titleField.ShowInNewForm = false; titleField.Update(); SPField titleField1 = myList.Fields.GetField("Escolh"); titleField1.ShowInEditForm = true; titleField1.ShowInDisplayForm = false; titleField1.ShowInNewForm = false; titleField1.Update(); SPField titleField2 = myList.Fields.GetField("Justificativa"); titleField2.ShowInEditForm = true; titleField2.ShowInDisplayForm = false; titleField2.ShowInNewForm = false; titleField2.Update(); SPField titleField3 = myList.Fields.GetField("Historico");

titleField3.ShowInEditForm = false; titleField3.ShowInDisplayForm = true; titleField3.ShowInNewForm = false; titleField3.Update(); SPField titleField4 = myList.Fields.GetField("Titulo"); titleField4.ShowInEditForm = false; titleField4.ShowInDisplayForm = true; titleField4.ShowInNewForm = true; titleField4.Update(); SPField titleField5 = myList.Fields.GetField("Descricao"); titleField5.ShowInEditForm = false; titleField5.ShowInDisplayForm = true; titleField5.ShowInNewForm = true; titleField5.Update(); SPField titleField6 = myList.Fields.GetField("Autor"); titleField6.ShowInEditForm = false; titleField6.ShowInDisplayForm = true; titleField6.ShowInNewForm = false; titleField6.Update(); SPField titleField7 = myList.Fields.GetField("Conta"); titleField7.ShowInEditForm = false; titleField7.ShowInDisplayForm = true; titleField7.ShowInNewForm = false; titleField7.Update(); } private void codigo1_ExecuteCode(object sender, EventArgs e) { bool ISADMIN = false; if (workflowProperties.Item.Fields.ContainsField("Escolha") && workf lowProperties.Item.Fields.ContainsField("Justificativa") && workflowProperties.I tem["Escolha"] != null && workflowProperties.Item["Justificativa"] != null) { this.RetornaAdmin(); ISADMIN = this.DoesUserHavePermissions(); } string escolha = workflowProperties.Item.GetFormattedValue("Escolh") ; string justificativa = workflowProperties.Item.GetFormattedValue("Ju stificativa"); string modificadoPor = workflowProperties.Item.GetFormattedValue("Mo dificado por"); var teste = String.Format("<div style=font-size=18px;font-family:Ari al;background-color:#8B7D6B;font-weight:bold;left:50%;top:50%;position: absolute

;><font color=#ffffff>Modificado em: {0}</div>" + "<div style=font-size:14px;font-family:Arial;ba ckground-color:#C1CDCD><font color=#1C1C1C><br><b>Escolha:</b>{1}</font><br><fon t color=#1C1C1C> <b>Justificativa:</b> {2}</font> <br><font color=#1C1C1C> <b>In tegrante CCM:</b> {3}</font></div>", DateTime.Now, escolha, justificativa, modif icadoPor); var teste2 = String.Format("<div style=font-size=18px;font-family:Ar ial;background-color:#8B4726;font-weight:bold;left:50%;top:50%;position: absolut e;><font color=#ffffff>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; M udana na deciso do Gestor </div>" + "<div style=font-size=18px;font-family:Arial;b ackground-color:#8B7D6B;font-weight:bold;left:50%;top:50%;position: absolute;><f ont color=#ffffff>Modificado em: {0}</div>" + "<div style=font-size:14px;font-family:Arial;background-color:#C1CDC D><font color=#1C1C1C><br><b>Escolha:&nbsp;</b>{1}</font><br><font color=#1C1C1C > <b>Justificativa:&nbsp;</b> {2}</font> <br><font color=#1C1C1C> <b>Integrante CCM:&nbsp;</b> {3}</font></div>", DateTime.Now, escolha, justificativa, modifica doPor); if (workflowProperties.Item.Fields.ContainsField("Status") && workfl owProperties.Item["Status"] != null) { //STATUS PENDENTE if (workflowProperties.Item["Status"].Equals("Pendente")) { /*if (autor != null && conta != null && autor == conta)*/ /*if(this.DoesUserHavePermissions().Equals(true))*/ if(ISADMIN == true) { this.codigo2_ExecuteCode(sender, e); } /*else if (autor != null && conta != null && autor != conta) */ /*else if(this.DoesUserHavePermissions().Equals(false))*/ else if(ISADMIN == false) { this.codigo4_ExecuteCode(sender, e); } } //STATUS APROVADO else if (workflowProperties.Item["Status"].Equals("Aprovado")) { /*if (autor != null && conta != null && autor == conta)*/ /*if(this.DoesUserHavePermissions().Equals(true))*/ if(ISADMIN == true) { if (workflowProperties.Item.Fields.ContainsField("Escolh ") && workflowProperties.Item["Escolh"] != null && (workflowProperties.Item["Esc olh"].Equals("Aprovado") workflowProperties.Item["Escolh"].Equals("Rejeitado" ))) { workflowProperties.Item["Historico"] += teste2; workflowProperties.Item["Status"] = "Pendente"; workflowProperties.Item.SystemUpdate();

this.codigo3_ExecuteCode(sender, e); } } /*else if (autor != null && conta != null && autor != conta) */ /* else if(this.DoesUserHavePermissions().Equals(false))*/ else if(ISADMIN == false) { if (workflowProperties.Item.Fields.ContainsField("Escolh ") && workflowProperties.Item["Escolh"] != null && (workflowProperties.Item["Esc olh"].Equals("Aprovado") workflowProperties.Item["Escolha"].Equals("Rejeitado "))) { this.codigo3_ExecuteCode(sender, e); } } } //STATUS REJEITADO else if (workflowProperties.Item["Status"].Equals("Rejeitado")) { /*if (autor != null && conta != null && autor == conta)*/ /*if(this.DoesUserHavePermissions().Equals(true))*/ if(ISADMIN == true) { if (workflowProperties.Item.Fields.ContainsField("Escolh ") && workflowProperties.Item["Escolh"] != null && (workflowProperties.Item["Esc olh"].Equals("Aprovado") workflowProperties.Item["Escolh"].Equals("Rejeitado" ))) { workflowProperties.Item["Historico"] += teste2; workflowProperties.Item["Status"] = "Pendente"; workflowProperties.Item.SystemUpdate(); this.codigo3_ExecuteCode(sender, e); } } /*else if (autor != null && conta != null && autor != conta) */ /*else if(this.DoesUserHavePermissions().Equals(false))*/ else if(ISADMIN == false) { if (workflowProperties.Item.Fields.ContainsField("Escolh ") && workflowProperties.Item["Escolh"] != null && (workflowProperties.Item["Esc olh"].Equals("Aprovado") workflowProperties.Item["Escolh"].Equals("Rejeitado" ))) { this.codigo3_ExecuteCode(sender, e); } } } } }

private void codigo4_ExecuteCode(object sender, EventArgs e) { string escolha = workflowProperties.Item.GetFormattedValue("Escolh") ; string justificativa = workflowProperties.Item.GetFormattedValue("Ju stificativa"); string modificadoPor = workflowProperties.Item.GetFormattedValue("Mo dificado por"); var designer = String.Format("<div style=font-size=18px;font-family: Arial;background-color:#8B7D6B;font-weight:bold;left:50%;top:50%;position: absol ute;><font color=#ffffff>Modificado em: {0}</div>" + "<div style=font-size:14px;font-family:Arial;b ackground-color:#C1CDCD><font color=#1C1C1C><br><b>Escolha:&nbsp;</b>{1}</font>< br><font color=#1C1C1C> <b>Justificativa:&nbsp;</b> {2}</font> <br><font color=# 1C1C1C> <b>Integrante CCM:&nbsp;</b> {3}</font></div>", DateTime.Now, escolha, j ustificativa, modificadoPor); if (workflowProperties.Item.Fields.ContainsField("Status") && workfl owProperties.Item["Status"] != null && workflowProperties.Item["Status"].Equals( "Pendente")) { if (workflowProperties.Item.Fields.ContainsField("Escolh") && wo rkflowProperties.Item["Escolh"] != null) { workflowProperties.Item["Historico"] += designer; workflowProperties.Item["Status"] = "Pendente"; workflowProperties.Item.SystemUpdate(); } } this.codigo3_ExecuteCode(sender, e); } private void codigo2_ExecuteCode(object sender, EventArgs e) { string escolha = workflowProperties.Item.GetFormattedValue("Escolh") ; string justificativa = workflowProperties.Item.GetFormattedValue("Ju stificativa"); string modificadoPor = workflowProperties.Item.GetFormattedValue("Mo dificado por"); var teste = String.Format("<div style=font-size=18px;font-family:Ari al;background-color:#8B4726;font-weight:bold;left:50%;top:50%;position: absolute ;><font color=#ffffff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;Deciso do Gestor </div>" + "<div style=font-size=18px;font-family:Arial;b ackground-color:#8B7D6B;font-weight:bold;left:50%;top:50%;position: absolute;><f ont color=#ffffff>Modificado em: {0}</div>" + "<div style=font-size:14px;font-family:Arial;background-color:#C1CDC D><font color=#1C1C1C><br><b>Escolha:&nbsp;</b>{1}</font><br><font color=#1C1C1C > <b>Justificativa:&nbsp;</b> {2}</font> <br><font color=#1C1C1C> <b>Integrante CCM:&nbsp;</b> {3}</font></div>", DateTime.Now, escolha, justificativa, modifica doPor); if (workflowProperties.Item.Fields.ContainsField("Status") && workfl

owProperties.Item["Status"] != null && workflowProperties.Item["Status"].Equals( "Pendente")) { if (workflowProperties.Item.Fields.ContainsField("Escolh") && wo rkflowProperties.Item["Escolh"] != null) { if (workflowProperties.Item["Escolh"].Equals("Aprovado")) { workflowProperties.Item["Historico"] += teste; workflowProperties.Item["Status"] = "Aprovado"; workflowProperties.Item.SystemUpdate(); } else if (workflowProperties.Item["Escolh"].Equals("Rejeitado ")) { workflowProperties.Item["Historico"] += teste; workflowProperties.Item["Status"] = "Rejeitado"; workflowProperties.Item.SystemUpdate(); } } } } private void codigo3_ExecuteCode(object sender, EventArgs e) { if (workflowProperties.Item.Fields.ContainsField("Escolh") && workfl owProperties.Item["Escolh"] != null && workflowProperties.Item.Fields.ContainsFi eld("Justificativa") && workflowProperties.Item["Justificativa"] != null && work flowProperties.Item["Conta"] != null && workflowProperties.Item.Fields.ContainsF ield("Conta")) { workflowProperties.Item["Escolh"] = ""; workflowProperties.Item["Justificativa"] = ""; workflowProperties.Item["Conta"] = ""; workflowProperties.Item.SystemUpdate(); this.codigo1_ExecuteCode(sender, e); } } public SPUser RetornaAdmin() // Retorna usuario logado { string ModifiedbyUserName = Convert.ToString(workflowProperties.Item .GetFormattedValue("Modificado por")); if (ModifiedbyUserName != null) { string[] strChar = { "ID=" }; string[] strChars = ModifiedbyUserName.Split(strChar, StringSpli tOptions.None);

Int32 iUserID = Convert.ToInt32(strChars[1].Substring(0, strChar s[1].IndexOf("\""))); SPUserCollection usersInSite = workflowProperties.Web.SiteUsers; int countUsers = usersInSite.Count; for (int iCnt = 0; iCnt <= countUsers - 1; iCnt++) { if (usersInSite[iCnt].ID == iUserID) { SPUser usuario = workflowProperties.Web.SiteUsers[iCnt]; workflowProperties.Item["Conta"] = usuario; workflowProperties.Item.SystemUpdate(); return usuario; } } } return null; } public bool DoesUserHavePermissions() // Ser preciso definir as permisses de cada WebSite e ento definir apenas 1 ManageWeb que ser o gestor do site. { string conta = workflowProperties.Item.GetFormattedValue("Conta"); / / o login do usurio SPWeb web = workflowProperties.Web; if (conta != null) { bool IsAdmin = web.DoesUserHavePermissions(conta, SPBasePermissi ons.ManageWeb); return IsAdmin; } return false; // retorna falso. } } }

Das könnte Ihnen auch gefallen