This commit is contained in:
@@ -0,0 +1,831 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using AyaNova.PlugIn;
|
||||
using GZTW.AyaNova.BLL;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AyaNova.Plugin.QuickNotification
|
||||
{
|
||||
public class QuickNotification : IAyaNovaPlugin
|
||||
{
|
||||
//Keep all the object types we want to deal with in a collection
|
||||
//so that we can quickly check it when asked
|
||||
private static List<RootObjectTypes> ObjectsWeCanDealWith = null;
|
||||
private static bool bLicensed = false;
|
||||
//Holds the image resources from AyaNova
|
||||
//so we can display the correct icons in our plugin
|
||||
System.Resources.ResourceManager resman = null;
|
||||
|
||||
//Holds the current logged in user's localized text
|
||||
//lookup object
|
||||
LocalizedTextTable LocaleText = null;
|
||||
|
||||
#region IAyaNovaPlugin Members
|
||||
|
||||
#region interface properties
|
||||
public string PluginName
|
||||
{
|
||||
get { return "QuickNotification"; }
|
||||
}
|
||||
|
||||
public string PluginVersion
|
||||
{
|
||||
get { return "7.5"; }
|
||||
}
|
||||
|
||||
public string About
|
||||
{
|
||||
get
|
||||
{
|
||||
return "AyaNova QuickNotification plugin\r\n" +
|
||||
"Built " + AyaNova.PlugIn.QuickNotification.Timestamp.BuildAt.ToString() + "\r\n" +
|
||||
"Copyright 2009-2018 Ground Zero Tech-Works Inc.";
|
||||
}
|
||||
}
|
||||
|
||||
public Guid PluginID
|
||||
{
|
||||
get { return new Guid("{5B0CBFEB-E6A0-4005-B0AA-CD5C9A2A7E97}"); }
|
||||
}
|
||||
|
||||
public System.Drawing.Image PluginSmallIcon
|
||||
{
|
||||
get { return Resource.QuickNotification16; }
|
||||
}
|
||||
|
||||
public System.Drawing.Image PluginLargeIcon
|
||||
{
|
||||
get { return Resource.QuickNotification32; }
|
||||
}
|
||||
|
||||
public System.Resources.ResourceManager AyaNovaResourceManager
|
||||
{
|
||||
set { resman = value; }
|
||||
get { return resman; }
|
||||
}
|
||||
#endregion interface properties
|
||||
|
||||
#region Initialization and Close
|
||||
public bool Initialize(Version AyaNovaVersion, LocalizedTextTable localizedText)
|
||||
{
|
||||
LocaleText = localizedText;
|
||||
// bLicensed = (!string.IsNullOrEmpty(AyaBizUtils.PluginLicensedVersion("QuickNotification")));
|
||||
//case 2094
|
||||
bLicensed = AyaBizUtils.PluginAllowed("QuickNotification", AyaNova.PlugIn.QuickNotification.Timestamp.BuildAt);
|
||||
|
||||
if (!bLicensed && AyaBizUtils.PluginTooNew("QuickNotification", AyaNova.PlugIn.QuickNotification.Timestamp.BuildAt))
|
||||
{
|
||||
MessageBox.Show(
|
||||
"NOT LICENSED!\r\n\r\nThis Quick Notification plugin was built " +
|
||||
AyaNova.PlugIn.QuickNotification.Timestamp.BuildAt.ToString() + "\r\n" +
|
||||
"but your license subscription for it ended " +
|
||||
AyaBizUtils.PluginSubscriptionDate("QuickNotification").ToString() + "\r\n" +
|
||||
"\r\nDowngrade back to your previous version or purchase a subscription to use this plugin.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AyaNovaVersion.Major < 7)
|
||||
{
|
||||
MessageBox.Show("This QuickNotification plugin requires AyaNova version 7 or newer");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ObjectsWeCanDealWith = new List<RootObjectTypes>();
|
||||
ObjectsWeCanDealWith.Add(RootObjectTypes.Nothing);
|
||||
ObjectsWeCanDealWith.Add(RootObjectTypes.User);
|
||||
ObjectsWeCanDealWith.Add(RootObjectTypes.Schedule);
|
||||
ObjectsWeCanDealWith.Add(RootObjectTypes.WorkorderService);
|
||||
ObjectsWeCanDealWith.Add(RootObjectTypes.Workorder);
|
||||
ObjectsWeCanDealWith.Add(RootObjectTypes.Memo);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
;
|
||||
}
|
||||
#endregion Initialization and close
|
||||
|
||||
#region ShowMenu?
|
||||
public bool SingleObjectMenuShow(RootObjectTypes objectType)
|
||||
{
|
||||
|
||||
return (ObjectsWeCanDealWith.Contains(objectType));
|
||||
}
|
||||
|
||||
public bool MultipleObjectsMenuShow(RootObjectTypes objectType)
|
||||
{
|
||||
|
||||
return (ObjectsWeCanDealWith.Contains(objectType));
|
||||
}
|
||||
|
||||
#endregion show menu?
|
||||
|
||||
#region Menu options
|
||||
public List<AyaNovaPluginMenuItem> SingleObjectMenuOptions(RootObjectTypes objectType, object ayaNovaObject)
|
||||
{
|
||||
if (!ObjectsWeCanDealWith.Contains(objectType)) return null;
|
||||
if (!PFC()) return null;
|
||||
List<AyaNovaPluginMenuItem> list = new List<AyaNovaPluginMenuItem>();
|
||||
switch (objectType)
|
||||
{
|
||||
default:
|
||||
//If it's not nothing and we already know it's something we can deal with
|
||||
//then present the export
|
||||
list.Add(new AyaNovaPluginMenuItem("MESSAGE_SELECTED", "Send quick notification", null, null));
|
||||
break;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<AyaNovaPluginMenuItem> MultipleObjectsMenuOptions(RootObjectTypes objectType)
|
||||
{
|
||||
if (!ObjectsWeCanDealWith.Contains(objectType)) return null;
|
||||
if (!PFC()) return null;
|
||||
if (objectType == RootObjectTypes.Nothing) return null;
|
||||
List<AyaNovaPluginMenuItem> list = new List<AyaNovaPluginMenuItem>();
|
||||
list.Add(new AyaNovaPluginMenuItem("MESSAGE_SELECTED", "Send quick notification", null, null));
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pre flight check
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool PFC()
|
||||
{
|
||||
if (!bLicensed)
|
||||
{
|
||||
ShowWarning("An AyaNova QuickNotification license is required to use this plugin.", "Not licensed");
|
||||
return false;
|
||||
}
|
||||
if (AyaBizUtils.Lite)
|
||||
{
|
||||
ShowWarning("QuickNotification can not be used with AyaNova Lite edition.", "AyaNova Lite not supported");
|
||||
return false;
|
||||
}
|
||||
if (!AyaBizUtils.GlobalSettings.UseNotification)
|
||||
{
|
||||
ShowWarning("This QuickNotification plugin uses AyaNova notification services.\r\n" +
|
||||
"Currently \"Use notification\" is set to False in AyaNova Global settings.\r\n" +
|
||||
"Set it to True to proceed.", "Notification is off");
|
||||
return false;
|
||||
}
|
||||
if (Subscribers.Count == 0)
|
||||
{
|
||||
ShowWarning("No users are subscribed to the \"Quick Notification\" event in AyaNova.\r\n" +
|
||||
"Only users subscribing to the \"Quick Notification\" event in their notification subscriptions\r\n" +
|
||||
"can be sent quick notifications.",
|
||||
"No users can be notified");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void ShowWarning(string swarn, string scaption)
|
||||
{
|
||||
MessageBox.Show(swarn, scaption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Menu Commands
|
||||
|
||||
#region LIST OBJECT COMMAND
|
||||
/// <summary>
|
||||
/// LIST OBJECT
|
||||
/// </summary>
|
||||
/// <param name="commandKey"></param>
|
||||
/// <param name="objectType"></param>
|
||||
/// <param name="objectIDList"></param>
|
||||
/// <param name="listObject"></param>
|
||||
/// <returns></returns>
|
||||
public bool CommandSelectedForList(string commandKey, RootObjectTypes objectType, List<Guid> objectIDList, object listObject)
|
||||
{
|
||||
NotifyList.Clear();
|
||||
upl = null;//case 3115
|
||||
bool bAllItemsInGridWereSelected = objectIDList.Count == 0;
|
||||
if (commandKey == "MESSAGE_SELECTED")
|
||||
{
|
||||
switch (objectType)
|
||||
{
|
||||
case RootObjectTypes.Schedule:
|
||||
{
|
||||
#region From schedule form
|
||||
bool bHasAppointments = false;
|
||||
//appointements
|
||||
if (listObject != null && listObject is System.Collections.Generic.List<AppointmentList.AppointmentListInfo>)
|
||||
{
|
||||
System.Collections.Generic.List<AppointmentList.AppointmentListInfo> aptlist = (System.Collections.Generic.List<AppointmentList.AppointmentListInfo>)listObject;
|
||||
if (aptlist.Count > 0) bHasAppointments = true;
|
||||
foreach (AppointmentList.AppointmentListInfo apt in aptlist)
|
||||
{
|
||||
switch (apt.SourceObjectType)
|
||||
{
|
||||
case RootObjectTypes.WorkorderItemScheduledUser:
|
||||
{
|
||||
InsertItem(apt.Subject, LocaleText.GetLocalizedText("O.WorkorderItemScheduledUser"), apt.AppliesToObjectID,true);
|
||||
}
|
||||
break;
|
||||
case RootObjectTypes.ScheduleMarker:
|
||||
{
|
||||
#region schedmarkers
|
||||
|
||||
////Could be a bunch by region , global , dispatchzone, schedusergroup
|
||||
////or could be a single by one user ID
|
||||
switch (apt.AppliesToObjectType)
|
||||
{
|
||||
case RootObjectTypes.User:
|
||||
InsertItem(apt.Subject, LocaleText.GetLocalizedText("O.ScheduleMarker"), apt.AppliesToObjectID,true);
|
||||
break;
|
||||
case RootObjectTypes.Region:
|
||||
{
|
||||
//Loop through all active scheduleable users
|
||||
//if the region ID matches the marker region ID then
|
||||
//add a marker on the calendar for it
|
||||
foreach (UserListScheduleable.UserListScheduleableInfo ui in UserList)
|
||||
{
|
||||
if (!ui.Active) continue;
|
||||
//case 58
|
||||
if (apt.AppliesToObjectID == GZTW.AyaNova.BLL.Region.DefaultRegionID)//SM is for default region? Then applies to everyone
|
||||
InsertItem(apt.Subject, LocaleText.GetLocalizedText("O.ScheduleMarker"), apt.AppliesToObjectID,true);
|
||||
else if (ui.RegionID == GZTW.AyaNova.BLL.Region.DefaultRegionID)//User is in default region? Then applies to them
|
||||
InsertItem(apt.Subject, LocaleText.GetLocalizedText("O.ScheduleMarker"), apt.AppliesToObjectID,true);
|
||||
else if (ui.RegionID == apt.AppliesToObjectID)//SM and User in same non default region
|
||||
InsertItem(apt.Subject, LocaleText.GetLocalizedText("O.ScheduleMarker"), apt.AppliesToObjectID,true);
|
||||
else continue;//no match
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RootObjectTypes.DispatchZone:
|
||||
{
|
||||
//Loop through all active scheduleable users
|
||||
//if the Dispatch zone ID matches the marker zone ID then
|
||||
//add a marker on the calendar for it
|
||||
foreach (UserListScheduleable.UserListScheduleableInfo ui in UserList)
|
||||
if (ui.Active && ui.DispatchZoneID == apt.AppliesToObjectID)
|
||||
InsertItem(apt.Subject, LocaleText.GetLocalizedText("O.ScheduleMarker"), apt.AppliesToObjectID,true);
|
||||
}
|
||||
break;
|
||||
case RootObjectTypes.ScheduleableUserGroup:
|
||||
{
|
||||
ScheduleableUserGroupUsersList ScheduleMarkerGroup = ScheduleableUserGroupUsersList.GetList(apt.AppliesToObjectID);
|
||||
//Loop through all active scheduleable users
|
||||
//if they are in the ScheduleableUserGroup then
|
||||
//add a marker on the calendar for it
|
||||
foreach (UserListScheduleable.UserListScheduleableInfo ui in UserList)
|
||||
if (ui.Active && ScheduleMarkerGroup.Contains(ui.ID))
|
||||
InsertItem(apt.Subject, LocaleText.GetLocalizedText("O.ScheduleMarker"), apt.AppliesToObjectID,true);
|
||||
}
|
||||
break;
|
||||
|
||||
case RootObjectTypes.Global:
|
||||
{
|
||||
|
||||
//WARNING: this code makes the assumption that
|
||||
//all ACTIVE users are in the calendar owner collection
|
||||
//and does not check to see if they exist or not
|
||||
|
||||
|
||||
//Loop through all active scheduleable users
|
||||
//add a marker on the calendar for each one as this applies to everyone
|
||||
foreach (UserListScheduleable.UserListScheduleableInfo ui in UserList)
|
||||
if (ui.Active)
|
||||
InsertItem(apt.Subject, LocaleText.GetLocalizedText("O.ScheduleMarker"), apt.AppliesToObjectID,true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endregion schedmarkers
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//all user resources
|
||||
foreach (Guid id in objectIDList)
|
||||
InsertItem(LocaleText.GetLocalizedText("UserTypes.Label.Schedulable"), LocaleText.GetLocalizedText("O.ScheduleForm"), id,!bHasAppointments);
|
||||
|
||||
#endregion From schedule form
|
||||
}
|
||||
break;
|
||||
case RootObjectTypes.User:
|
||||
{
|
||||
#region user list form
|
||||
if (bAllItemsInGridWereSelected)
|
||||
{
|
||||
UserList ul = (UserList)listObject;
|
||||
foreach (UserList.UserListInfo i in ul)
|
||||
InsertItem("", LocaleText.GetLocalizedText("O.User"), i.LT_User_Label_LastName.Value, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Guid g in objectIDList)
|
||||
InsertItem("", LocaleText.GetLocalizedText("O.User"), g, true);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
case RootObjectTypes.WorkorderService:
|
||||
{
|
||||
#region Service wo tree lists
|
||||
Type t = listObject.GetType();
|
||||
switch (t.Name)
|
||||
{
|
||||
case "WorkorderServiceList":
|
||||
{
|
||||
WorkorderServiceList l = (WorkorderServiceList)listObject;
|
||||
|
||||
foreach (WorkorderServiceList.WorkorderServiceListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_O_Workorder.Value))
|
||||
{
|
||||
//iterate all users in wo
|
||||
Workorder w = Workorder.GetItemNoMRU(i.LT_O_Workorder.Value);
|
||||
InsertWorkorder(w, i.LT_O_Workorder.Display);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "WorkorderServiceScheduledUserList":
|
||||
{
|
||||
WorkorderServiceScheduledUserList l = (WorkorderServiceScheduledUserList)listObject;
|
||||
string sourcecat = LocaleText.GetLocalizedText(l.LocaleKey);
|
||||
|
||||
foreach (WorkorderServiceScheduledUserList.WorkorderServiceScheduledUserListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_WorkorderItemScheduledUser_Label_ID))
|
||||
{
|
||||
InsertItem(i.LT_O_Workorder.Display +
|
||||
" - " +
|
||||
i.LT_WorkorderItemScheduledUser_Label_StartDate.ToString(),
|
||||
sourcecat,
|
||||
i.LT_WorkorderItemScheduledUser_Label_UserID.Value,
|
||||
true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "WorkorderServiceLaborList":
|
||||
{
|
||||
WorkorderServiceLaborList l = (WorkorderServiceLaborList)listObject;
|
||||
string sourcecat = LocaleText.GetLocalizedText(l.LocaleKey);
|
||||
foreach (WorkorderServiceLaborList.WorkorderServiceLaborListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_WorkorderItemLabor_Label_ID))
|
||||
InsertItem(i.LT_O_Workorder.Display +
|
||||
" - " +
|
||||
i.LT_WorkorderItemLabor_Label_ServiceStartDate.ToString(),
|
||||
sourcecat,
|
||||
i.LT_WorkorderItemLabor_Label_UserID.Value,
|
||||
true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "WorkorderServiceTravelList":
|
||||
{
|
||||
WorkorderServiceTravelList l = (WorkorderServiceTravelList)listObject;
|
||||
string sourcecat = LocaleText.GetLocalizedText(l.LocaleKey);
|
||||
foreach (WorkorderServiceTravelList.WorkorderServiceTravelListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_WorkorderItemTravel_Label_ID))
|
||||
InsertItem(i.LT_O_Workorder.Display +
|
||||
" - " +
|
||||
i.LT_WorkorderItemTravel_Label_TravelStartDate.ToString(),
|
||||
sourcecat,
|
||||
Workorder.GetWorkorderByRelativeNoMRU(RootObjectTypes.WorkorderItemTravel,i.LT_WorkorderItemTravel_Label_ID).WorkorderItems[i.LT_WorkorderItem_Label_ID].Travels[i.LT_WorkorderItemTravel_Label_ID.ToString()].UserID,
|
||||
true);
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "WorkorderServiceItemList":
|
||||
{
|
||||
WorkorderServiceItemList l = (WorkorderServiceItemList)listObject;
|
||||
|
||||
foreach (WorkorderServiceItemList.WorkorderServiceItemListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_WorkorderItem_Label_ID))
|
||||
{
|
||||
//iterate all users in wo item
|
||||
Workorder w = Workorder.GetItemNoMRU(i.LT_O_Workorder.Value);
|
||||
InsertWorkorderItemUsers(w.WorkorderItems[i.LT_WorkorderItem_Label_ID], i.LT_O_Workorder.Display);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "WorkorderServicePartList":
|
||||
{
|
||||
WorkorderServicePartList l = (WorkorderServicePartList)listObject;
|
||||
|
||||
foreach (WorkorderServicePartList.WorkorderServicePartListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_WorkorderItemPart_Label_ID))
|
||||
{
|
||||
//iterate all users in wo item
|
||||
Workorder w = Workorder.GetItemNoMRU(i.LT_O_Workorder.Value);
|
||||
InsertWorkorderItemUsers(w.WorkorderItems[i.LT_WorkorderItem_Label_ID], i.LT_O_Workorder.Display);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "WorkorderServiceLoanList":
|
||||
{
|
||||
WorkorderServiceLoanList l = (WorkorderServiceLoanList)listObject;
|
||||
|
||||
foreach (WorkorderServiceLoanList.WorkorderServiceLoanListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_WorkorderItemLoan_Label_ID))
|
||||
{
|
||||
//iterate all users in wo item
|
||||
Workorder w = Workorder.GetItemNoMRU(i.LT_O_Workorder.Value);
|
||||
InsertWorkorderItemUsers(w.WorkorderItems[i.LT_WorkorderItem_Label_ID], i.LT_O_Workorder.Display);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "WorkorderServiceExpenseList":
|
||||
{
|
||||
WorkorderServiceExpenseList l = (WorkorderServiceExpenseList)listObject;
|
||||
|
||||
foreach (WorkorderServiceExpenseList.WorkorderServiceExpenseListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_WorkorderItemMiscExpense_Label_ID))
|
||||
{
|
||||
//iterate all users in wo item
|
||||
Workorder w = Workorder.GetItemNoMRU(i.LT_O_Workorder.Value);
|
||||
InsertWorkorderItemUsers(w.WorkorderItems[i.LT_WorkorderItem_Label_ID], i.LT_O_Workorder.Display);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "WorkorderServiceCustomList":
|
||||
{
|
||||
WorkorderServiceCustomList l = (WorkorderServiceCustomList)listObject;
|
||||
|
||||
foreach (WorkorderServiceCustomList.WorkorderServiceCustomListInfo i in l)
|
||||
{
|
||||
if (bAllItemsInGridWereSelected || objectIDList.Contains(i.LT_WorkorderItem_Label_ID))
|
||||
{
|
||||
//iterate all users in wo item
|
||||
Workorder w = Workorder.GetItemNoMRU(i.LT_O_Workorder.Value);
|
||||
InsertWorkorderItemUsers(w.WorkorderItems[i.LT_WorkorderItem_Label_ID], i.LT_O_Workorder.Display);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
case RootObjectTypes.Memo:
|
||||
{
|
||||
#region memo
|
||||
string language=User.CurrentUserLanguage;
|
||||
if (bAllItemsInGridWereSelected)
|
||||
{
|
||||
MemoList ml = (MemoList)listObject;
|
||||
foreach(MemoList.MemoListInfo i in ml)
|
||||
{
|
||||
MemoFetcher m = MemoFetcher.GetItem(i.ID, language);
|
||||
InsertItem(LocaleText.GetLocalizedText("O.Memo"), m.ShortHeader.Replace("\r\n", " "), m.FromID, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Guid g in objectIDList)
|
||||
{
|
||||
MemoFetcher m = MemoFetcher.GetItem(g, language);
|
||||
InsertItem(LocaleText.GetLocalizedText("O.Memo"), m.ShortHeader.Replace("\r\n", " "), m.FromID, true);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ShowQuickNotifyForm();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion list object command
|
||||
|
||||
#region SINGLE OBJECT COMMAND
|
||||
/// <summary>
|
||||
/// SINGLE OBJECT
|
||||
/// </summary>
|
||||
/// <param name="commandKey"></param>
|
||||
/// <param name="objectType"></param>
|
||||
/// <param name="ayaNovaObject"></param>
|
||||
public void CommandSelectedForSingleObject(string commandKey, RootObjectTypes objectType, object ayaNovaObject)
|
||||
{
|
||||
NotifyList.Clear();
|
||||
upl = null;//case 3115
|
||||
switch (commandKey)
|
||||
{
|
||||
|
||||
case "MESSAGE_SELECTED":
|
||||
{
|
||||
switch (objectType)
|
||||
{
|
||||
case RootObjectTypes.User:
|
||||
{
|
||||
if(ayaNovaObject!=null && ayaNovaObject is User)
|
||||
InsertItem("", LocaleText.GetLocalizedText("O.User"), ((User)ayaNovaObject).ID, true);
|
||||
}
|
||||
break;
|
||||
case RootObjectTypes.Nothing:
|
||||
{
|
||||
foreach (UserPickList.UserPickListInfo i in UserList)
|
||||
{
|
||||
if(i.Type == UserTypes.Schedulable || i.Type==UserTypes.NonSchedulable || i.Type==UserTypes.Administrator)
|
||||
InsertItem("All Users", LocaleText.GetLocalizedText("O.User"), i.ID, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RootObjectTypes.Workorder:
|
||||
{
|
||||
if (ayaNovaObject != null && ayaNovaObject is Workorder)
|
||||
InsertWorkorder((Workorder)ayaNovaObject, "");
|
||||
}
|
||||
break;
|
||||
case RootObjectTypes.Memo:
|
||||
{
|
||||
#region memo
|
||||
string language = User.CurrentUserLanguage;
|
||||
if (ayaNovaObject != null && ayaNovaObject is MemoFetcher)
|
||||
{
|
||||
MemoFetcher m = (MemoFetcher)ayaNovaObject;
|
||||
InsertItem(LocaleText.GetLocalizedText("O.Memo"), m.ShortHeader.Replace("\r\n", " "), m.FromID, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
ShowQuickNotifyForm();
|
||||
}
|
||||
#endregion single object command
|
||||
|
||||
|
||||
#region Insert workorder users
|
||||
private void InsertWorkorder(Workorder w, string workorderdisplay)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(workorderdisplay))
|
||||
workorderdisplay = w.WorkorderService.ServiceNumber.ToString();
|
||||
foreach (WorkorderItem wi in w.WorkorderItems)
|
||||
{
|
||||
InsertWorkorderItemUsers(wi,workorderdisplay);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void InsertWorkorderItemUsers(WorkorderItem wi, string workorderdisplay)
|
||||
{
|
||||
string sourcecat = "";
|
||||
sourcecat = LocaleText.GetLocalizedText("O.WorkorderItemScheduledUser");
|
||||
foreach (WorkorderItemScheduledUser su in wi.ScheduledUsers)
|
||||
{
|
||||
InsertItem(workorderdisplay + " - " + su.StartDate.ToString(), sourcecat, su.UserID, true);
|
||||
}
|
||||
|
||||
sourcecat = LocaleText.GetLocalizedText("O.WorkorderItemLabor");
|
||||
foreach (WorkorderItemLabor su in wi.Labors)
|
||||
{
|
||||
InsertItem(workorderdisplay + " - " + su.ServiceStartDate.ToString(), sourcecat, su.UserID, true);
|
||||
}
|
||||
|
||||
sourcecat = LocaleText.GetLocalizedText("O.WorkorderItemTravel");
|
||||
foreach (WorkorderItemTravel su in wi.Travels)
|
||||
{
|
||||
InsertItem(workorderdisplay + " - " + su.TravelStartDate.ToString(), sourcecat, su.UserID, true);
|
||||
}
|
||||
}
|
||||
#endregion insert workorder users
|
||||
|
||||
#endregion menu commands
|
||||
|
||||
#region QuickNotifyForm
|
||||
/// <summary>
|
||||
/// Show the form, take the selections and send the messages
|
||||
/// </summary>
|
||||
public void ShowQuickNotifyForm()
|
||||
{
|
||||
NotifyList.AllowNew = false;
|
||||
QuickNotificationCompose qn = new QuickNotificationCompose(this);
|
||||
DialogResult dr=qn.ShowDialog();
|
||||
NotifyList.AllowNew = true;
|
||||
if (dr == DialogResult.OK)
|
||||
{
|
||||
if (HasSelectedUsers && qn.HasSomethingToSend)
|
||||
{
|
||||
foreach (Guid id in SelectedUserList)
|
||||
{
|
||||
NotifyEvent.AddOrUpdateEvent(RootObjectTypes.User, id, (int)UserEvent.QuickNotification, id, qn.MesageToSend.Trim());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
qn.Dispose();
|
||||
}
|
||||
#endregion quicknotifyform
|
||||
|
||||
#endregion
|
||||
|
||||
#region Notify subscribers
|
||||
private List<Guid> mSubscribers;
|
||||
public List<Guid> Subscribers
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mSubscribers == null)
|
||||
mSubscribers = NotifySubscribersListFetcher.GetItem((int)UserEvent.QuickNotification, RootObjectTypes.User, Guid.Empty);
|
||||
return mSubscribers;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region BindingList
|
||||
|
||||
UserPickList upl;
|
||||
public UserPickList UserList
|
||||
{
|
||||
get
|
||||
{
|
||||
if (upl == null)
|
||||
upl = UserPickList.GetList(false);
|
||||
return upl;
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertItem(string source, string category, Guid userID, bool bSend)
|
||||
{
|
||||
if (userID == Guid.Empty) return;
|
||||
|
||||
//case 3115 - weed out empty users
|
||||
UserPickList.UserPickListInfo upi = UserList[userID.ToString()];
|
||||
if (!upi.Active)
|
||||
return;
|
||||
|
||||
if (!Subscribers.Contains(userID)) bSend = false;
|
||||
NotifyList.Add(new NotifyItem(category, source.Replace("\r\n"," "), UserList[userID], userID,bSend));
|
||||
|
||||
}
|
||||
|
||||
//http://msdn.microsoft.com/en-us/library/ms132679.aspx
|
||||
BindingList<NotifyItem> mNotifyList;
|
||||
public BindingList<NotifyItem> NotifyList
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mNotifyList == null)
|
||||
{
|
||||
mNotifyList = new BindingList<NotifyItem>();
|
||||
mNotifyList.AllowNew = true;
|
||||
mNotifyList.AllowRemove = false;
|
||||
mNotifyList.RaiseListChangedEvents = true;
|
||||
mNotifyList.AllowEdit = true;
|
||||
}
|
||||
return mNotifyList;
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckAllForUser(bool bCheck, Guid UserID)
|
||||
{
|
||||
foreach (NotifyItem i in NotifyList)
|
||||
{
|
||||
if (i.UserID == UserID)
|
||||
i.Send = bCheck;
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckAll(bool bCheck)
|
||||
{
|
||||
if (NotifyList.Count == 0) return;
|
||||
|
||||
foreach (NotifyItem i in NotifyList)
|
||||
if (Subscribers.Contains(i.UserID)) i.Send = bCheck;
|
||||
}
|
||||
|
||||
public bool HasSelectedUsers
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (NotifyItem i in NotifyList)
|
||||
if (i.Send) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public System.Collections.Generic.List<Guid> SelectedUserList
|
||||
{
|
||||
get
|
||||
{
|
||||
System.Collections.Generic.List<Guid> lsSelected = new List<Guid>();
|
||||
foreach (NotifyItem i in NotifyList)
|
||||
{
|
||||
if (i.Send)
|
||||
{
|
||||
if (!lsSelected.Contains(i.UserID))
|
||||
lsSelected.Add(i.UserID);
|
||||
}
|
||||
}
|
||||
return lsSelected;
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyList_ListChanged(object sender, ListChangedEventArgs e)
|
||||
{
|
||||
//MessageBox.Show(e.ListChangedType.ToString());
|
||||
}
|
||||
#endregion binding list
|
||||
}
|
||||
|
||||
#region NotifyItem
|
||||
|
||||
|
||||
public class NotifyItem //: INotifyPropertyChanged
|
||||
{
|
||||
public NotifyItem() { }
|
||||
public NotifyItem( string category, string source, string username, Guid userID, bool bSend)
|
||||
{
|
||||
mUserID = userID;
|
||||
mSource = source;
|
||||
mUserName = username;
|
||||
mCategory = category;
|
||||
mSend = bSend;
|
||||
}
|
||||
|
||||
private string mCategory;
|
||||
private Guid mUserID;
|
||||
private string mSource;
|
||||
private string mUserName;
|
||||
private bool mSend;
|
||||
|
||||
public string Category { get { return mCategory; } set { mCategory = value; } }
|
||||
public string Source { get { return mSource; } set { mSource = value; } }
|
||||
[Browsable(false)]
|
||||
public Guid UserID { get { return mUserID; } set { mUserID = value; } }
|
||||
public string UserName { get { return mUserName; } set { mUserName = value; } }
|
||||
public bool Send
|
||||
{
|
||||
get
|
||||
{
|
||||
return mSend;
|
||||
}
|
||||
set
|
||||
{
|
||||
// if (mSend != value)
|
||||
//{
|
||||
mSend = value;
|
||||
// NotifyPropertyChanged("Send");
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
//private void NotifyPropertyChanged(String info)
|
||||
//{
|
||||
// if (PropertyChanged != null)
|
||||
// {
|
||||
// PropertyChanged(this, new PropertyChangedEventArgs(info));
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user