private void RecuperarInformacion_ExecuteCode(object sender, EventArgs e)
        {
            itemOC = workflowProperties.Item;

            try
            {
                autonomina = this.VerificarAutonomia();

                if (autonomina)
                {
                    #region Aprobar automaticamente el item
                    SPModerationInformation estadoAprobacion = itemOC.ModerationInformation;
                    estadoAprobacion.Status = SPModerationStatusType.Approved;

                    using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
                    {//Para evitar que ejecute una y otra vez el Evento ItemUpdating sobre este item
                        itemOC.SystemUpdate();
                    }
                    #endregion

                    #region Actualizar bitacora
                    //EjecutorOperacionesSP.ActualizarBitacoraAprobacion(itemOC);
                    #endregion

                    #region Notificacion por correo
                    asuntoNotificacion  = "Abastecimiento, orden de compra aprobada";
                    cuerpoNotificacion  = this.CuerpoCorreoNotificacion();
                    usuariosNotificados = this.UsuariosANotificar();
                    usuariosCopiados    = this.UsuariosACopiar();
                    mensajeHistorial    = "Notificación por aprobación automática realizada exitosamente.";
                    #endregion

                    #region Iniciar el flujo 'Notificar Descuentos'
                    EjecutorOperacionesSP.IniciarFlujoNotificarDescuentos(itemOC);
                    #endregion
                }
                else
                {
                    #region Notificacion por correo
                    asuntoNotificacion  = "Abastecimiento, solictud de aprobación";
                    cuerpoNotificacion  = this.CuerpoCorreoSolicitud();
                    usuariosNotificados = this.UsuariosANotificar();
                    //usuariosCopiados = this.UsuariosACopiar();
                    mensajeHistorial = "Notificación a 'Aprobadores de OC' realizada exitosamente.";
                    #endregion
                }
            }
            catch (Exception ex)
            {
                #region Registro de Evento Error
                LogEventos.LogArchivo log = new LogEventos.LogArchivo("LogErrores.txt");
                log.WriteEvent("--- [FLUJO] RecuperarInformacion_ExecuteCode flujo 'Notificar aprobación' ---");
                log.WriteException(ex);
                #endregion

                logNotificarAprobacion.EventId            = SPWorkflowHistoryEventType.WorkflowError;
                logNotificarAprobacion.HistoryOutcome     = "Error";
                logNotificarAprobacion.HistoryDescription = ex.Message;
            }
        }
Exemple #2
0
        /// <summary>
        ///     На самом деле это синхронный метод. Аналог ItemUpdating
        /// </summary>
        /// <param name="properties"></param>
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
            List <SyncType> syncTypes = SettingsProvider.Instance(properties.Web).CacheType(properties.List);

            using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
            {
                if (properties.ListItem.Fields.ContainsField(Fields.IsUpdated))
                {
                    bool   needSetIsUpdated = false;
                    object isUpdatedObj     = properties.ListItem.Properties[Fields.IsUpdated];
                    if (isUpdatedObj != null)
                    {
                        bool isUpdated;
                        if (bool.TryParse(isUpdatedObj.ToString(), out isUpdated))
                        {
                            if (!isUpdated)
                            {
                                needSetIsUpdated = true;
                            }
                        }
                    }
                    else
                    {
                        needSetIsUpdated = true;
                    }

                    if (needSetIsUpdated)
                    {
                        properties.ListItem[Fields.IsUpdated] = true;
                        properties.ListItem.Update();
                    }

                    //Если у элемента не проставлено значение в поле ItemUniqueID, то проставляем его.
                    //Такая ситуация может произойти со старыми элементами.
                    if (properties.ListItem[Constants.ItemUniqueIDFieldName] == null ||
                        string.IsNullOrEmpty(Convert.ToString(properties.ListItem[Constants.ItemUniqueIDFieldName])))
                    {
                        properties.ListItem[Constants.ItemUniqueIDFieldName] = properties.ListItem.UniqueId;
                        properties.ListItem.Update();
                    }
                }
            }
            this.Synchronize(properties, syncTypes, SyncActionType.Update);
        }