private static void UpdateProjectAndManager(int objectId, int projectId, int managerId) { int oldProjectId = DBEvent.GetProject(objectId); int oldManagerId = DBEvent.GetManager(objectId); if (managerId == 0) // Don't change manager { managerId = oldManagerId; } if (projectId == 0) // Don't change project { projectId = oldProjectId; } if (projectId != oldProjectId || managerId != oldManagerId) { using (DbTransaction tran = DbTransaction.Begin()) { DbCalendarEntry2.UpdateProjectAndManager(objectId, projectId, managerId); // OZ: User Role Addon if (managerId != oldManagerId) { UserRoleHelper.DeleteEventManagerRole(objectId, oldManagerId); UserRoleHelper.AddEventManagerRole(objectId, managerId); } if (projectId != oldProjectId) { ForeignContainerKey.Delete(UserRoleHelper.CreateEventContainerKey(objectId), UserRoleHelper.CreateProjectContainerKey(oldProjectId)); if (projectId > 0) { ForeignContainerKey.Add(UserRoleHelper.CreateEventContainerKey(objectId), UserRoleHelper.CreateProjectContainerKey(projectId)); } } // end OZ if (projectId != oldProjectId) { if (projectId > 0) { SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_CalendarEntryList_CalendarEntryAdded, projectId, objectId); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_CalendarEntryList_CalendarEntryDeleted, oldProjectId, objectId); } } if (managerId != oldManagerId) { SystemEvents.AddSystemEvents(SystemEventTypes.CalendarEntry_Updated_Manager_ManagerDeleted, objectId, oldManagerId); SystemEvents.AddSystemEvents(SystemEventTypes.CalendarEntry_Updated_Manager_ManagerAdded, objectId, managerId); } tran.Commit(); } } }
public static void DeclineResource(int documentId) { int userId = Security.CurrentUser.UserID; using (DbTransaction tran = DbTransaction.Begin()) { DbDocument2.ResourceReply(documentId, userId, false); SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_ResourceList_RequestDenied, documentId, userId); tran.Commit(); } }
public static void AcceptResource(int todoId) { int userId = Security.CurrentUser.UserID; using (DbTransaction tran = DbTransaction.Begin()) { DbTodo2.ResourceReply(todoId, userId, true); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_RequestAccepted, todoId, userId); tran.Commit(); } }
/// <summary> /// Deletes the specified request. /// </summary> /// <param name="Pop3MailRequestId">The POP3 mail request id.</param> static public void Delete(int issueRequestId) { using (DbTransaction tran = DbTransaction.Begin()) { SystemEvents.AddSystemEvents(SystemEventTypes.IssueRequest_Deleted, issueRequestId); FileStorage fileStorage = GetFileStorage(issueRequestId); fileStorage.DeleteAll(); DbPop3MailRequest.Delete(issueRequestId); tran.Commit(); } }
/*#region Approve() * public static int Approve(int issueRequestId, int projectId, bool createExternalUser) * { * int issueId = -1; * * string senderEmail = string.Empty; * int userId = -1; * string FirstName = string.Empty; * string LastName = string.Empty; * string Subject = string.Empty; * string InnerText = string.Empty; * int Priority = 500; * int Pop3BoxId = -1; * DateTime Received = DateTime.Now; * * using(IDataReader reader = Get(issueRequestId)) * { * if(reader.Read()) * { * senderEmail = reader["Sender"].ToString(); * if(reader["SenderIbnUserId"]!=DBNull.Value) * userId = (int)reader["SenderIbnUserId"]; * FirstName = reader["FirstName"].ToString(); * LastName = reader["LastName"].ToString(); * Subject = reader["Subject"].ToString(); * InnerText = reader["InnerText"].ToString(); * Priority = (int)reader["Priority"]; * Pop3BoxId = (int)reader["Pop3BoxId"]; * Received = (DateTime)reader["Received"]; * } * } * * if(senderEmail.Length > 0) * { * using(DbTransaction tran = DbTransaction.Begin()) * { * if(createExternalUser && userId <= 0) * { * // Create an external user * userId = User.CreateExternal(FirstName,LastName, senderEmail, new ArrayList(), true, * string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, * string.Empty, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId, * string.Empty, string.Empty, null); * } * * // Create issue * * // Commented by O.Rylin - весь этот метод не должен вызываться * // issueId = Incident.Create(Subject, InnerText, Priority, userId, projectId, userId <= 0); * * BaseIbnContainer destContainer; * BaseIbnContainer issueContainer = BaseIbnContainer.Create("FileLibrary", string.Format("IncidentId_{0}", issueId)); * * if(userId > 0) * destContainer = issueContainer; * else * { * Issue2.UpdateMailSenderEmail(issueId, senderEmail); * * // Create Forum Node * ForumStorage forumStorage = (ForumStorage)issueContainer.LoadControl("ForumStorage"); * ForumThreadNodeInfo node = forumStorage.CreateForumThreadNode(Subject,string.Format("{0} {1}", FirstName, LastName), senderEmail, (int)ForumStorage.NodeTypes.ExternalQuestion); * * destContainer = BaseIbnContainer.Create("FileLibrary", string.Format("ForumNodeId_{0}", node.Id)); * } * * // Upload Files * FileStorage destFileStorage = (FileStorage)destContainer.LoadControl("FileStorage"); * foreach(FileInfo srcFileInfo in GetFileStorage(issueRequestId).GetFiles()) * { * destFileStorage.CopyFile(srcFileInfo, destFileStorage.Root); * } * * // Delete Request * SystemEvents.AddSystemEvents(SystemEventTypes.IssueRequest_Approved, issueRequestId); * Delete(issueRequestId); * * tran.Commit(); * } * } * return issueId; * } #endregion*/ #region Create() public static int Create(string senderEmail, int senderUserId, string firstName, string lastName, string subject, string innerText, int priority, int pop3BoxId) { int issueRequestId; using (DbTransaction tran = DbTransaction.Begin()) { issueRequestId = DbPop3MailRequest.Create(senderEmail, senderUserId, firstName, lastName, subject, innerText, priority, pop3BoxId); SystemEvents.AddSystemEvents(SystemEventTypes.IssueRequest_Created, issueRequestId); tran.Commit(); } return(issueRequestId); }
internal static void UpdateGeneralInfo(int todoId, string title, string description, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(todoId); } using (DbTransaction tran = DbTransaction.Begin()) { DbTodo2.UpdateGeneralInfo(todoId, title, description); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_GeneralInfo, todoId); tran.Commit(); } }
internal static void UpdateGeneralInfo(int eventId, int typeId, string title, string description, string location, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(eventId); } using (DbTransaction tran = DbTransaction.Begin()) { DbCalendarEntry2.UpdateGeneralInfo(eventId, typeId, title, description, location); SystemEvents.AddSystemEvents(SystemEventTypes.CalendarEntry_Updated_GeneralInfo, eventId); tran.Commit(); } }
internal static void UpdatePriority(int todoId, int priorityId, bool checkAccess) { if (checkAccess && !ToDo.CanUpdate(todoId)) { throw new AccessDeniedException(); } using (DbTransaction tran = DbTransaction.Begin()) { if (0 < DbTodo2.UpdatePriority(todoId, priorityId)) { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Priority, todoId); } tran.Commit(); } }
internal static void UpdatePriority(int taskId, int priorityId, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(taskId); } using (DbTransaction tran = DbTransaction.Begin()) { if (0 < DbTask2.UpdatePriority(taskId, priorityId)) { SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_Priority, taskId); } tran.Commit(); } }
public static int AcceptChanges(MetaObject obj) { obj.AcceptChanges(); if (obj.MetaClass.Namespace == "Mediachase.IBN40.List") // ƒобавление/изменение записи в списке { string[] splitter = obj.MetaClass.Name.Split('_'); try { int ListId = int.Parse(splitter[1]); SystemEvents.AddSystemEvents(SystemEventTypes.List_Updated_Data, ListId); } catch {} } return(obj.Id); }
internal static void UpdateConfigurationInfo(int todoId, int activationTypeId, int completionTypeId, bool mustBeConfirmed, bool checkAccess) { if (checkAccess && !ToDo.CanUpdate(todoId)) { throw new AccessDeniedException(); } using (DbTransaction tran = DbTransaction.Begin()) { if (0 < DbTodo2.UpdateConfigurationInfo(todoId, activationTypeId, completionTypeId, mustBeConfirmed)) { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ConfigurationInfo, todoId); } tran.Commit(); } }
internal static void UpdateStatus(int documentId, int statusId, bool checkAccess) { if (checkAccess && !Document.CanUpdateStatus(documentId)) { throw new AccessDeniedException(); } using (DbTransaction tran = DbTransaction.Begin()) { if (0 < DbDocument2.UpdateStatus(documentId, statusId)) { SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_Status, documentId); } tran.Commit(); } }
internal static void UpdatePriority(int eventId, int priorityId, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(eventId); } using (DbTransaction tran = DbTransaction.Begin()) { if (0 < DbCalendarEntry2.UpdatePriority(eventId, priorityId)) { SystemEvents.AddSystemEvents(SystemEventTypes.CalendarEntry_Updated_Priority, eventId); } tran.Commit(); } }
internal static void UpdateConfigurationInfo(int taskId, int activationTypeId, int completionTypeId, bool mustBeConfirmed, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(taskId); } using (DbTransaction tran = DbTransaction.Begin()) { if (0 < DbTask2.UpdateConfigurationInfo(taskId, activationTypeId, completionTypeId, mustBeConfirmed)) { SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ConfigurationInfo, taskId); Task.RecalculateAllStates(DBTask.GetProject(taskId)); } tran.Commit(); } }
public static string GetDisplayName(AlertTemplateTypes type, string key) { string ret = null; switch (type) { case AlertTemplateTypes.Notification: string[] parts = key.Split('|'); // EventType|MessageType ret = string.Format("{0} [{1}]", SystemEvents.GetSystemEventName(parts[0]), SystemEvents.GetMessageTypeName(parts[1])); break; case AlertTemplateTypes.Reminder: ret = ReminderTemplate.TypesRM.GetString(key); break; case AlertTemplateTypes.Special: ret = SpecialMessage.TypesRM.GetString(key); break; } return(ret); }
public static void DeclineResource(int todoId) { UserLight cu = Security.CurrentUser; int UserId = cu.UserID; DateTime utc_now = DateTime.UtcNow; int CompletionTypeId; bool IsManagerConfirmed; bool IsCompleted; int ReasonId; int IncidentId = -1; int DocumentId = -1; int TaskId = -1; bool CompleteIncident = false; bool CompleteTask = false; bool CompleteDocument = false; int oldPercentCompleted = 0; string title = ""; using (IDataReader reader = DBToDo.GetToDo(todoId, cu.TimeZoneId, cu.LanguageId)) { reader.Read(); CompletionTypeId = (int)reader["CompletionTypeId"]; IsManagerConfirmed = (bool)reader["MustBeConfirmed"]; IsCompleted = (bool)reader["IsCompleted"]; ReasonId = (int)reader["ReasonId"]; if (reader["IncidentId"] != DBNull.Value) { IncidentId = (int)reader["IncidentId"]; } if (reader["DocumentId"] != DBNull.Value) { DocumentId = (int)reader["DocumentId"]; } if (reader["TaskId"] != DBNull.Value) { TaskId = (int)reader["TaskId"]; } if (reader["CompleteIncident"] != DBNull.Value) { CompleteIncident = (bool)reader["CompleteIncident"]; } if (reader["CompleteTask"] != DBNull.Value) { CompleteTask = (bool)reader["CompleteTask"]; } if (reader["CompleteDocument"] != DBNull.Value) { CompleteDocument = (bool)reader["CompleteDocument"]; } oldPercentCompleted = (int)reader["PercentCompleted"]; title = reader["Title"].ToString(); } using (DbTransaction tran = DbTransaction.Begin()) { DbTodo2.ResourceReply(todoId, UserId, false); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, todoId, UserId); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_RequestDenied, todoId, UserId); if (CompletionTypeId == (int)CompletionType.All) { int OverallPercent = ToDo.RecalculateOverallPercent(todoId); if (oldPercentCompleted != OverallPercent) { DBToDo.UpdatePercent(todoId, OverallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Percent, todoId); } if (!IsCompleted && !IsManagerConfirmed && OverallPercent == 100) { DBToDo.UpdateCompletion(todoId, true, (int)CompletionReason.CompletedAutomatically); if (TaskId > 0 && CompleteTask) { ToDo.UpdateTaskCompletion(TaskId); } if (DocumentId > 0 && CompleteDocument) { ToDo.UpdateDocumentCompletion(DocumentId); } if (IncidentId > 0 && CompleteIncident) { ToDo.CompleteIncidentIfNeed(IncidentId); } ToDo.RecalculateState(todoId); } } tran.Commit(); } }
public static void SendMessage(string[] To, string Subject, string Body, Mediachase.IBN.Business.ControlSystem.DirectoryInfo Attachments, string Mode, NameValueCollection Params) { // Cleanup Temporary files DbEMailTempFile.CleanUp(); #region Validate Arguments if (To == null) { throw new ArgumentNullException("To"); } if (Subject == null) { throw new ArgumentNullException("Subject"); } if (Body == null) { throw new ArgumentNullException("Body"); } //if (To.Length == 0) // throw new ArgumentOutOfRangeException("To", "Email recipient list is empty."); if (Mode == null) { Mode = string.Empty; } if (Params == null) { Params = new NameValueCollection(); } #endregion string FromEmail = string.Empty; switch (Mode) { case EMailClient.IssueMode: case EMailClient.SmtpTestMode: FromEmail = Alerts2.AlertSenderEmail; break; default: FromEmail = Security.CurrentUser.Email; break; } string FullFromEmail = string.Format("\"{0} {1}\" <{2}>", Security.CurrentUser.LastName, Security.CurrentUser.FirstName, FromEmail); using (DbTransaction tran = DbTransaction.Begin()) { EMailMessageLogSetting EmailLogSettings = EMailMessageLogSetting.Current; if (EmailLogSettings.IsActive) { EMailMessageLog.CleanUp(EmailLogSettings.Period); } else { EmailLogSettings = null; } Mode = Mode.ToLower(); #region Pre-format incoming arguments switch (Mode) { case EMailClient.IssueMode: if (Params["IssueId"] == null) { throw new ArgumentNullException("Params[\"IssueId\"]"); } int IssueId = int.Parse(Params["IssueId"]); // TODO: Validate Subject & Ticket if (TicketUidUtil.LoadFromString(Subject) == string.Empty) { IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IssueId)); string IncidentTicket = Incident.GetIdentifier(IssueId); if (incidentBox.Document.GeneralBlock.AllowOutgoingEmailFormat) { StringBuilder sb = new StringBuilder(incidentBox.Document.GeneralBlock.OutgoingEmailFormatSubject, 4096); sb.Replace("[=Title=]", Subject); sb.Replace("[=Ticket=]", IncidentTicket); //sb.Replace("[=Text=]", Body); sb.Replace("[=FirstName=]", Security.CurrentUser.FirstName); sb.Replace("[=LastName=]", Security.CurrentUser.LastName); Subject = sb.ToString(); } else { Subject = string.Format("RE: [{0}] {1}", IncidentTicket, Subject); } } break; default: break; } #endregion Pop3Message msg = Create(FullFromEmail, To, Subject, Body, Attachments); switch (Mode) { case EMailClient.IssueMode: #region Issue int IssueId = int.Parse(Params["IssueId"]); IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IssueId)); bool AllowEMailRouting = true; EMailRouterIncidentBoxBlock settings = IncidentBoxDocument.Load(incidentBox.IncidentBoxId).EMailRouterBlock; if (!settings.AllowEMailRouting) { AllowEMailRouting = false; } EMailRouterPop3Box internalPop3Box = EMailRouterPop3Box.ListInternal(); if (internalPop3Box == null) { AllowEMailRouting = false; } // Register Email Message // OZ: [2007--05-25] Fix Problem Object reference not set to an instance of an object If (internalPop3Box == NULL) int EMailMessageId = EMailMessage.Create(internalPop3Box != null? internalPop3Box.EMailRouterPop3BoxId : EMailRouterOutputMessage.FindEMailRouterPublicId(IssueId), msg); // Register Forume Node int ThreadNodeId = EMailMessage.AddToIncidentMessage(true, IssueId, EMailMessageId, msg); // Send Message if (AllowEMailRouting) { ArrayList excludedUsers = EMailRouterOutputMessage.Send(IssueId, internalPop3Box, msg, To); SystemEvents.AddSystemEvents(SystemEventTypes.Issue_Updated_Forum_MessageAdded, IssueId, -1, excludedUsers); } else { FromEmail = EMailRouterOutputMessage.FindEMailRouterPublicEmail(IssueId); FullFromEmail = string.Format("\"{0} {1}\" <{2}>", Security.CurrentUser.LastName, Security.CurrentUser.FirstName, FromEmail); // Create OutputMessageCreator OutputMessageCreator issueOutput = new OutputMessageCreator(msg, -1, FromEmail, FullFromEmail); // Fill Recipent foreach (string ToItem in To) { issueOutput.AddRecipient(ToItem); } foreach (EMailIssueExternalRecipient exRecipient in EMailIssueExternalRecipient.List(IssueId)) { issueOutput.AddRecipient(exRecipient.EMail); } int emailBoxId = EMail.EMailRouterOutputMessage.FindEMailRouterPublicId(IssueId); //Send Smtp Message foreach (OutputMessage outputMsg in issueOutput.Create()) { SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, emailBoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data); } ArrayList excludedUsers = new ArrayList(); foreach (string ToItem in To) { int emailUserId = DBUser.GetUserByEmail(ToItem, false); if (emailUserId > 0) { excludedUsers.Add(emailUserId); } } SystemEvents.AddSystemEvents(SystemEventTypes.Issue_Updated_Forum_MessageAdded, IssueId, -1, excludedUsers); } #endregion break; case EMailClient.SmtpTestMode: throw new NotImplementedException(); //OutputMessageCreator smtpTestOutput = new OutputMessageCreator(msg, // -1, // FromEmail, // FullFromEmail); //// Fill Recipent //foreach (string ToItem in To) //{ // smtpTestOutput.AddRecipient(ToItem); //} ////Send Smtp Message //foreach (OutputMessage outputMsg in smtpTestOutput.Create()) //{ // //SmtpClientUtility.DirectSendMessage(outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data); // //SmtpBox.SendTestEmail( //} //break; default: #region Default // Create OutputMessageCreator OutputMessageCreator defaultOutput = new OutputMessageCreator(msg, -1, FromEmail, FullFromEmail); // Fill Recipent foreach (string ToItem in To) { defaultOutput.AddRecipient(ToItem); } //Send Smtp Message foreach (OutputMessage outputMsg in defaultOutput.Create()) { SmtpClientUtility.SendMessage(OutgoingEmailServiceType.SendFile, null, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data); } #endregion break; } if (Attachments != null) { FileStorage.InnerDeleteFolder(Attachments.Id); } tran.Commit(); } }
private static void UpdateListResources(int objectId, DataTable items, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(objectId); } int managerId = -1; using (IDataReader reader = DBDocument.GetDocument(objectId, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId)) { reader.Read(); managerId = (int)reader["ManagerId"]; } ArrayList oldItems = new ArrayList(); using (IDataReader reader = DBDocument.GetListResources(objectId, Security.CurrentUser.TimeZoneId)) { Common.LoadPrincipals(reader, oldItems); } ArrayList add = new ArrayList(); ArrayList del = new ArrayList(); foreach (DataRow row in items.Rows) { int id = (int)row["PrincipalId"]; if (oldItems.Contains(id)) { oldItems.Remove(id); } else { add.Add(id); } } del.AddRange(oldItems); using (DbTransaction tran = DbTransaction.Begin()) { foreach (int id in del) { DBCommon.DeleteGate((int)OBJECT_TYPE, objectId, id); DBDocument.DeleteResource(objectId, id); // OZ: User Role Addon UserRoleHelper.DeleteDocumentResourceRole(objectId, id); if (id != managerId) { UserRoleHelper.DeleteDocumentManagerRole(objectId, id); } // SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_ResourceList_AssignmentDeleted, objectId, id); } foreach (DataRow row in items.Rows) { int id = (int)row["PrincipalId"]; bool mustBeConfirmed = (bool)row["MustBeConfirmed"]; bool canManage = (bool)row["CanManage"]; bool updated = true; if (add.Contains(id)) { DbDocument2.ResourceAdd(objectId, id, mustBeConfirmed, canManage); if (User.IsExternal(id)) { DBCommon.AddGate((int)OBJECT_TYPE, objectId, id); } } else { updated = (0 < DbDocument2.ResourceUpdate(objectId, id, mustBeConfirmed, canManage)); } // OZ: User Role Addon if (canManage) { if (id != managerId) { UserRoleHelper.AddDocumentManagerRole(objectId, id); } } else { UserRoleHelper.AddDocumentResourceRole(objectId, id); } // end if (updated) { if (mustBeConfirmed) { SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_ResourceList_RequestAdded, objectId, id); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Document_Updated_ResourceList_AssignmentAdded, objectId, id); } } } tran.Commit(); } }
public static void ProcessHandler(int handlerId, string argument, int hookId, int?objectId, Guid?objectUid, DateTime dateValue) { ObjectTypes objectType = ObjectTypes.UNDEFINED; DateTypes dateType = DateTypes.Undefined; if (handlerId == (int)DateTypeHandlers.SendReminder) { // Напоминать только о тех датах, которые еще не наступили. if (dateValue >= DateTime.UtcNow) { bool sendReminder = false; int userId = -1; using (IDataReader reader = DbSchedule2.GetReminderSubscriptionByHookId(hookId)) { if (reader.Read()) { sendReminder = true; if (reader["UserId"] != DBNull.Value) { userId = (int)reader["UserId"]; // O.R. [2010-04-01]: Don't process inactive user if (User.GetUserActivity(userId) != User.UserActivity.Active) { sendReminder = false; } } objectType = (ObjectTypes)reader["ObjectTypeId"]; dateType = (DateTypes)reader["DateTypeId"]; } } // Не напоминать о досрочно запущенных или досрочно завершённых объектах [2007-02-16] if (sendReminder) { sendReminder = ConfirmNotification(objectType, dateType, objectId, objectUid); } if (sendReminder) { SubscriptionTypes subscriptionType = (SubscriptionTypes)int.Parse(argument, CultureInfo.InvariantCulture); switch (subscriptionType) { case SubscriptionTypes.Global: ProcessGlobalSubscription(hookId, dateType, objectType, objectId, objectUid); break; case SubscriptionTypes.Personal: ProcessPersonalSubscription(hookId, dateType, userId, objectType, objectId, objectUid); break; case SubscriptionTypes.PersonalForObject: ProcessPersonalSubscriptionForObject(hookId, dateType, userId, objectType, objectId, objectUid); break; } } } } else if (handlerId == (int)DateTypeHandlers.RaiseSystemEvent) { bool raiseEvent = false; using (IDataReader reader = DbSchedule2.GetHook(hookId)) { if (reader.Read()) { raiseEvent = true; objectType = (ObjectTypes)reader["ObjectTypeId"]; dateType = (DateTypes)reader["DateTypeId"]; } } if (raiseEvent) { // Не уведомлять о досрочно запущенных или досрочно завершённых объектах [2008-07-29] raiseEvent = ConfirmNotification(objectType, dateType, objectId, objectUid); if (raiseEvent) { SystemEventTypes EventType = (SystemEventTypes)int.Parse(argument); if (objectId.HasValue) { SystemEvents.AddSystemEvents(EventType, objectId.Value); } else if (objectUid.HasValue) { SystemEvents.AddSystemEvents(EventType, objectUid.Value); } } if (objectType == ObjectTypes.Task) { Task.RecalculateAllStates(Task.GetProject(objectId.Value)); } else if (objectType == ObjectTypes.ToDo) { ToDo.RecalculateState(objectId.Value); } else if (objectType == ObjectTypes.CalendarEntry) { CalendarEntry.RecalculateState(objectId.Value); } } } else if (handlerId == (int)DateTypeHandlers.BatchAlert) { if (objectId.HasValue) { Alerts2.SendBatch(objectId.Value, dateValue); } } else if (handlerId == (int)DateTypeHandlers.LdapSync) { if (objectId.HasValue) { Ldap.Synchronize(objectId.Value, dateValue); } } }
private static void UpdateListResources(int objectId, DataTable items, bool checkAccess) { if (checkAccess) { VerifyCanModifyResources(objectId); } int taskCompletionTypeId; bool taskMustBeConfirmed; bool taskIsCompleted; int taskReasonId; int taskProjectId; int taskPercentCompleted; using (IDataReader reader = DBTask.GetTask(objectId, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId)) { reader.Read(); taskCompletionTypeId = (int)reader["CompletionTypeId"]; taskMustBeConfirmed = (bool)reader["MustBeConfirmed"]; taskIsCompleted = (bool)reader["IsCompleted"]; taskReasonId = (int)reader["ReasonId"]; taskProjectId = (int)reader["ProjectId"]; taskPercentCompleted = (int)reader["PercentCompleted"]; } int managerId = DBProject.GetProjectManager(taskProjectId); ArrayList oldItems = new ArrayList(); using (IDataReader reader = DBTask.GetListResources(objectId, Security.CurrentUser.TimeZoneId)) { Common.LoadItems(reader, "UserId", oldItems); } ArrayList add = new ArrayList(); ArrayList del = new ArrayList(); foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; if (oldItems.Contains(id)) { oldItems.Remove(id); } else { add.Add(id); } } del.AddRange(oldItems); int cuid = Security.CurrentUser.UserID; using (DbTransaction tran = DbTransaction.Begin()) { foreach (int id in del) { DBCommon.DeleteGate((int)OBJECT_TYPE, objectId, id); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, objectId, id); DBTask.DeleteResource(objectId, id); // OZ: User Role Addon UserRoleHelper.DeleteTaskResourceRole(objectId, id); if (id != managerId) { UserRoleHelper.DeleteTaskManagerRole(objectId, id); } // SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_AssignmentDeleted, objectId, id); } foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; bool mustBeConfirmed = (bool)row["MustBeConfirmed"]; bool canManage = (bool)row["CanManage"]; if (id == managerId) { canManage = true; } bool updated = true; if (add.Contains(id)) { DbTask2.AddResource(objectId, id, mustBeConfirmed, canManage); if (User.IsExternal(id)) { DBCommon.AddGate((int)OBJECT_TYPE, objectId, id); } } else { updated = (0 < DbTask2.UpdateResource(objectId, id, mustBeConfirmed, canManage)); } // OZ: User Role Addon if (id != managerId) { UserRoleHelper.DeleteTaskManagerRole(objectId, id); } UserRoleHelper.DeleteTaskResourceRole(objectId, id); if (canManage) { if (id != managerId) { UserRoleHelper.AddTaskManagerRole(objectId, id); } } else { UserRoleHelper.AddTaskResourceRole(objectId, id); } // if (updated) { if (mustBeConfirmed) { SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_RequestAdded, objectId, id); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_AssignmentAdded, objectId, id); } } } if (taskCompletionTypeId == (int)CompletionType.All) { int overallPercent = Task.RecalculateOverallPercent(objectId); if (taskPercentCompleted != overallPercent) { DBTask.UpdatePercent(objectId, overallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_Percent, objectId); } // Если задача была незавершённой, то при удалении людей, процент завершения может // увеличиться и достигнуть 100%. Если при этом не требуется подтверждения менеджера, // то произойдёт завершение задачи if (!taskIsCompleted && !taskMustBeConfirmed && overallPercent == 100) { DBTask.UpdateCompletion(objectId, true, (int)CompletionReason.CompletedAutomatically); Task.CompleteToDo(objectId); Task.RecalculateAllStates(taskProjectId); } DBTask.RecalculateSummaryPercent(objectId); } tran.Commit(); } }
internal static void UpdateTimeline(int todoId, DateTime startDate, DateTime finishDate, int taskTime, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(todoId); } object oStartDate = null; object oFinishDate = null; DateTime MinValue1 = DateTime.MinValue.AddDays(1); int TimeZoneId = Security.CurrentUser.TimeZoneId; if (startDate > MinValue1 && finishDate > MinValue1 && startDate > finishDate) { throw new Exception("wrong dates"); } if (startDate > MinValue1) { oStartDate = DBCommon.GetUTCDate(TimeZoneId, startDate); } if (finishDate > MinValue1) { oFinishDate = DBCommon.GetUTCDate(TimeZoneId, finishDate); } int projectId = ToDo.GetProject(todoId); using (DbTransaction tran = DbTransaction.Begin()) { int retVal = DbTodo2.UpdateTimeline(todoId, oStartDate, oFinishDate, taskTime); if (retVal > 0) { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Timeline, todoId); // O.R: Scheduling if (retVal == 1 || retVal == 3) // StartDate Changed { if (oStartDate != null) { Schedule.UpdateDateTypeValue(DateTypes.Todo_StartDate, todoId, (DateTime)oStartDate); } else { Schedule.DeleteDateTypeValue(DateTypes.Todo_StartDate, todoId); } } if (retVal == 2 || retVal == 3) // FinishDate Changed { if (oFinishDate != null) { Schedule.UpdateDateTypeValue(DateTypes.Todo_FinishDate, todoId, (DateTime)oFinishDate); } else { Schedule.DeleteDateTypeValue(DateTypes.Todo_FinishDate, todoId); } } // O.R: Recalculating project TaskTime if (projectId > 0) { TimeTracking.RecalculateProjectTaskTime(projectId); } ToDo.RecalculateState(todoId); } tran.Commit(); } }
internal static void UpdateTimeline(int eventId, DateTime startDate, DateTime finishDate, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(eventId); } int TimeZoneId = Security.CurrentUser.TimeZoneId; startDate = DBCommon.GetUTCDate(TimeZoneId, startDate); finishDate = DBCommon.GetUTCDate(TimeZoneId, finishDate); int projectId = -1; bool hasRecurrence = false; using (IDataReader reader = CalendarEntry.GetEvent(eventId, false)) { if (reader.Read()) { if (reader["ProjectId"] != DBNull.Value) { projectId = (int)reader["ProjectId"]; } hasRecurrence = ((int)reader["HasRecurrence"] == 1); } } // O.R. [2009-12-18] Dates for recurrent events should be chnaged in recurrence editing. if (hasRecurrence) { return; } TimeSpan ts = finishDate.Subtract(startDate); int taskTime = (int)ts.TotalMinutes; using (DbTransaction tran = DbTransaction.Begin()) { int retVal = DbCalendarEntry2.UpdateTimeline(eventId, startDate, finishDate, taskTime); if (retVal > 0) { SystemEvents.AddSystemEvents(SystemEventTypes.CalendarEntry_Updated_Timeline, eventId); if (!hasRecurrence) { if (retVal == 1 || retVal == 3) { Schedule.UpdateDateTypeValue(DateTypes.CalendarEntry_StartDate, eventId, startDate); } if (retVal == 2 || retVal == 3) { Schedule.UpdateDateTypeValue(DateTypes.CalendarEntry_FinishDate, eventId, finishDate); } } else { // O.R.[2009-09-29]: Recalculate events dates for scheduling Schedule.DeleteDateTypeValue(DateTypes.CalendarEntry_StartDate, eventId); Schedule.DeleteDateTypeValue(DateTypes.CalendarEntry_FinishDate, eventId); int ReminderInterval; Hashtable ret = CalendarEntry.GetEventInstances(eventId, out ReminderInterval); foreach (DateTime dtStart in ret.Keys) { DateTime dtEnd = (DateTime)ret[dtStart]; if (dtStart > DateTime.UtcNow && dtEnd > DateTime.UtcNow) { DbSchedule2.AddNewDateTypeValue((int)DateTypes.CalendarEntry_StartDate, eventId, dtStart); DbSchedule2.AddNewDateTypeValue((int)DateTypes.CalendarEntry_FinishDate, eventId, dtEnd); } } } // O.R: Recalculating project TaskTime if (projectId > 0) { TimeTracking.RecalculateProjectTaskTime(projectId); } } CalendarEntry.RecalculateState(eventId); tran.Commit(); } }
private static void UpdateProjectAndManager(int todoId, int projectId, int managerId) { int oldProjectId = DBToDo.GetProject(todoId); int oldManagerId = DBToDo.GetManager(todoId); if (projectId == 0) // leave old project { projectId = oldProjectId; } if (managerId == 0) // Leave old manager { managerId = oldManagerId; } if (projectId != oldProjectId && projectId > 0 && !ToDo.CanCreate(projectId)) { throw new AccessDeniedException(); } if (projectId != oldProjectId || managerId != oldManagerId) { using (DbTransaction tran = DbTransaction.Begin()) { DBToDo.UpdateProjectAndManager(todoId, projectId, managerId); // OZ: User Role Addon if (managerId != oldManagerId) { UserRoleHelper.DeleteTodoManagerRole(todoId, oldManagerId); UserRoleHelper.AddTodoManagerRole(todoId, managerId); } if (projectId != oldProjectId) { ForeignContainerKey.Delete(UserRoleHelper.CreateTodoContainerKey(todoId), UserRoleHelper.CreateProjectContainerKey(oldProjectId)); if (projectId > 0) { ForeignContainerKey.Add(UserRoleHelper.CreateTodoContainerKey(todoId), UserRoleHelper.CreateProjectContainerKey(projectId)); } } // end OZ if (projectId != oldProjectId) { if (projectId > 0) { SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_TodoList_TodoAdded, projectId, todoId); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_TodoList_TodoDeleted, oldProjectId, todoId); } // O.R. [2008-07-30] if (oldProjectId > 0) { TimeTracking.RecalculateProjectTaskTime(oldProjectId); } if (projectId > 0) { TimeTracking.RecalculateProjectTaskTime(projectId); } } if (managerId != oldManagerId) { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Manager_ManagerDeleted, todoId, oldManagerId); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Manager_ManagerAdded, todoId, managerId); } tran.Commit(); } } }
private static void UpdateListResources(int objectId, DataTable items, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(objectId); } int todoCompletionTypeId; bool todoManagerConfirmed; bool todoIsCompleted; int todoReasonId; int todoIncidentId = -1; int todoDocumentId = -1; int todoTaskId = -1; int todoPercentCompleted = 0; bool CompleteIncident = false; bool todoCompleteTask = false; bool todoCompleteDocument = false; string todoTitle = ""; using (IDataReader reader = DBToDo.GetToDo(objectId, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId)) { reader.Read(); todoCompletionTypeId = (int)reader["CompletionTypeId"]; todoManagerConfirmed = (bool)reader["MustBeConfirmed"]; todoIsCompleted = (bool)reader["IsCompleted"]; todoReasonId = (int)reader["ReasonId"]; if (reader["IncidentId"] != DBNull.Value) { todoIncidentId = (int)reader["IncidentId"]; } if (reader["DocumentId"] != DBNull.Value) { todoDocumentId = (int)reader["DocumentId"]; } if (reader["TaskId"] != DBNull.Value) { todoTaskId = (int)reader["TaskId"]; } if (reader["CompleteIncident"] != DBNull.Value) { CompleteIncident = (bool)reader["CompleteIncident"]; } if (reader["CompleteTask"] != DBNull.Value) { todoCompleteTask = (bool)reader["CompleteTask"]; } if (reader["CompleteDocument"] != DBNull.Value) { todoCompleteDocument = (bool)reader["CompleteDocument"]; } todoPercentCompleted = (int)reader["PercentCompleted"]; todoTitle = reader["Title"].ToString(); } ArrayList oldItems = new ArrayList(); using (IDataReader reader = DBToDo.GetListResources(objectId, Security.CurrentUser.TimeZoneId)) { Common.LoadItems(reader, "UserId", oldItems); } ArrayList add = new ArrayList(); ArrayList del = new ArrayList(); foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; if (oldItems.Contains(id)) { oldItems.Remove(id); } else { add.Add(id); } } del.AddRange(oldItems); int cuid = Security.CurrentUser.UserID; using (DbTransaction tran = DbTransaction.Begin()) { foreach (int id in del) { DBCommon.DeleteGate((int)OBJECT_TYPE, objectId, id); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, objectId, id); DBToDo.DeleteResource(objectId, id); // OZ: User Role Addon //if(todoIncidentId!=-1) //{ // UserRoleHelper.DeleteIssueTodoResourceRole(todoIncidentId, id); //} //else if (todoDocumentId != -1) { UserRoleHelper.DeleteDocumentTodoResourceRole(todoDocumentId, id); } else if (todoTaskId != -1) { UserRoleHelper.DeleteTaskTodoResourceRole(todoTaskId, id); } else { UserRoleHelper.DeleteTodoResourceRole(objectId, id); } // SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_AssignmentDeleted, objectId, id); } foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; bool mustBeConfirmed = (bool)row["MustBeConfirmed"]; bool updated = true; if (add.Contains(id)) { DbTodo2.AddResource(objectId, id, mustBeConfirmed); if (User.IsExternal(id)) { DBCommon.AddGate((int)OBJECT_TYPE, objectId, id); } // OZ: User Role Addon //if(todoIncidentId!=-1) //{ // UserRoleHelper.AddIssueTodoResourceRole(todoIncidentId, id); //} //else if (todoDocumentId != -1) { UserRoleHelper.AddDocumentTodoResourceRole(todoDocumentId, id); } else if (todoTaskId != -1) { UserRoleHelper.AddTaskTodoResourceRole(todoTaskId, id); } else { UserRoleHelper.AddTodoResourceRole(objectId, id); } // } else { updated = (0 < DbTodo2.UpdateResource(objectId, id, mustBeConfirmed)); } if (updated) { if (mustBeConfirmed) { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_RequestAdded, objectId, id); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_AssignmentAdded, objectId, id); } } } if (todoCompletionTypeId == (int)CompletionType.All) { int overallPercent = ToDo.RecalculateOverallPercent(objectId); if (todoPercentCompleted != overallPercent) { DBToDo.UpdatePercent(objectId, overallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Percent, objectId); } // Если поручение было незавершённым, то при удалении людей, процент завершения может // увеличиться и достигнуть 100%. Если при этом не требуется подтверждения менеджера, // то произойдёт завершение todo if (!todoIsCompleted && !todoManagerConfirmed && overallPercent == 100) { DBToDo.UpdateCompletion(objectId, true, (int)CompletionReason.CompletedAutomatically); if (todoTaskId > 0 && todoCompleteTask) { ToDo.UpdateTaskCompletion(todoTaskId); } if (todoDocumentId > 0 && todoCompleteDocument) { ToDo.UpdateDocumentCompletion(todoDocumentId); } if (todoIncidentId > 0 && CompleteIncident) { ToDo.CompleteIncidentIfNeed(todoIncidentId); } ToDo.RecalculateState(objectId); } } tran.Commit(); } }