1780 lines
45 KiB
C#
1780 lines
45 KiB
C#
///////////////////////////////////////////////////////////
|
|
// WorkorderItem.cs
|
|
// Implementation of Class WorkorderItem
|
|
// CSLA type: Editable Child
|
|
// Created on: 07-Jun-2004 8:41:47 AM
|
|
// Object design: Joyce
|
|
// Coded: John 28-July-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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>
|
|
/// "Body" of workorder (all non header information)
|
|
/// Stored in <see cref="WorkorderItems"/> collection of <see cref="Workorder"/> object
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class WorkorderItem : BusinessBase {
|
|
|
|
#region Attributes
|
|
|
|
private bool bReadOnly;
|
|
private Guid mID;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
|
|
|
|
/// <summary>
|
|
/// Guid ID of root object (Workorder which may be a Service, ServiceTemplate,
|
|
/// WorkorderQuote, QuoteTemplate, PM, or PMTemplate
|
|
/// </summary>
|
|
private Guid mWorkorderID;
|
|
/// <summary>
|
|
/// This is a user definable date and time in the event the request came many hours
|
|
/// previously, but was created at a later date and they wish to identify "actual"
|
|
/// response time from when the request actually occurred - not via the Created
|
|
/// attribute. Default value is the WorkorderItem mCreated attribute
|
|
/// </summary>
|
|
private SmartDate mRequestDate;
|
|
/// <summary>
|
|
/// Brief summary of what the service item is for For display on lists, reports,
|
|
/// schedule screen etc Corresponds to probs.brief in AyaNova 1.9.4.4
|
|
/// </summary>
|
|
private string mSummary="";
|
|
/// <summary>
|
|
/// Used to identify for the dispatched technican what service is to be performed
|
|
/// Corresponds to probs.notes in AyaNova v1
|
|
/// </summary>
|
|
private string mTechNotes="";
|
|
private Guid mPriorityID;
|
|
/// <summary>
|
|
/// ID of WorkorderItemType
|
|
/// </summary>
|
|
private Guid mTypeID;
|
|
/// <summary>
|
|
/// Status selected for WorkorderItems - uses object Status which is also used by
|
|
/// WorkorderStatus - this allows reports to be based on either or WorkorderStatus
|
|
/// from Workorder object able to update this field When this WorkorderItem Status
|
|
/// is marked as closed any parts set to Reserved results in a popup alerting user
|
|
/// that there are parts yet reserved and not yet set to UsedIService - can't
|
|
/// closed until changed
|
|
/// </summary>
|
|
private Guid mWorkorderStatusID;
|
|
|
|
/// <summary>
|
|
///WorkorderItemParts child collection
|
|
/// </summary>
|
|
private WorkorderItemParts mParts;
|
|
|
|
private WorkorderItemPartRequests mPartRequests;
|
|
|
|
/// <summary>
|
|
///WorkorderItemScheduledUsers child collection
|
|
/// </summary>
|
|
private WorkorderItemScheduledUsers mScheduledUsers;
|
|
/// <summary>
|
|
///WorkorderItemLabors child collection
|
|
/// </summary>
|
|
private WorkorderItemLabors mLabors;
|
|
/// <summary>
|
|
///WorkorderItemMiscExpenses child collection
|
|
/// </summary>
|
|
private WorkorderItemMiscExpenses mExpenses;
|
|
/// <summary>
|
|
///WorkorderItemTravels child collection
|
|
/// </summary>
|
|
private WorkorderItemTravels mTravels;
|
|
/// <summary>
|
|
///WorkorderItemTasks child collection
|
|
/// </summary>
|
|
private WorkorderItemTasks mTasks;
|
|
|
|
/// <summary>
|
|
/// 0..1 ratioWorkorderItemOutsideService object
|
|
/// </summary>
|
|
private WorkorderItemOutsideService mOutsideService;
|
|
|
|
|
|
/// <summary>
|
|
///WorkorderItemLoans child collection
|
|
/// </summary>
|
|
private WorkorderItemLoans mLoans;
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// ID of unit being serviced can be null
|
|
/// </summary>
|
|
private Guid mUnitID;
|
|
/// <summary>
|
|
/// If UnitID has a value, than this is available
|
|
/// </summary>
|
|
private Guid mWorkorderItemUnitServiceTypeID;
|
|
/// <summary>
|
|
/// If a unit selected, service provided under warranty for this unit
|
|
/// </summary>
|
|
private bool mWarrantyService;
|
|
|
|
|
|
//Custom fields
|
|
private string mCustom1="";
|
|
private string mCustom2="";
|
|
private string mCustom3="";
|
|
private string mCustom4="";
|
|
private string mCustom5="";
|
|
private string mCustom6="";
|
|
private string mCustom7="";
|
|
private string mCustom8="";
|
|
private string mCustom9="";
|
|
private string mCustom0="";
|
|
|
|
//Indicates internally that this workorder item
|
|
//record is present in memory only and has actually moved
|
|
//so don't attempt any update of it, just ignore it
|
|
//and allow it to be removed from the collection without
|
|
//affecting the db.
|
|
internal bool mMoved=false;
|
|
|
|
//Type of workorder
|
|
//used to flag whether to track serial numbers
|
|
//etc
|
|
internal WorkorderTypes mWorkorderType;
|
|
|
|
//case 1387
|
|
internal SecurityLevelTypes mHeaderRights;
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private WorkorderItem()
|
|
{
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//Child object
|
|
MarkAsChild();
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
|
|
mRequestDate=new SmartDate();
|
|
|
|
//instantiate child objects
|
|
mParts=WorkorderItemParts.NewItems();
|
|
mPartRequests=WorkorderItemPartRequests.NewItems();
|
|
mScheduledUsers=WorkorderItemScheduledUsers.NewItems();
|
|
mLabors=WorkorderItemLabors.NewItems();
|
|
mExpenses=WorkorderItemMiscExpenses.NewItems();
|
|
mTravels=WorkorderItemTravels.NewItems();
|
|
mTasks=WorkorderItemTasks.NewItems();
|
|
mLoans=WorkorderItemLoans.NewItems();
|
|
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
|
|
mUnitID=Guid.Empty;
|
|
|
|
|
|
|
|
}
|
|
|
|
#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>
|
|
/// Used to identify for the dispatched technican what service is to be performed
|
|
///
|
|
/// </summary>
|
|
public string TechNotes
|
|
{
|
|
get
|
|
{
|
|
return mTechNotes;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mTechNotes!=value)
|
|
{
|
|
mTechNotes = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///WorkorderItemMiscExpenses child collection
|
|
/// </summary>
|
|
public WorkorderItemMiscExpenses Expenses
|
|
{
|
|
get
|
|
{
|
|
return mExpenses;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///WorkorderItemLoans child collection
|
|
/// </summary>
|
|
public WorkorderItemLoans Loans
|
|
{
|
|
get
|
|
{
|
|
return mLoans;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///WorkorderItemLabors child collection
|
|
/// </summary>
|
|
public WorkorderItemLabors Labors
|
|
{
|
|
get
|
|
{
|
|
return mLabors;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 0..1 ratioWorkorderItemOutsideService object
|
|
/// </summary>
|
|
public WorkorderItemOutsideService OutsideService
|
|
{
|
|
get
|
|
{
|
|
return mOutsideService;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// WorkorderItemParts child collection
|
|
/// </summary>
|
|
public WorkorderItemParts Parts
|
|
{
|
|
get
|
|
{
|
|
return mParts;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///WorkorderItemPartRequests child collection
|
|
/// </summary>
|
|
public WorkorderItemPartRequests PartRequests
|
|
{
|
|
get
|
|
{
|
|
return mPartRequests;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///WorkorderItemScheduledUsers child collection
|
|
/// </summary>
|
|
public WorkorderItemScheduledUsers ScheduledUsers
|
|
{
|
|
get
|
|
{
|
|
return mScheduledUsers;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///WorkorderItemTasks child collection
|
|
/// </summary>
|
|
public WorkorderItemTasks Tasks
|
|
{
|
|
get
|
|
{
|
|
return mTasks;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///WorkorderItemTravels child collection
|
|
/// </summary>
|
|
public WorkorderItemTravels Travels
|
|
{
|
|
get
|
|
{
|
|
return mTravels;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// If UnitID has a value, than this is available
|
|
/// </summary>
|
|
public Guid WorkorderItemUnitServiceTypeID
|
|
{
|
|
get
|
|
{
|
|
return mWorkorderItemUnitServiceTypeID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mWorkorderItemUnitServiceTypeID!=value)
|
|
{
|
|
mWorkorderItemUnitServiceTypeID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Status selected for WorkorderItem. Same as workorder overall status but
|
|
/// for this single workorder item instead.
|
|
/// </summary>
|
|
public Guid WorkorderStatusID
|
|
{
|
|
get
|
|
{
|
|
return mWorkorderStatusID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mWorkorderStatusID!=value)
|
|
{
|
|
mWorkorderStatusID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ID of unit being serviced
|
|
/// </summary>
|
|
public Guid UnitID
|
|
{
|
|
get
|
|
{
|
|
return mUnitID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mUnitID!=value)
|
|
{
|
|
mUnitID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// If a unit selected, service provided under warranty for this unit
|
|
/// </summary>
|
|
public bool WarrantyService
|
|
{
|
|
get
|
|
{
|
|
return mWarrantyService;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mWarrantyService!=value)
|
|
{
|
|
mWarrantyService = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// ID of <see cref="Priority"/>
|
|
/// </summary>
|
|
public Guid PriorityID
|
|
{
|
|
get
|
|
{
|
|
return mPriorityID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPriorityID!=value)
|
|
{
|
|
mPriorityID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This is a user definable date and time in the event the request came many hours
|
|
/// previously, but was created at a later date and they wish to identify "actual"
|
|
/// response time from when the request actually occurred - not via the Created
|
|
/// attribute. Default value is the WorkorderItem mCreated attribute
|
|
/// </summary>
|
|
public object RequestDate
|
|
{
|
|
get
|
|
{
|
|
return mRequestDate.DBValue;
|
|
}
|
|
set
|
|
{
|
|
if(!AyaBizUtils.IsGenerator && bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (!AyaBizUtils.SmartDateEquals(mRequestDate, value)) //Case 298
|
|
{
|
|
mRequestDate.DBValue = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// For pm setting and other internal use
|
|
/// </summary>
|
|
internal DateTime dtRequestDate
|
|
{
|
|
get
|
|
{
|
|
return mRequestDate.Date;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mRequestDate.Date!=value)
|
|
{
|
|
mRequestDate.Date = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// ID of WorkorderItemType
|
|
/// </summary>
|
|
public Guid TypeID
|
|
{
|
|
get
|
|
{
|
|
return mTypeID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mTypeID!=value)
|
|
{
|
|
mTypeID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Brief summary of what the service item is for For display on lists, reports,
|
|
/// schedule screen etc Corresponds to prob.brief in AyaNova v1
|
|
/// </summary>
|
|
public string Summary
|
|
{
|
|
get
|
|
{
|
|
return mSummary;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mSummary!=value)
|
|
{
|
|
mSummary = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*********************
|
|
//Items to assist in UI code
|
|
//Originally the child collections were to be null if not present
|
|
//but it doesn't work that way, so there is no quick way to tell
|
|
//if there are any child objects or not without this:
|
|
/// <summary>
|
|
/// UI Helper returns true if more than zero <see cref="WorkorderItemLabor"/> objects in this workorder item's <see cref="Labors"/> collection
|
|
/// </summary>
|
|
public bool HasLabor
|
|
{
|
|
get
|
|
{
|
|
return (mLabors.Count>0);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI Helper returns true if a <see cref="Unit"/> was selected on this workorder item
|
|
/// </summary>
|
|
public bool HasUnit
|
|
{
|
|
get
|
|
{
|
|
return (mUnitID!=Guid.Empty);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// UI Helper returns true if more than zero <see cref="WorkorderItemPart"/> objects in this workorder item's <see cref="Parts"/> collection
|
|
/// OR
|
|
/// if more than zero <see cref="WorkorderItemPartRequest"/> objects in this workorder item's <see cref="PartRequests"/> collection
|
|
/// </summary>
|
|
public bool HasParts
|
|
{
|
|
get
|
|
{
|
|
|
|
return (mParts.Count>0 || mPartRequests.Count>0);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// UI Helper returns true if more than zero <see cref="WorkorderItemTravel"/> objects in this workorder item's <see cref="Travels"/> collection
|
|
/// </summary>
|
|
public bool HasTravel
|
|
{
|
|
get
|
|
{
|
|
return (mTravels.Count>0);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI Helper returns true if more than zero <see cref="WorkorderItemScheduledUser"/> objects in this workorder item's <see cref="ScheduledUsers"/> collection
|
|
/// </summary>
|
|
public bool HasScheduledUsers
|
|
{
|
|
get
|
|
{
|
|
return (mScheduledUsers.Count>0);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// UI Helper returns true if more than zero <see cref="WorkorderItemTask"/> objects in this workorder item's <see cref="Tasks"/> collection
|
|
/// </summary>
|
|
public bool HasTasks
|
|
{
|
|
get
|
|
{
|
|
return (mTasks.Count>0);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI Helper returns true if more than zero <see cref="WorkorderItemMiscExpense"/> objects in this workorder item's <see cref="Expenses"/> collection
|
|
/// </summary>
|
|
public bool HasExpenses
|
|
{
|
|
get
|
|
{
|
|
return (mExpenses.Count>0);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI Helper returns true if more than zero <see cref="WorkorderItemLoan"/> objects in this workorder item's <see cref="Loans"/> collection
|
|
/// </summary>
|
|
public bool HasLoans
|
|
{
|
|
get
|
|
{
|
|
return (mLoans.Count>0);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI Helper returns true if <see cref="WorkorderItemOutsideService.VendorSentToID"/> is not Guid.Empty
|
|
/// </summary>
|
|
public bool HasOutsideService
|
|
{
|
|
get
|
|
{
|
|
return (mOutsideService.VendorSentToID!=Guid.Empty);
|
|
}
|
|
}
|
|
|
|
//Added:25-Oct-2006 to support wbi
|
|
/// <summary>
|
|
/// UI Helper returns true if there is a unit and it's metered
|
|
/// </summary>
|
|
public bool HasMeteredUnit
|
|
{
|
|
get
|
|
{
|
|
if (mUnitID != Guid.Empty)
|
|
return (Unit.IsMetered(mUnitID));
|
|
else
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// UI Helper returns true if there is a request date entered
|
|
/// </summary>
|
|
public bool HasRequestDate//case 1975
|
|
{
|
|
get
|
|
{
|
|
return (!mRequestDate.IsEmpty);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI Helper returns formatted unit name
|
|
/// </summary>
|
|
public string UnitName//case 1975
|
|
{
|
|
get
|
|
{
|
|
if (HasUnit)
|
|
return (UnitNameFetcher.GetUnitNameFromWorkorderItemID(mID));
|
|
else
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
#region Custom Fields
|
|
|
|
//*********************
|
|
|
|
|
|
//CUSTOM FIELDS
|
|
/// <summary>
|
|
/// Custom1
|
|
/// </summary>
|
|
public string Custom1
|
|
{
|
|
get
|
|
{
|
|
return mCustom1;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom1!=value)
|
|
{
|
|
mCustom1 = value;
|
|
BrokenRules.Assert("Custom1Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom1","Custom1",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom2
|
|
/// </summary>
|
|
public string Custom2
|
|
{
|
|
get
|
|
{
|
|
return mCustom2;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom2!=value)
|
|
{
|
|
mCustom2 = value;
|
|
BrokenRules.Assert("Custom2Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom2","Custom2",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom3
|
|
/// </summary>
|
|
public string Custom3
|
|
{
|
|
get
|
|
{
|
|
return mCustom3;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom3!=value)
|
|
{
|
|
mCustom3 = value;
|
|
BrokenRules.Assert("Custom3Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom3","Custom3",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom4
|
|
/// </summary>
|
|
public string Custom4
|
|
{
|
|
get
|
|
{
|
|
return mCustom4;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom4!=value)
|
|
{
|
|
mCustom4 = value;
|
|
BrokenRules.Assert("Custom4Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom4","Custom4",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom5
|
|
/// </summary>
|
|
public string Custom5
|
|
{
|
|
get
|
|
{
|
|
return mCustom5;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom5!=value)
|
|
{
|
|
mCustom5 = value;
|
|
BrokenRules.Assert("Custom5Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom5","Custom5",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom6
|
|
/// </summary>
|
|
public string Custom6
|
|
{
|
|
get
|
|
{
|
|
return mCustom6;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom6!=value)
|
|
{
|
|
mCustom6 = value;
|
|
BrokenRules.Assert("Custom6Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom6","Custom6",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom7
|
|
/// </summary>
|
|
public string Custom7
|
|
{
|
|
get
|
|
{
|
|
return mCustom7;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom7!=value)
|
|
{
|
|
mCustom7 = value;
|
|
BrokenRules.Assert("Custom7Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom7","Custom7",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom8
|
|
/// </summary>
|
|
public string Custom8
|
|
{
|
|
get
|
|
{
|
|
return mCustom8;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom8!=value)
|
|
{
|
|
mCustom8 = value;
|
|
BrokenRules.Assert("Custom8Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom8","Custom8",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom9
|
|
/// </summary>
|
|
public string Custom9
|
|
{
|
|
get
|
|
{
|
|
return mCustom9;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom9!=value)
|
|
{
|
|
mCustom9 = value;
|
|
BrokenRules.Assert("Custom9Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom9","Custom9",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Custom0
|
|
/// </summary>
|
|
public string Custom0
|
|
{
|
|
get
|
|
{
|
|
return mCustom0;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCustom0!=value)
|
|
{
|
|
mCustom0 = value;
|
|
BrokenRules.Assert("Custom0Length",
|
|
"Error.Object.FieldLengthExceeded500,WorkorderItem.Label.Custom0","Custom0",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion custom fields
|
|
|
|
/// <summary>
|
|
/// Called by workorder items collection object
|
|
/// when called in turn by workorder object that is read only due to
|
|
/// security or closed or service completed
|
|
/// </summary>
|
|
/// <param name="RO">Either true or the rights allowed for the current user</param>
|
|
public void SetReadOnly(bool RO)
|
|
{
|
|
bReadOnly=RO;
|
|
mParts.SetReadOnly(RO);
|
|
mPartRequests.SetReadOnly(RO);
|
|
mScheduledUsers.SetReadOnly(RO);
|
|
mLabors.SetReadOnly(RO);
|
|
mExpenses.SetReadOnly(RO);
|
|
mLoans.SetReadOnly(RO);
|
|
mTravels.SetReadOnly(RO);
|
|
mTasks.SetReadOnly(RO);
|
|
mOutsideService.SetReadOnly(RO);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets all parts for this workorder item
|
|
/// to part status "UsedInService"
|
|
/// </summary>
|
|
public void SetAllPartsToUsedInService()
|
|
{
|
|
foreach(WorkorderItemPart wip in this.Parts)
|
|
{
|
|
//case 3192
|
|
if(!wip.Used)
|
|
wip.Used=true;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Helper for GUI, if user selects more parts than are in stock
|
|
/// and indicates they want to request them from the purchaser
|
|
/// this function will move the quantity indicated to the request line
|
|
/// </summary>
|
|
/// <param name="WorkorderItemPartID"></param>
|
|
/// <param name="QuantityToMove"></param>
|
|
public void MovePartToRequest(Guid WorkorderItemPartID,decimal QuantityToMove)
|
|
{
|
|
if(this.Parts[WorkorderItemPartID]==null)
|
|
{
|
|
//part id is bad
|
|
throw new System.ArgumentException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Object.FieldValueNotValid"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItem")+":MovePartToRequest:"+LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItemPart"+".ID")
|
|
|
|
)
|
|
);
|
|
}
|
|
|
|
//case 2082
|
|
Guid selectedPartId = this.Parts[WorkorderItemPartID].PartID;
|
|
Guid selectedWarehouseId = this.Parts[WorkorderItemPartID].PartWarehouseID;
|
|
if (selectedPartId == Guid.Empty || selectedWarehouseId == Guid.Empty)
|
|
return;
|
|
|
|
WorkorderItemPartRequest pr=this.PartRequests.Add(this);
|
|
pr.PartID=this.Parts[WorkorderItemPartID].PartID;
|
|
pr.PartWarehouseID=this.Parts[WorkorderItemPartID].PartWarehouseID;
|
|
pr.Quantity=QuantityToMove;
|
|
|
|
//If were moving *all* the quantity then set part record quantity to zero
|
|
//(removing it would cause an exception otherwise)
|
|
//otherwise take away from it's quantity
|
|
if(this.Parts[WorkorderItemPartID].Quantity==QuantityToMove)
|
|
this.Parts[WorkorderItemPartID].Quantity=0m;
|
|
else
|
|
this.Parts[WorkorderItemPartID].Quantity-=QuantityToMove;
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// True means there are WorkorderItemPartRequest items
|
|
/// still on order and not fully received
|
|
///
|
|
///A workorder item can not be deleted if there are part requests on order
|
|
///as it would break inventory
|
|
/// </summary>
|
|
public bool HasPartRequestsOnOrder
|
|
{
|
|
get
|
|
{
|
|
|
|
foreach(WorkorderItemPartRequest w in PartRequests)
|
|
{
|
|
//if there is a purchase order for this request
|
|
//and there are more parts requested (Quantity) than received
|
|
//it's still on order
|
|
if(w.OnOrder)
|
|
return true;
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//Case 398
|
|
/// <summary>
|
|
/// True means there are WorkorderItemPartRequest items
|
|
/// not yet ordered or received
|
|
/// (used by workorder to prevent closing when unordered part requests still exist)
|
|
/// </summary>
|
|
public bool HasPartRequestsUnOrdered
|
|
{
|
|
get
|
|
{
|
|
|
|
foreach (WorkorderItemPartRequest w in PartRequests)
|
|
{
|
|
|
|
//case 885
|
|
if(w.Unordered)
|
|
return true;//has a part request and it's not ordered
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// A list of unique Guid's of parts selected
|
|
/// on this work order item.
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public System.Collections.Generic.List<Guid> ListOfPartsSelected()
|
|
{
|
|
System.Collections.Generic.List<Guid> l = new System.Collections.Generic.List<Guid>();
|
|
foreach (WorkorderItemPart wl in mParts)
|
|
{
|
|
if (!l.Contains(wl.PartID))
|
|
l.Add(wl.PartID);
|
|
}
|
|
return l;
|
|
}
|
|
|
|
|
|
/// <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.WorkorderItem")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "WorkorderItem" + mID.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
WorkorderItem c=(WorkorderItem)obj;
|
|
return mID==c.mID;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("WorkorderItem"+mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Searching
|
|
|
|
/// <summary>
|
|
/// Returns a search result object based on search terms
|
|
/// for the ID specified
|
|
/// </summary>
|
|
/// <param name="ID"></param>
|
|
/// <param name="searchTerms"></param>
|
|
/// <returns></returns>
|
|
public static SearchResult GetSearchResult(Guid ID, string[]searchTerms)
|
|
{
|
|
|
|
|
|
|
|
if(AyaBizUtils.Right("Object.WorkorderItem")<(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 aID, aCreator, aModifier, aCreated, aModified, aTechNotes, " +
|
|
//" aSummary, aCustom1, aCustom2, aCustom3, aCustom4, " +
|
|
//" aCustom5, aCustom6, aCustom7, aCustom8, aCustom9, aCustom0 " +
|
|
//"FROM aWorkorderItem WHERE (aID = @ID)"
|
|
|
|
//Case 88 changed query and code below to give info in description field of search result
|
|
|
|
"SELECT AWORKORDERITEM.aID, AWORKORDERITEM.aCreator, " +
|
|
" AWORKORDERITEM.aModifier, AWORKORDERITEM.aCreated, " +
|
|
" AWORKORDERITEM.aModified, AWORKORDERITEM.aTechNotes, " +
|
|
" AWORKORDERITEM.aSummary, AWORKORDERITEM.aCustom1, " +
|
|
" AWORKORDERITEM.aCustom2, AWORKORDERITEM.aCustom3, " +
|
|
" AWORKORDERITEM.aCustom4, AWORKORDERITEM.aCustom5, " +
|
|
" AWORKORDERITEM.aCustom6, AWORKORDERITEM.aCustom7, " +
|
|
" AWORKORDERITEM.aCustom8, AWORKORDERITEM.aCustom9, " +
|
|
" AWORKORDERITEM.aCustom0, AWORKORDERSERVICE.ASERVICENUMBER, " +
|
|
" AWORKORDERQUOTE.AQUOTENUMBER, AWORKORDERPREVENTIVEMAINTENANCE.APREVENTIVEMAINTENANCENUMBER, " +
|
|
" ACLIENT.ANAME AS ACLIENTNAME, aClient.aRegionID AS ACLIENTREGION, AWORKORDER.aWorkorderType " +
|
|
"FROM AWORKORDERITEM LEFT OUTER " +
|
|
"JOIN AWORKORDER ON AWORKORDERITEM.AWORKORDERID = " +
|
|
"AWORKORDER.AID LEFT OUTER JOIN ACLIENT ON AWORKORDER.ACLIENTID " +
|
|
"= ACLIENT.AID LEFT OUTER JOIN AWORKORDERPREVENTIVEMAINTENANCE " +
|
|
"ON AWORKORDER.AID = " +
|
|
"AWORKORDERPREVENTIVEMAINTENANCE.AWORKORDERID LEFT OUTER JOIN " +
|
|
"AWORKORDERQUOTE ON AWORKORDER.AID = AWORKORDERQUOTE.AWORKORDERID " +
|
|
"LEFT OUTER JOIN AWORKORDERSERVICE " +
|
|
"ON AWORKORDER.AID = AWORKORDERSERVICE.AWORKORDERID " +
|
|
"WHERE (aWorkorderItem.aID = @ID)"
|
|
|
|
, ID);
|
|
|
|
if(!dr.Read())
|
|
return new SearchResult();
|
|
|
|
if (!AyaBizUtils.InYourRegion(dr.GetGuid("ACLIENTREGION"))) return new SearchResult();//case 58
|
|
|
|
//Case 88 parse out workorder type and prepare description field accordingly
|
|
|
|
WorkorderTypes workorderType = (WorkorderTypes)dr.GetInt16("aWorkorderType");
|
|
switch (workorderType)
|
|
{
|
|
case WorkorderTypes.Service:
|
|
sr.Description=LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderService") + " " +dr.GetInt32("aServiceNumber").ToString() + " " + dr.GetString("ACLIENTNAME");
|
|
break;
|
|
case WorkorderTypes.Quote:
|
|
sr.Description = LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderQuote") + " " + dr.GetInt32("AQUOTENUMBER").ToString() + " " + dr.GetString("ACLIENTNAME");
|
|
break;
|
|
case WorkorderTypes.PreventiveMaintenance:
|
|
sr.Description = LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderPreventiveMaintenance") + " " + dr.GetInt32("APREVENTIVEMAINTENANCENUMBER").ToString() + " " + dr.GetString("ACLIENTNAME");
|
|
break;
|
|
}
|
|
|
|
//sr.Description="";
|
|
|
|
sb.Append(dr.GetString("aTechNotes"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aSummary"));
|
|
sb.Append(" ");
|
|
|
|
|
|
sb.Append(dr.GetString("aCustom0"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom1"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom2"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom3"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom4"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom5"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom6"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom7"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom8"));
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("aCustom9"));
|
|
|
|
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.WorkorderItem;
|
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
/// <summary>
|
|
/// New item
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
internal static WorkorderItem NewItem(Workorder obj)
|
|
{
|
|
//case 1387
|
|
if(AyaBizUtils.IsGenerator || ((obj.Rights > SecurityLevelTypes.ReadOnly) &&
|
|
(AyaBizUtils.Right("Object.WorkorderItem")>(int)SecurityLevelTypes.ReadOnly)))
|
|
{
|
|
WorkorderItem child = new WorkorderItem();
|
|
|
|
//case 1387
|
|
child.mHeaderRights = obj.Rights;
|
|
|
|
child.mWorkorderID=obj.ID;
|
|
child.mOutsideService=WorkorderItemOutsideService.NewItem(child);
|
|
child.mWorkorderType=obj.WorkorderType;
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItem")));
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Item
|
|
/// </summary>
|
|
internal static WorkorderItem GetItem(SafeDataReader dr,WorkorderTypes type, Workorder obj)
|
|
{
|
|
if (((obj.Rights > SecurityLevelTypes.NoAccess) &&
|
|
(AyaBizUtils.Right("Object.WorkorderItem") > (int)SecurityLevelTypes.NoAccess)))
|
|
{
|
|
WorkorderItem child = new WorkorderItem();
|
|
//case 1387
|
|
child.mHeaderRights = obj.Rights;
|
|
|
|
child.mWorkorderType=type;
|
|
child.Fetch(dr);
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItem")));
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
protected void Fetch(SafeDataReader dr)
|
|
{
|
|
|
|
//Standard fields
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModifier=dr.GetGuid("aModifier");
|
|
mID=dr.GetGuid("aID");
|
|
|
|
|
|
//Custom fields
|
|
mCustom1=dr.GetString("aCustom1");
|
|
mCustom2=dr.GetString("aCustom2");
|
|
mCustom3=dr.GetString("aCustom3");
|
|
mCustom4=dr.GetString("aCustom4");
|
|
mCustom5=dr.GetString("aCustom5");
|
|
mCustom6=dr.GetString("aCustom6");
|
|
mCustom7=dr.GetString("aCustom7");
|
|
mCustom8=dr.GetString("aCustom8");
|
|
mCustom9=dr.GetString("aCustom9");
|
|
mCustom0=dr.GetString("aCustom0");
|
|
|
|
//WorkorderItem fields
|
|
mTechNotes=dr.GetString("aTechNotes");
|
|
mWorkorderID=dr.GetGuid("aWorkorderID");
|
|
mRequestDate=DBUtil.ToLocal(dr.GetSmartDate("aRequestDate"));
|
|
mSummary=dr.GetString("aSummary");
|
|
mPriorityID=dr.GetGuid("aPriorityID");
|
|
mTypeID=dr.GetGuid("aTypeID");
|
|
mWorkorderStatusID=dr.GetGuid("aWorkorderStatusID");
|
|
|
|
mUnitID=dr.GetGuid("aUnitID");
|
|
mWorkorderItemUnitServiceTypeID=dr.GetGuid("aWorkorderItemUnitServiceTypeID");
|
|
mWarrantyService=dr.GetBoolean("aWarrantyService");
|
|
|
|
//Retrieve children
|
|
mParts=WorkorderItemParts.GetItems(this);
|
|
mPartRequests=WorkorderItemPartRequests.GetItems(this);
|
|
mScheduledUsers=WorkorderItemScheduledUsers.GetItems(this);
|
|
mLabors=WorkorderItemLabors.GetItems(this);
|
|
mExpenses=WorkorderItemMiscExpenses.GetItems(this);
|
|
mLoans=WorkorderItemLoans.GetItems(this);
|
|
mTravels=WorkorderItemTravels.GetItems(this);
|
|
mTasks=WorkorderItemTasks.GetItems(this);
|
|
|
|
mOutsideService=WorkorderItemOutsideService.GetItem(this);
|
|
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.WorkorderItem")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
MarkOld();
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Add / Update
|
|
|
|
/// <summary>
|
|
/// Update child
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="tr"></param>
|
|
internal void Update(Workorder obj,IDbTransaction tr)
|
|
{
|
|
//No need to update if there is nothing changed
|
|
if(!this.IsDirty) return;
|
|
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
if(!IsNew)
|
|
DBUtil.CheckSafeToUpdateInsideTransaction(this.mModified.Date, this.mID, "aWorkorderItem", tr);//case 1960
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
if(this.HasPartRequestsOnOrder)
|
|
throw new System.ApplicationException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Object.NotDeleteable"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItem")
|
|
)
|
|
);
|
|
//call the static delete-o-matic method below which
|
|
//handles all the shit
|
|
DeleteItems(this.mID,tr);
|
|
|
|
}
|
|
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 aWorkorderItem (aWorkorderID, aID, aTechNotes, " +
|
|
"aWorkorderStatusID, aPriorityID, aRequestDate, " +
|
|
"aSummary, aTypeID, aUnitID, aWorkorderItemUnitServiceTypeID, " +
|
|
"aWarrantyService, aCreated,aModified,aCreator, " +
|
|
"aModifier, aCustom1, aCustom2, aCustom3, " +
|
|
"aCustom4, aCustom5, aCustom6, aCustom7, aCustom8, " +
|
|
"aCustom9, aCustom0) VALUES (@WorkorderID,@ID,@TechNotes, " +
|
|
"@WorkorderStatusID,@PriorityID, @RequestDate, " +
|
|
"@Summary,@TypeID,@UnitID,@WorkorderItemUnitServiceTypeID, " +
|
|
" @WarrantyService,@Created, @Modified,@CurrentUserID, " +
|
|
"@CurrentUserID, @Custom1,@Custom2,@Custom3,@Custom4, " +
|
|
"@Custom5,@Custom6,@Custom7,@Custom8,@Custom9, " +
|
|
"@Custom0)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aWorkorderItem SET aWorkorderID=@WorkorderID, " +
|
|
"aID=@ID, aTechNotes=@TechNotes, " +
|
|
"aWorkorderStatusID=@WorkorderStatusID, aPriorityID=@PriorityID, " +
|
|
"aRequestDate=@RequestDate, aSummary=@Summary, " +
|
|
"aTypeID=@TypeID, " +
|
|
"aUnitID=@UnitID, aWorkorderItemUnitServiceTypeID=@WorkorderItemUnitServiceTypeID, " +
|
|
"aWarrantyService=@WarrantyService, " +
|
|
"aModifier=@CurrentUserID, " +
|
|
"aModified=@Modified, aCustom1=@Custom1, aCustom2=@Custom2, " +
|
|
"aCustom3=@Custom3, aCustom4=@Custom4, " +
|
|
"aCustom5=@Custom5, aCustom6=@Custom6, aCustom7=@Custom7, " +
|
|
"aCustom8=@Custom8, aCustom9=@Custom9, " +
|
|
"aCustom0=@Custom0 WHERE aID=@ID"
|
|
);
|
|
|
|
|
|
|
|
//WorkorderItem fields
|
|
cm.AddInParameter("@ID",DbType.Guid,mID);
|
|
cm.AddLargeStringInParameter("@TechNotes",mTechNotes);
|
|
cm.AddInParameter("@WorkorderID",DbType.Guid,mWorkorderID);
|
|
cm.AddInParameter("@RequestDate",DbType.DateTime, DBUtil.ToUTC(mRequestDate).DBValue);
|
|
cm.AddInParameter("@Summary",DbType.String,mSummary);
|
|
cm.AddInParameter("@PriorityID",DbType.Guid,mPriorityID);
|
|
cm.AddInParameter("@TypeID",DbType.Guid,mTypeID);
|
|
cm.AddInParameter("@WorkorderStatusID",DbType.Guid,mWorkorderStatusID);
|
|
cm.AddInParameter("@UnitID",DbType.Guid,mUnitID);
|
|
cm.AddInParameter("@WorkorderItemUnitServiceTypeID",DbType.Guid,mWorkorderItemUnitServiceTypeID);
|
|
cm.AddInParameter("@WarrantyService",DbType.Boolean,mWarrantyService);
|
|
|
|
//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));
|
|
|
|
//Custom fields
|
|
cm.AddLargeStringInParameter("@Custom1", mCustom1);
|
|
cm.AddLargeStringInParameter("@Custom2", mCustom2);
|
|
cm.AddLargeStringInParameter("@Custom3", mCustom3);
|
|
cm.AddLargeStringInParameter("@Custom4", mCustom4);
|
|
cm.AddLargeStringInParameter("@Custom5", mCustom5);
|
|
cm.AddLargeStringInParameter("@Custom6", mCustom6);
|
|
cm.AddLargeStringInParameter("@Custom7", mCustom7);
|
|
cm.AddLargeStringInParameter("@Custom8", mCustom8);
|
|
cm.AddLargeStringInParameter("@Custom9", mCustom9);
|
|
cm.AddLargeStringInParameter("@Custom0", mCustom0);
|
|
|
|
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, tr);
|
|
|
|
//Update children
|
|
mParts.Update(this,tr);
|
|
mPartRequests.Update(this,tr);
|
|
mScheduledUsers.Update(this,tr);
|
|
mLabors.Update(this,tr);
|
|
mExpenses.Update(this,tr);
|
|
mLoans.Update(this,tr);
|
|
mTravels.Update(this,tr);
|
|
mTasks.Update(this,tr);
|
|
mOutsideService.Update(this,tr);
|
|
|
|
|
|
//Process keywords
|
|
DBUtil.ProcessKeywords(tr,this.mID,RootObjectTypes.WorkorderItem,IsNew,AyaBizUtils.Break(false,
|
|
mTechNotes,mSummary,
|
|
/*Custom fields*/
|
|
mCustom1,mCustom2,mCustom3,mCustom4,mCustom5,mCustom6,mCustom7,mCustom8,mCustom9,mCustom0));
|
|
|
|
MarkOld();//db is now synched with object
|
|
|
|
|
|
|
|
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Shared Delete method One stop delete shop
|
|
|
|
/// <summary>
|
|
/// Called by collection and by the Update method in this object
|
|
/// to remove all child collections and workorder item itself
|
|
/// </summary>
|
|
/// <param name="WorkorderItemID"></param>
|
|
/// <param name="transaction"></param>
|
|
internal static void DeleteItems(Guid WorkorderItemID, IDbTransaction transaction)
|
|
{
|
|
WorkorderItemPartRequests.DeleteItems(WorkorderItemID,transaction);
|
|
WorkorderItemLabors.DeleteItems(WorkorderItemID,transaction);
|
|
WorkorderItemParts.DeleteItems(WorkorderItemID,transaction);
|
|
WorkorderItemScheduledUsers.DeleteItems(WorkorderItemID,transaction);
|
|
WorkorderItemMiscExpenses.DeleteItems(WorkorderItemID,transaction);
|
|
WorkorderItemTravels.DeleteItems(WorkorderItemID,transaction);
|
|
WorkorderItemTasks.DeleteItems(WorkorderItemID,transaction);
|
|
WorkorderItemOutsideService.DeleteItem(WorkorderItemID,transaction);
|
|
WorkorderItemLoans.DeleteItems(WorkorderItemID,transaction);
|
|
|
|
//Case 354 - reopen any CSR's that might be attached to this woitem
|
|
//and remove the link so the woitem can be deleted. More efficient to just
|
|
//always run this update query than to see if there is a csr since woitem has not
|
|
//built in flag to indicate it's from a csr
|
|
DBCommandWrapper cmCSR = DBUtil.GetCommandFromSQL(
|
|
"UPDATE aclientservicerequest SET aworkorderitemid=null, " +
|
|
"astatus=0 WHERE aworkorderitemid=@ID;");
|
|
cmCSR.AddInParameter("@ID", DbType.Guid, WorkorderItemID);
|
|
DBUtil.DB.ExecuteNonQuery(cmCSR, transaction);
|
|
|
|
//case 1618
|
|
//delete meter readings tied to this workorder item
|
|
DBCommandWrapper cmDeleteMeterReadings = DBUtil.GetCommandFromSQL(
|
|
"DELETE FROM AUNITMETERREADING WHERE AUNITMETERREADING.AWORKORDERITEMID = @ID;");
|
|
cmDeleteMeterReadings.AddInParameter("@ID", DbType.Guid, WorkorderItemID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDeleteMeterReadings, transaction);
|
|
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aWorkorderItem WHERE aID=@ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,WorkorderItemID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
|
|
DBUtil.RemoveKeywords(transaction,RootObjectTypes.WorkorderItem,WorkorderItemID);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Override IsValid / IsDirty
|
|
//Override base class version if there are child objects
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override bool IsValid
|
|
{
|
|
get
|
|
{
|
|
return base.IsValid && mParts.IsValid && mPartRequests.IsValid &&
|
|
mScheduledUsers.IsValid && mLabors.IsValid &&
|
|
mExpenses.IsValid && mTravels.IsValid &&
|
|
mTasks.IsValid && mOutsideService.IsValid &&
|
|
mLoans.IsValid;
|
|
}
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
return base.IsDirty || mParts.IsDirty || mPartRequests.IsDirty ||
|
|
mScheduledUsers.IsDirty || mLabors.IsDirty ||
|
|
mExpenses.IsDirty || mTravels.IsDirty ||
|
|
mTasks.IsDirty || mOutsideService.IsDirty ||
|
|
mLoans.IsDirty;
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}//end WorkorderItem
|
|
|
|
#region Notification events
|
|
|
|
|
|
// public enum WorkorderItemEvent : int
|
|
// {
|
|
//
|
|
// [Description("LT:WorkorderItem.Label.Event.NotServiced")] NotServiced=256//pending
|
|
//
|
|
// }
|
|
|
|
#endregion
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |