Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/NotifyEventUIHelper.cs
2020-08-17 18:29:32 +00:00

342 lines
10 KiB
C#

using System;
using System.Data;
using System.Collections;
using CSLA.Data;
using CSLA;
using System.ComponentModel;
namespace GZTW.AyaNova.BLL
{
/// <summary>
/// User interface helper methods and properties
/// for managing subscriptions to notification events
///
/// Provides lists and data tables for managing notification through
/// the user interface
/// </summary>
[Serializable]
public class NotifyEventUIHelper
{
#region DataTable for building selections
/// <summary>
/// Utility list of events that can be subscribed to
/// </summary>
/// <param name="ns">NotifySubscriber - used to flag already subscribed events</param>
/// <returns>DataTable containing events that can be subscribed to and already subscribed events flagged as subscribed</returns>
public static DataTable GetEventsTable(NotifySubscriber ns)
{
DataTable dt = new DataTable( );
//Columns...
dt.Columns.Add( "ID",typeof(Guid));
dt.Columns.Add( "Selected",typeof(bool));
dt.Columns.Add( "RootObjectType",typeof(RootObjectTypes));
dt.Columns.Add( "EventType",typeof(int));
dt.Columns.Add( "LTKEY",typeof(string));
//Data...
//MEMO
dt.Rows.Add(AddRow(RootObjectTypes.Memo,(int)MemoEvent.Created));
//SCHEDULEMARKER
dt.Rows.Add(AddRow(RootObjectTypes.ScheduleMarker,(int)ScheduleMarkerEvent.Created));
dt.Rows.Add(AddRow(RootObjectTypes.ScheduleMarker,(int)ScheduleMarkerEvent.PendingAlert));
//WorkorderItemScheduledUser
dt.Rows.Add(AddRow(RootObjectTypes.WorkorderItemScheduledUser,(int)WorkorderItemScheduledUserEvent.CreatedUpdated));
dt.Rows.Add(AddRow(RootObjectTypes.WorkorderItemScheduledUser,(int)WorkorderItemScheduledUserEvent.PendingAlert));
//WorkorderItem
//dt.Rows.Add(AddRow(RootObjectTypes.WorkorderItem,(int)WorkorderItemEvent.NotServiced));
//Workorder
dt.Rows.Add(AddRow(RootObjectTypes.Workorder,(int)WorkorderEvent.Status));
dt.Rows.Add(AddRow(RootObjectTypes.Workorder,(int)WorkorderEvent.CloseByDatePassed));
//Quote - case 1555
dt.Rows.Add(AddRow(RootObjectTypes.Workorder, (int)WorkorderEvent.QuoteUpdated));
//WorkorderItemOutsideService
dt.Rows.Add(AddRow(RootObjectTypes.WorkorderItemOutsideService,(int)WorkorderItemOutsideServiceEvent.UnitBackFromService));
dt.Rows.Add(AddRow(RootObjectTypes.WorkorderItemOutsideService,(int)WorkorderItemOutsideServiceEvent.UnitNotBackFromServiceByETA));
//WorkorderItemPartRequest
dt.Rows.Add(AddRow(RootObjectTypes.WorkorderItemPartRequest,(int)WorkorderItemPartRequestEvent.PartsReceived));
//Client
dt.Rows.Add(AddRow(RootObjectTypes.Client,(int)ClientEvent.ContractExpire));
//ClientServiceRequest
dt.Rows.Add(AddRow(RootObjectTypes.ClientServiceRequest,(int)ClientServiceRequestEvent.Created));
//ServiceBank
dt.Rows.Add(AddRow(RootObjectTypes.ServiceBank,(int)ServiceBankEvent.CurrencyBalanceZero));
dt.Rows.Add(AddRow(RootObjectTypes.ServiceBank,(int)ServiceBankEvent.HoursBalanceZero));
dt.Rows.Add(AddRow(RootObjectTypes.ServiceBank,(int)ServiceBankEvent.IncidentsBalanceZero));
//User
//case 812
//if(!string.IsNullOrEmpty(AyaBizUtils.PluginLicensedVersion("QuickNotification")))
//case 2094
if (AyaBizUtils.PluginSubscriptionExists("QuickNotification") )
dt.Rows.Add(AddRow(RootObjectTypes.User, (int)UserEvent.QuickNotification));
//case 1382 - general smtp connection failure rootobjecttype=nothing, event=0
//case 1561 this should never have been here, removal was forgotten when completing 1382
//dt.Rows.Add(AddRow(RootObjectTypes.Nothing, 0));
foreach(DataRow dr in dt.Rows)
{
//skip over workorderevent.status because there can be more than one
if((RootObjectTypes)dr["RootObjectType"]==RootObjectTypes.Workorder && (int)dr["EventType"]==(int)WorkorderEvent.Status)
continue;
if(ns.Subscriptions.Contains((RootObjectTypes)dr["RootObjectType"],(int)dr["EventType"]))
dr["Selected"]=true;
}
return dt;
}
private static object[] AddRow(RootObjectTypes RootObject, int EventType)
{
return new object[]{Guid.NewGuid(),false,RootObject,EventType,GetEventLocalizedTextKey(RootObject,EventType)};
}
#endregion
#region Localized text key retriever for event
internal static string GetEventLocalizedTextKey(RootObjectTypes RootObject, int EventType)
{
switch (RootObject)
{
case RootObjectTypes.Memo:
{
switch(EventType)
{
case (int)MemoEvent.Created:
return "Memo.Label.Event.Created";
}
break;
}
case RootObjectTypes.ScheduleMarker:
{
switch(EventType)
{
case (int)ScheduleMarkerEvent.Created:
return "ScheduleMarker.Label.Event.Created";
case (int)ScheduleMarkerEvent.PendingAlert:
return "ScheduleMarker.Label.Event.PendingAlert";
}
break;
}
case RootObjectTypes.WorkorderItemScheduledUser:
{
switch(EventType)
{
case (int)WorkorderItemScheduledUserEvent.CreatedUpdated:
return "WorkorderItemScheduledUser.Label.Event.CreatedUpdated";
case (int)WorkorderItemScheduledUserEvent.PendingAlert:
return "WorkorderItemScheduledUser.Label.Event.PendingAlert";
}
break;
}
//case 812
case RootObjectTypes.User:
{
switch (EventType)
{
case (int)UserEvent.QuickNotification:
return "User.Label.Event.QuickNotification";
}
break;
}
// case RootObjectTypes.WorkorderItem:
// {
// switch(EventType)
// {
// case (int)WorkorderItemEvent.NotServiced:
// return "WorkorderItem.Label.Event.NotServiced";
//
// }
// break;
// }
case RootObjectTypes.Workorder:
{
switch(EventType)
{
case (int)WorkorderEvent.Status:
return "Workorder.Label.Event.Status";
case (int)WorkorderEvent.CloseByDatePassed:
return "Workorder.Label.Event.CloseByDatePassed";
//case 1555
case (int)WorkorderEvent.QuoteUpdated:
return "Workorder.Label.Event.QuoteUpdated";
}
break;
}
case RootObjectTypes.WorkorderItemOutsideService:
{
switch(EventType)
{
case (int)WorkorderItemOutsideServiceEvent.UnitBackFromService:
return "WorkorderItemOutsideService.Label.Event.UnitBackFromService";
case (int)WorkorderItemOutsideServiceEvent.UnitNotBackFromServiceByETA:
return "WorkorderItemOutsideService.Label.Event.UnitNotBackFromServiceByETA";
}
break;
}
case RootObjectTypes.WorkorderItemPartRequest:
{
switch(EventType)
{
case (int)WorkorderItemPartRequestEvent.PartsReceived:
return "WorkorderItemPartRequest.Label.Event.PartsReceived";
}
break;
}
case RootObjectTypes.Client:
{
switch(EventType)
{
case (int)ClientEvent.ContractExpire:
return "Client.Label.Event.ContractExpire";
}
break;
}
case RootObjectTypes.ClientServiceRequest:
{
switch (EventType)
{
case (int)ClientServiceRequestEvent.Created:
return "ClientServiceRequest.Label.Event.Created";
}
break;
}
case RootObjectTypes.ServiceBank:
{
switch(EventType)
{
case (int)ServiceBankEvent.CurrencyBalanceZero:
return "ServiceBank.Label.Event.CurrencyBalanceZero";
case (int)ServiceBankEvent.HoursBalanceZero:
return "ServiceBank.Label.Event.HoursBalanceZero";
case (int)ServiceBankEvent.IncidentsBalanceZero:
return "ServiceBank.Label.Event.IncidentsBalanceZero";
}
break;
}
//case 1382
case RootObjectTypes.Nothing:
{
//return "SMTP connection failure";
//case 3808
return "SMTP";//there are now many items logged as SMTP due to this case that aren't errors so just return smtp instead
}
}
return "NotifyEventUIHelper.GetEventLocalizedTextKey() missing event for " + RootObject.ToString() + " Event:" + EventType.ToString();
}
#endregion
#region Notification Message Formatter
internal static NotifyMessage GetNotificationMessage(NotifyMessageRequestData d)
{
switch (d.RootObject)
{
case RootObjectTypes.Memo:
{
return Memo.GetNotificationMessage(d);
}
case RootObjectTypes.ScheduleMarker:
{
return ScheduleMarker.GetNotificationMessage(d);
}
case RootObjectTypes.WorkorderItemScheduledUser:
{
return WorkorderItemScheduledUser.GetNotificationMessage(d);
}
case RootObjectTypes.Workorder:
{
return Workorder.GetNotificationMessage(d);
}
case RootObjectTypes.WorkorderItemOutsideService:
{
return WorkorderItemOutsideService.GetNotificationMessage(d);
}
case RootObjectTypes.WorkorderItemPartRequest:
{
return WorkorderItemPartRequest.GetNotificationMessage(d);
}
case RootObjectTypes.Client:
{
return Client.GetNotificationMessage(d);
}
case RootObjectTypes.ClientServiceRequest:
{
return ClientServiceRequest.GetNotificationMessage(d);
}
case RootObjectTypes.ServiceBank:
{
return ServiceBank.GetNotificationMessage(d);
}
case RootObjectTypes.User:
{
return User.GetNotificationMessage(d);
}
}
return new NotifyMessage("","Error: Unable to retrieve notification message");
}
#endregion
}
}