1220 lines
40 KiB
C#
1220 lines
40 KiB
C#
///////////////////////////////////////////////////////////
|
|
// ClientServiceRequest.cs
|
|
// Implementation of Class ClientServiceRequest
|
|
// CSLA type: Editable Root
|
|
// Created on: 07-Jun-2004 8:41:30 AM
|
|
// Object design: Joyce & John Nov 8th 2006
|
|
// Coded: John 8-Nov-2006
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.ComponentModel;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Contains request for service entered by the <see cref="Client"/> directly via WBI or other means
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ClientServiceRequest : BusinessBase
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
private bool bReadOnly;
|
|
private Guid mID;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
|
|
private string mDetails = "";
|
|
private string mTitle = null;
|
|
|
|
private Guid mClientID;
|
|
private Guid mUnitID;
|
|
private Guid mWorkorderItemID;
|
|
private string mClientRef = "";
|
|
private ClientServiceRequestStatus mStatus=ClientServiceRequestStatus.Open;
|
|
private ClientServiceRequestPriority mPriority = ClientServiceRequestPriority.NotUrgent;
|
|
|
|
private string mRequestedBy = "";
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private ClientServiceRequest()
|
|
{
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly = false;
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified = new SmartDate();
|
|
mCreator = Guid.Empty;
|
|
mModifier = Guid.Empty;
|
|
|
|
mClientID = Guid.Empty;
|
|
//pre-break Title rule
|
|
Title = "";
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties
|
|
|
|
/// <summary>
|
|
/// Get internal id number Read only property because it's set internally, not
|
|
/// externally
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get created date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get modified date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user record ID of person who created this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user ID of person who modified this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Details about service required
|
|
/// for technician - > ends up in workorder item
|
|
/// notes field
|
|
/// </summary>
|
|
public string Details
|
|
{
|
|
get
|
|
{
|
|
return mDetails;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mDetails != value)
|
|
{
|
|
mDetails = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Short descriptive title of
|
|
/// service required
|
|
/// (ends up in workorder item summary field)
|
|
/// </summary>
|
|
public string Title
|
|
{
|
|
get
|
|
{
|
|
return mTitle;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mTitle != value)
|
|
{
|
|
mTitle = value;
|
|
|
|
BrokenRules.Assert("TitleRequired",
|
|
"Error.Object.RequiredFieldEmpty,ClientServiceRequest.Label.Title",
|
|
"Title", value.Length == 0);
|
|
|
|
BrokenRules.Assert("TitleLength",
|
|
"Error.Object.FieldLengthExceeded255,ClientServiceRequest.Label.Title",
|
|
"Title", value.Length > 255);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Client's reference number
|
|
/// </summary>
|
|
public string ClientRef
|
|
{
|
|
get
|
|
{
|
|
return mClientRef;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mClientRef != value)
|
|
{
|
|
mClientRef = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Name of person requesting service
|
|
/// copied to workorder contact field if filled in
|
|
/// </summary>
|
|
public string RequestedBy
|
|
{
|
|
get
|
|
{
|
|
return mRequestedBy;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mRequestedBy != value)
|
|
{
|
|
mRequestedBy = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// ID of client requesting service
|
|
/// </summary>
|
|
public Guid ClientID
|
|
{
|
|
get
|
|
{
|
|
return mClientID;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mClientID != value)
|
|
{
|
|
mClientID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// ID of Unit service is requested for
|
|
/// </summary>
|
|
public Guid UnitID
|
|
{
|
|
get
|
|
{
|
|
return mUnitID;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mUnitID != value)
|
|
{
|
|
mUnitID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// ID of WorkorderItem that
|
|
/// request has been accepted to
|
|
/// (set internally)
|
|
/// </summary>
|
|
public Guid WorkorderItemID
|
|
{
|
|
get
|
|
{
|
|
return mWorkorderItemID;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Status of request, read write with the exception
|
|
/// that a request that is currently Accepted can not be changed.
|
|
/// </summary>
|
|
public ClientServiceRequestStatus Status
|
|
{
|
|
get
|
|
{
|
|
return mStatus;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mStatus != ClientServiceRequestStatus.Accepted && mStatus != value)
|
|
{
|
|
mStatus = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Customer selected priority
|
|
/// </summary>
|
|
public ClientServiceRequestPriority Priority
|
|
{
|
|
get
|
|
{
|
|
return mPriority;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
mPriority = value;
|
|
MarkDirty();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Object is editable if it's not set to status accepted
|
|
/// and current user is not read only
|
|
/// </summary>
|
|
public bool IsEditable
|
|
{
|
|
get
|
|
{
|
|
if (Status == ClientServiceRequestStatus.Accepted || Status== ClientServiceRequestStatus.Closed) return false;
|
|
if (bReadOnly) return false;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Throw an error when a read only user
|
|
/// tries to set a property
|
|
/// (this should normally never be called unless someone is using the developer api since the UI
|
|
/// should prevent it from happening initially)
|
|
/// </summary>
|
|
private void ThrowSetError()
|
|
{
|
|
throw new System.Security.SecurityException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.ClientServiceRequest")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "ClientServiceRequest" + mID.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if (obj == null || GetType() != obj.GetType()) return false;
|
|
ClientServiceRequest c = (ClientServiceRequest)obj;
|
|
return mID == c.mID;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("ClientServiceRequest" + mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Searching
|
|
|
|
/// <summary>
|
|
/// Returns a search result object based on search terms
|
|
/// for the ID specified
|
|
/// </summary>
|
|
/// <param Title="ID"></param>
|
|
/// <param Title="searchTerms"></param>
|
|
/// <returns></returns>
|
|
public static SearchResult GetSearchResult(Guid ID, string[]searchTerms)
|
|
{
|
|
|
|
|
|
if (AyaBizUtils.Right("Object.ClientServiceRequest") < (int)SecurityLevelTypes.ReadOnly)
|
|
return new SearchResult();
|
|
|
|
SearchResult sr = new SearchResult();
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr = DBUtil.GetReaderFromSQLString(
|
|
|
|
"SELECT aClient.aRegionID, aClientServiceRequest.aCreated, aClientServiceRequest.aModified, aClientServiceRequest.aCreator, aClientServiceRequest.aModifier, aClientServiceRequest.aTitle, " +
|
|
" aClientServiceRequest.aDetails, aClientServiceRequest.aClientRef FROM aClientServiceRequest LEFT JOIN " +
|
|
"aClient ON aClientServiceRequest.aClientID = aClient.aID " +
|
|
"WHERE (aClientServiceRequest.aID = @ID)"
|
|
, ID);
|
|
|
|
if (!dr.Read())
|
|
return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for ClientServiceRequestID: " + ID.ToString());
|
|
|
|
if (!AyaBizUtils.InYourRegion(dr.GetGuid("aRegionID"))) return new SearchResult();//case 58
|
|
|
|
sr.Description = dr.GetString("aTitle");
|
|
sb.Append(sr.Description);
|
|
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aDetails"));
|
|
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aClientRef"));
|
|
|
|
|
|
|
|
sr.Created = DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
sr.Modified = DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
sr.Creator = dr.GetGuid("aCreator");
|
|
sr.Modifier = dr.GetGuid("aModifier");
|
|
|
|
|
|
|
|
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
|
|
|
|
|
|
|
|
//Formulate results
|
|
ExtractAndRank er = new ExtractAndRank();
|
|
er.Process(sb.ToString().Trim(), searchTerms);
|
|
sr.Extract = er.Extract;
|
|
sr.Rank = er.Ranking;
|
|
sr.AncestorRootObjectID = ID;
|
|
sr.AncestorRootObjectType = RootObjectTypes.ClientServiceRequest;
|
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
/// <summary>
|
|
/// Sets request status to accepted and
|
|
/// creates a new workorder item in the indicated workorder
|
|
/// with data copied from the CSR to the workorder item.
|
|
///
|
|
/// </summary>
|
|
/// <param name="workorderID">Existing open workorder to add this request as a new workorder item
|
|
/// or if Guid.empty then a new workorder is created for this request item</param>
|
|
/// <returns>workorder object populated from request</returns>
|
|
public Workorder AcceptToWorkorder(Guid workorderID)
|
|
{
|
|
return accept(Workorder.GetItem(workorderID));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets request status to accepted and
|
|
/// creates a new workorder and workorder item
|
|
/// with data copied from the CSR to the workorder item
|
|
/// and various fields in the workorder header.
|
|
///
|
|
/// </summary>
|
|
/// <returns>New workorder object populated from request</returns>
|
|
public Workorder AcceptToNewWorkorder()
|
|
{
|
|
//case 870
|
|
Workorder w = null;
|
|
Guid gTemplate=TemplateServiceResolver.ResolveTemplate(mClientID, Guid.Empty);
|
|
|
|
if(gTemplate!=Guid.Empty)
|
|
w=Workorder.NewItem(gTemplate,mClientID);
|
|
else
|
|
w = Workorder.NewItem(WorkorderTypes.Service);
|
|
|
|
return accept(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Workorder accept(Workorder w)
|
|
{
|
|
WorkorderItem wi;
|
|
if (w.IsNew)
|
|
{
|
|
w.ClientID = mClientID;
|
|
w.Summary = mTitle;
|
|
w.CustomerReferenceNumber = mClientRef;
|
|
if (!string.IsNullOrEmpty(mRequestedBy))
|
|
w.CustomerContactName = mRequestedBy;
|
|
|
|
wi = w.WorkorderItems[0];
|
|
}
|
|
else
|
|
wi = w.WorkorderItems.Add(w);
|
|
|
|
wi.UnitID = mUnitID;
|
|
wi.Summary = mTitle;
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("ClientServiceRequest.Label.CustomerReferenceNumber"));
|
|
sb.Append(": ");
|
|
sb.Append(mClientRef);
|
|
sb.Append("\r\n");
|
|
sb.Append(PriorityLocalized(mPriority));
|
|
sb.Append("\r\n");
|
|
if (!string.IsNullOrEmpty(mRequestedBy))
|
|
{
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("ClientServiceRequest.Label.RequestedBy"));
|
|
sb.Append(": ");
|
|
sb.Append(mRequestedBy);
|
|
sb.Append("\r\n");
|
|
}
|
|
sb.Append(mDetails);
|
|
wi.TechNotes = sb.ToString();
|
|
|
|
mWorkorderItemID = wi.ID;
|
|
mStatus = ClientServiceRequestStatus.Accepted;
|
|
//case 969
|
|
w = (Workorder)w.Save();
|
|
MarkDirty();
|
|
Save();
|
|
return w;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the localized text representation of the indication priority enum
|
|
/// </summary>
|
|
/// <param name="p"></param>
|
|
/// <returns></returns>
|
|
public static string PriorityLocalized(ClientServiceRequestPriority p)
|
|
{
|
|
switch (p)
|
|
{
|
|
case ClientServiceRequestPriority.NotUrgent:
|
|
return LocalizedTextTable.GetLocalizedTextDirect("ClientServiceRequestPriority.NotUrgent");
|
|
|
|
case ClientServiceRequestPriority.ASAP:
|
|
return LocalizedTextTable.GetLocalizedTextDirect("ClientServiceRequestPriority.ASAP");
|
|
|
|
case ClientServiceRequestPriority.Emergency:
|
|
return LocalizedTextTable.GetLocalizedTextDirect("ClientServiceRequestPriority.Emergency");
|
|
|
|
}
|
|
return "";
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Flags request as rejected
|
|
/// and saves
|
|
/// </summary>
|
|
public void Reject()
|
|
{
|
|
mStatus = ClientServiceRequestStatus.Declined;
|
|
MarkDirty();
|
|
Save();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a new client service request
|
|
/// </summary>
|
|
/// <param name="clientID">Required, id of client request is for</param>
|
|
/// <returns></returns>
|
|
public static ClientServiceRequest NewItem(Guid clientID)
|
|
{
|
|
if (clientID == Guid.Empty)
|
|
throw new System.ApplicationException("CLIENT ID NOT VALID");
|
|
ClientServiceRequest c;
|
|
|
|
if (AyaBizUtils.Right("Object.ClientServiceRequest") > (int)SecurityLevelTypes.ReadOnly)
|
|
{
|
|
c = new ClientServiceRequest();
|
|
c.mClientID = clientID;
|
|
|
|
return c;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.ClientServiceRequest")));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Fetch existing ClientServiceRequest
|
|
/// </summary>
|
|
/// <returns>ClientServiceRequest</returns>
|
|
/// <param name="_ID">ClientServiceRequest Guid</param>
|
|
public static ClientServiceRequest GetItem(Guid _ID)
|
|
{
|
|
return GetItemMRU(_ID, true);
|
|
}
|
|
/// <summary>
|
|
/// Fetch existing client service request, do not add it to the user's MRU list
|
|
/// </summary>
|
|
/// <param name="_ID"></param>
|
|
/// <returns></returns>
|
|
public static ClientServiceRequest GetItemNoMRU(Guid _ID)
|
|
{
|
|
return GetItemMRU(_ID, false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetch existing client service request, optionally add it to the user's MRU list
|
|
/// See <see cref="UserMRU"/>
|
|
/// </summary>
|
|
/// <param name="_ID"></param>
|
|
/// <param name="TrackMRU"></param>
|
|
/// <returns></returns>
|
|
public static ClientServiceRequest GetItemMRU(Guid _ID, bool TrackMRU)
|
|
{
|
|
if (AyaBizUtils.Right("Object.ClientServiceRequest") > (int)SecurityLevelTypes.NoAccess)
|
|
return (ClientServiceRequest)DataPortal.Fetch(new Criteria(_ID, TrackMRU));
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.ClientServiceRequest")));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete ClientServiceRequest
|
|
/// </summary>
|
|
/// <param name="_ID">ClientServiceRequest GUID</param>
|
|
public static void DeleteItem(Guid _ID)
|
|
{
|
|
|
|
if (AyaBizUtils.Right("Object.ClientServiceRequest") > (int)SecurityLevelTypes.ReadWrite)
|
|
DataPortal.Delete(new Criteria(_ID,true));
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.ClientServiceRequest")));
|
|
}
|
|
|
|
|
|
#region Close flag
|
|
/// <summary>
|
|
/// Called when a work order is closed to flag any csr's that might be attached to it as closed
|
|
/// </summary>
|
|
/// <param name="_ID">Workorder GUID</param>
|
|
public static void CloseFlag(Guid _ID)
|
|
{
|
|
ClientServiceRequest.ClosedFlagger.Flag(_ID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Shared Notification Message Processor
|
|
internal static NotifyMessage GetNotificationMessage(NotifyMessageRequestData d)
|
|
{
|
|
//string Language=User.GetUserLanguage(MessageForUserID);
|
|
ClientServiceRequest c = ClientServiceRequest.GetItemNoMRU(d.RootObjectID);
|
|
string sClientName = NameFetcher.GetItem("CLIENT", "NAME", c.ClientID).RecordName;
|
|
string sEventDescription = LocalizedTextTable.GetLocalizedTextDirect("ClientServiceRequest.Label.Event.Created", d.Language);
|
|
string sMessage = sEventDescription;
|
|
string sSubject = sEventDescription;
|
|
NotifyMessage nm = null;
|
|
if (d.Format == NotifyDeliveryMessageFormats.Brief)
|
|
{
|
|
sMessage += "-" + sClientName + " " + PriorityLocalized(c.Priority);
|
|
if (d.MaxCharacters > 0 && sMessage.Length > d.MaxCharacters)
|
|
nm = new NotifyMessage("", sMessage.Substring(0, d.MaxCharacters));
|
|
else
|
|
nm = new NotifyMessage("", sMessage);
|
|
|
|
}
|
|
else
|
|
{
|
|
sSubject += ": " + sClientName + " " + PriorityLocalized(c.Priority);
|
|
sMessage += ": " + c.Title + "\r\n" + c.Details;
|
|
nm = new NotifyMessage(sSubject, sMessage);
|
|
|
|
}
|
|
return nm;
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
///
|
|
/// <param Title="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
//set to false to load items initially
|
|
bReadOnly = false;
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
|
|
try
|
|
{
|
|
dr = DBUtil.GetReaderFromSQLString("SELECT * FROM ACLIENTSERVICEREQUEST WHERE AID=@ID;", crit.ID);
|
|
if (!dr.Read())
|
|
DBUtil.ThrowFetchError("ClientServiceRequest ID: " + crit.ID.ToString());
|
|
|
|
//Standard fields
|
|
mID = dr.GetGuid("AID");
|
|
mCreated = DBUtil.ToLocal(dr.GetSmartDate("ACREATED"));
|
|
mModified = DBUtil.ToLocal(dr.GetSmartDate("AMODIFIED"));
|
|
mCreator = dr.GetGuid("ACREATOR");
|
|
mModifier = dr.GetGuid("AMODIFIER");
|
|
|
|
|
|
|
|
|
|
//ClientServiceRequest fields
|
|
mDetails = dr.GetString("ADETAILS");
|
|
//Unbreak rule:
|
|
Title = dr.GetString("ATITLE");
|
|
mClientRef = dr.GetString("ACLIENTREF");
|
|
mClientID = dr.GetGuid("ACLIENTID");
|
|
mUnitID = dr.GetGuid("AUNITID");
|
|
mWorkorderItemID = dr.GetGuid("AWORKORDERITEMID");
|
|
mStatus = (ClientServiceRequestStatus)dr.GetInt16("ASTATUS");
|
|
mPriority = (ClientServiceRequestPriority)dr.GetInt16("APRIORITY");
|
|
|
|
mRequestedBy = dr.GetString("AREQUESTEDBY");
|
|
if (dr != null) dr.Close();
|
|
|
|
/*
|
|
* Load child collection objects HERE IF ANY DOWN THE ROAD
|
|
*/
|
|
|
|
//Docs
|
|
|
|
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
MarkOld();
|
|
|
|
if(crit.TrackMRU)
|
|
if(AyaBizUtils.AllowAutomaticMRUOnUpdate) AyaBizUtils.MRU.Add(RootObjectTypes.ClientServiceRequest, mID);
|
|
|
|
//Get access rights level
|
|
bReadOnly = AyaBizUtils.Right("Object.ClientServiceRequest") < (int)SecurityLevelTypes.ReadWrite;
|
|
if (!bReadOnly)
|
|
{
|
|
if (mStatus == ClientServiceRequestStatus.Accepted || mStatus==ClientServiceRequestStatus.Closed)
|
|
bReadOnly = true;
|
|
}
|
|
|
|
}
|
|
|
|
#endregion fetch
|
|
|
|
#region Update
|
|
|
|
/// <summary>
|
|
/// Called by DataPortal to delete/add/update data into the database
|
|
/// </summary>
|
|
protected override void DataPortal_Update()
|
|
{
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
if (!IsNew)
|
|
DBUtil.CheckSafeToUpdate(this.mModified.Date, this.mID, "ACLIENTSERVICEREQUEST");
|
|
|
|
#region Delete
|
|
if (IsDeleted)
|
|
{
|
|
if (!IsEditable)
|
|
throw new System.ApplicationException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Object.NotDeleteable"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.ClientServiceRequest")
|
|
)
|
|
);
|
|
|
|
if (!IsNew)
|
|
{
|
|
|
|
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aClientServiceRequest WHERE aID = @ID;");
|
|
cmDelete.AddInParameter("@ID", DbType.Guid, this.mID);
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
DBUtil.RemoveKeywords(transaction, RootObjectTypes.ClientServiceRequest, this.mID);
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
}
|
|
|
|
//Remove any events for this object
|
|
if (AyaBizUtils.GlobalSettings.UseNotification)//Case 510
|
|
{
|
|
NotifyEvent.RemoveAllEventsForObject(this.mID);
|
|
}
|
|
//-----------------------------
|
|
}
|
|
MarkNew();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Add / Update
|
|
|
|
//get modification time temporarily, if update succeeds then
|
|
//set to this time
|
|
System.DateTime dtModified = DBUtil.CurrentWorkingDateTime;
|
|
DBCommandWrapper cm = null;
|
|
if (IsNew)//Add or update?
|
|
cm = DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO ACLIENTSERVICEREQUEST (AID, ATITLE, ADETAILS, ACLIENTID, ACLIENTREF, AREQUESTEDBY, " +
|
|
"ASTATUS, APRIORITY, AWORKORDERITEMID, AUNITID, ACREATED,AMODIFIED,ACREATOR,AMODIFIER " +
|
|
") " +
|
|
"VALUES (@ID,@TITLE,@DETAILS,@CLIENTID,@CLIENTREF, @REQUESTEDBY, " +
|
|
"@STATUS, @PRIORITY, @WORKORDERITEMID, @UNITID, @CREATED,@MODIFIED,@CURRENTUSERID,@CURRENTUSERID " +
|
|
")"
|
|
);
|
|
else
|
|
cm = DBUtil.GetCommandFromSQL(
|
|
"UPDATE ACLIENTSERVICEREQUEST SET AID=@ID, ATITLE=@TITLE, " +
|
|
"ADETAILS=@DETAILS, ACLIENTID=@CLIENTID, " +
|
|
"ACLIENTREF=@CLIENTREF, AREQUESTEDBY=@REQUESTEDBY, " +
|
|
"ASTATUS=@STATUS,APRIORITY=@PRIORITY, AWORKORDERITEMID=@WORKORDERITEMID, " +
|
|
"AUNITID=@UNITID, " +
|
|
"AMODIFIER=@CURRENTUSERID, AMODIFIED=@MODIFIED " +
|
|
"WHERE AID=@ID"
|
|
);
|
|
|
|
|
|
//ClientServiceRequest fields
|
|
cm.AddInParameter("@ID", DbType.Guid, mID);
|
|
cm.AddLargeStringInParameter("@DETAILS", mDetails);
|
|
cm.AddInParameter("@TITLE", DbType.String, mTitle);
|
|
cm.AddInParameter("@CLIENTREF", DbType.String, mClientRef);
|
|
cm.AddInParameter("@STATUS", DbType.Int16, (int)mStatus);
|
|
cm.AddInParameter("@PRIORITY", DbType.Int16, (int)mPriority);
|
|
cm.AddInParameter("@CLIENTID", DbType.Guid, mClientID);
|
|
cm.AddInParameter("@UNITID", DbType.Guid, mUnitID);
|
|
cm.AddInParameter("@WORKORDERITEMID", DbType.Guid, mWorkorderItemID);
|
|
|
|
cm.AddInParameter("@REQUESTEDBY", DbType.String, mRequestedBy);
|
|
|
|
//Standard fields
|
|
cm.AddInParameter("@CURRENTUSERID", DbType.Guid, CurrentUserID);
|
|
cm.AddInParameter("@CREATED", DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue);
|
|
cm.AddInParameter("@MODIFIED", DbType.DateTime, DBUtil.ToUTC(dtModified));
|
|
|
|
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, transaction);
|
|
|
|
|
|
//Process keywords
|
|
DBUtil.ProcessKeywords(transaction, this.mID, RootObjectTypes.ClientServiceRequest, IsNew, AyaBizUtils.Break(false,
|
|
mDetails, mTitle, mClientRef));
|
|
|
|
MarkOld();//db is now synched with object
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date = dtModified;
|
|
|
|
//Process events as necessary
|
|
if (AyaBizUtils.GlobalSettings.UseNotification)//Case 510
|
|
{
|
|
if (mStatus == ClientServiceRequestStatus.Accepted || mStatus==ClientServiceRequestStatus.Declined)
|
|
NotifyEvent.RemoveSpecificEventForObject(this.mID, (int)ClientServiceRequestEvent.Created);
|
|
else
|
|
NotifyEvent.AddOrUpdateEvent(RootObjectTypes.ClientServiceRequest, this.mID, (int)ClientServiceRequestEvent.Created);
|
|
|
|
//client notification case 53
|
|
if(mStatus==ClientServiceRequestStatus.Accepted)
|
|
ClientNotifyEvent.ProcessEvent(ClientNotifyEventType.CSRAccepted, mClientID, Guid.Empty, "",
|
|
"",this.ClientRef, mDetails, Guid.Empty,"",mTitle);
|
|
|
|
if (mStatus == ClientServiceRequestStatus.Declined)
|
|
ClientNotifyEvent.ProcessEvent(ClientNotifyEventType.CSRRejected, mClientID, Guid.Empty, "",
|
|
"", this.ClientRef, mDetails, Guid.Empty,"",mTitle);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
if(AyaBizUtils.AllowAutomaticMRUOnUpdate) AyaBizUtils.MRU.Add(RootObjectTypes.ClientServiceRequest, mID);
|
|
}
|
|
|
|
#endregion update
|
|
|
|
#region Delete
|
|
|
|
/// <summary>
|
|
/// Remove a ClientServiceRequest record .
|
|
/// </summary>
|
|
/// <param Title="Criteria"></param>
|
|
protected override void DataPortal_Delete(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
ClientServiceRequest rq = ClientServiceRequest.GetItemNoMRU(crit.ID);
|
|
if(!rq.IsEditable)
|
|
throw new System.ApplicationException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Object.NotDeleteable"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.ClientServiceRequest")
|
|
)
|
|
);
|
|
|
|
rq = null;
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aClientServiceRequest WHERE aID = @ID;");
|
|
cmDelete.AddInParameter("@ID", DbType.Guid, crit.ID);
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
DBUtil.RemoveKeywords(transaction, RootObjectTypes.ClientServiceRequest, crit.ID);
|
|
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
|
|
AyaBizUtils.MRU.Remove(RootObjectTypes.ClientServiceRequest, crit.ID);
|
|
|
|
//Remove any events for this object
|
|
if (AyaBizUtils.GlobalSettings.UseNotification)//Case 510
|
|
{
|
|
NotifyEvent.RemoveAllEventsForObject(crit.ID);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion delete
|
|
|
|
#endregion
|
|
|
|
#region Override IsValid / IsDirty
|
|
/// <summary>
|
|
/// No broken rules
|
|
/// </summary>
|
|
public override bool IsValid
|
|
{
|
|
get
|
|
{
|
|
return base.IsValid ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// contains unsaved changes
|
|
/// </summary>
|
|
public override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
return base.IsDirty ;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public Guid ID;
|
|
public bool TrackMRU;
|
|
public Criteria(Guid _ID, bool _TrackMRU)
|
|
{
|
|
ID = _ID;
|
|
TrackMRU = _TrackMRU;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#pragma warning disable 1591
|
|
#region Flag closed when workorder closed
|
|
/// <summary>
|
|
/// Flags every CSR that is a member of workorder stated as closed
|
|
/// called by workorder when it's closed
|
|
/// </summary>
|
|
[Serializable, System.ComponentModel.Browsable(false)]
|
|
public class ClosedFlagger//DO_NOT_OBFUSCATE
|
|
{
|
|
Guid _WorkorderID;
|
|
|
|
public ClosedFlagger(Guid WorkorderID)
|
|
{
|
|
_WorkorderID = WorkorderID;
|
|
}
|
|
|
|
public static void Flag(Guid WorkorderID)
|
|
{
|
|
DataPortal.Update(new ClosedFlagger(WorkorderID));
|
|
}
|
|
|
|
public void DataPortal_Update()
|
|
{
|
|
|
|
//because firebird doesn't support updating through a join statement
|
|
//we need to get a list of all the potential csr's that might be attached to the
|
|
//closed workorder first so they can be updated to closed status in a separate update
|
|
//query later
|
|
|
|
//Iterate through subscriptions looking for people subscribed to this event
|
|
//create an event record for each one
|
|
DBCommandWrapper cmCSRS = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
//************************************************************
|
|
"SELECT ACLIENTSERVICEREQUEST.AID " +
|
|
"FROM AWORKORDERITEM " +
|
|
"RIGHT OUTER JOIN AWORKORDER ON (AWORKORDERITEM.AWORKORDERID = AWORKORDER.AID) " +
|
|
"LEFT OUTER JOIN ACLIENTSERVICEREQUEST ON (AWORKORDERITEM.AID = ACLIENTSERVICEREQUEST.AWORKORDERITEMID) " +
|
|
"WHERE AWORKORDER.AID=@WorkorderID "
|
|
//************************************************************
|
|
);
|
|
cmCSRS.AddInParameter("@WorkorderID", DbType.Guid, _WorkorderID);
|
|
|
|
|
|
SafeDataReader dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cmCSRS));
|
|
System.Collections.Generic.List<Guid> l = new System.Collections.Generic.List<Guid>();
|
|
|
|
while (dr.Read())
|
|
{
|
|
l.Add(dr.GetGuid("AID"));
|
|
}
|
|
|
|
|
|
foreach (Guid g in l)
|
|
{
|
|
if (g != Guid.Empty)
|
|
{
|
|
DBCommandWrapper cm = DBUtil.GetCommandFromSQL(
|
|
"UPDATE " +
|
|
" ACLIENTSERVICEREQUEST " +
|
|
" SET " +
|
|
" ACLIENTSERVICEREQUEST.ASTATUS='3' " +
|
|
" WHERE AID=@CSRID "
|
|
);
|
|
cm.AddInParameter("@CSRID", DbType.Guid, g);
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
#endregion closed flagger
|
|
|
|
|
|
}//end ClientServiceRequest
|
|
#region Notification events
|
|
public enum ClientServiceRequestEvent : int
|
|
{
|
|
[Description("LT:ClientServiceRequest.Label.Event.Created")]
|
|
Created = 1
|
|
}
|
|
#endregion
|
|
#pragma warning restore 1591
|
|
}//end NAMESPACE GZTW.AyaNova.BLL |