/////////////////////////////////////////////////////////// // 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 { /// /// "Body" of workorder (all non header information) /// Stored in collection of object /// /// [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; /// /// Guid ID of root object (Workorder which may be a Service, ServiceTemplate, /// WorkorderQuote, QuoteTemplate, PM, or PMTemplate /// private Guid mWorkorderID; /// /// 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 /// private SmartDate mRequestDate; /// /// 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 /// private string mSummary=""; /// /// Used to identify for the dispatched technican what service is to be performed /// Corresponds to probs.notes in AyaNova v1 /// private string mTechNotes=""; private Guid mPriorityID; /// /// ID of WorkorderItemType /// private Guid mTypeID; /// /// 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 /// private Guid mWorkorderStatusID; /// ///WorkorderItemParts child collection /// private WorkorderItemParts mParts; private WorkorderItemPartRequests mPartRequests; /// ///WorkorderItemScheduledUsers child collection /// private WorkorderItemScheduledUsers mScheduledUsers; /// ///WorkorderItemLabors child collection /// private WorkorderItemLabors mLabors; /// ///WorkorderItemMiscExpenses child collection /// private WorkorderItemMiscExpenses mExpenses; /// ///WorkorderItemTravels child collection /// private WorkorderItemTravels mTravels; /// ///WorkorderItemTasks child collection /// private WorkorderItemTasks mTasks; /// /// 0..1 ratioWorkorderItemOutsideService object /// private WorkorderItemOutsideService mOutsideService; /// ///WorkorderItemLoans child collection /// private WorkorderItemLoans mLoans; /// /// ID of unit being serviced can be null /// private Guid mUnitID; /// /// If UnitID has a value, than this is available /// private Guid mWorkorderItemUnitServiceTypeID; /// /// If a unit selected, service provided under warranty for this unit /// 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 /// /// Private constructor to prevent direct instantiation /// 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 /// /// Get internal id number Read only property because it's set internally, not /// externally /// public Guid ID { get { return mID; } } /// /// Get created date /// /// /// public string Created { get { return mCreated.ToString(); } } /// /// Get modified date /// /// /// public string Modified { get { return mModified.ToString(); } } /// /// Get user record ID of person who created this record /// /// /// public Guid Creator { get { return mCreator; } } /// /// Get user ID of person who modified this record /// /// /// public Guid Modifier { get { return mModifier; } } /// /// Used to identify for the dispatched technican what service is to be performed /// /// public string TechNotes { get { return mTechNotes; } set { if(bReadOnly) ThrowSetError(); else { if(mTechNotes!=value) { mTechNotes = value; MarkDirty(); } } } } /// ///WorkorderItemMiscExpenses child collection /// public WorkorderItemMiscExpenses Expenses { get { return mExpenses; } } /// ///WorkorderItemLoans child collection /// public WorkorderItemLoans Loans { get { return mLoans; } } /// ///WorkorderItemLabors child collection /// public WorkorderItemLabors Labors { get { return mLabors; } } /// /// 0..1 ratioWorkorderItemOutsideService object /// public WorkorderItemOutsideService OutsideService { get { return mOutsideService; } } /// /// WorkorderItemParts child collection /// public WorkorderItemParts Parts { get { return mParts; } } /// ///WorkorderItemPartRequests child collection /// public WorkorderItemPartRequests PartRequests { get { return mPartRequests; } } /// ///WorkorderItemScheduledUsers child collection /// public WorkorderItemScheduledUsers ScheduledUsers { get { return mScheduledUsers; } } /// ///WorkorderItemTasks child collection /// public WorkorderItemTasks Tasks { get { return mTasks; } } /// ///WorkorderItemTravels child collection /// public WorkorderItemTravels Travels { get { return mTravels; } } /// /// If UnitID has a value, than this is available /// public Guid WorkorderItemUnitServiceTypeID { get { return mWorkorderItemUnitServiceTypeID; } set { if(bReadOnly) ThrowSetError(); else { if(mWorkorderItemUnitServiceTypeID!=value) { mWorkorderItemUnitServiceTypeID = value; MarkDirty(); } } } } /// /// Status selected for WorkorderItem. Same as workorder overall status but /// for this single workorder item instead. /// public Guid WorkorderStatusID { get { return mWorkorderStatusID; } set { if(bReadOnly) ThrowSetError(); else { if(mWorkorderStatusID!=value) { mWorkorderStatusID = value; MarkDirty(); } } } } /// /// ID of unit being serviced /// public Guid UnitID { get { return mUnitID; } set { if(bReadOnly) ThrowSetError(); else { if(mUnitID!=value) { mUnitID = value; MarkDirty(); } } } } /// /// If a unit selected, service provided under warranty for this unit /// public bool WarrantyService { get { return mWarrantyService; } set { if(bReadOnly) ThrowSetError(); else { if(mWarrantyService!=value) { mWarrantyService = value; MarkDirty(); } } } } /// /// ID of /// public Guid PriorityID { get { return mPriorityID; } set { if(bReadOnly) ThrowSetError(); else { if(mPriorityID!=value) { mPriorityID = value; MarkDirty(); } } } } /// /// 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 /// 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(); } } } } /// /// For pm setting and other internal use /// internal DateTime dtRequestDate { get { return mRequestDate.Date; } set { if(bReadOnly) ThrowSetError(); else { if(mRequestDate.Date!=value) { mRequestDate.Date = value; MarkDirty(); } } } } /// /// ID of WorkorderItemType /// public Guid TypeID { get { return mTypeID; } set { if(bReadOnly) ThrowSetError(); else { if(mTypeID!=value) { mTypeID = value; MarkDirty(); } } } } /// /// Brief summary of what the service item is for For display on lists, reports, /// schedule screen etc Corresponds to prob.brief in AyaNova v1 /// 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: /// /// UI Helper returns true if more than zero objects in this workorder item's collection /// public bool HasLabor { get { return (mLabors.Count>0); } } /// /// UI Helper returns true if a was selected on this workorder item /// public bool HasUnit { get { return (mUnitID!=Guid.Empty); } } /// /// UI Helper returns true if more than zero objects in this workorder item's collection /// OR /// if more than zero objects in this workorder item's collection /// public bool HasParts { get { return (mParts.Count>0 || mPartRequests.Count>0); } } /// /// UI Helper returns true if more than zero objects in this workorder item's collection /// public bool HasTravel { get { return (mTravels.Count>0); } } /// /// UI Helper returns true if more than zero objects in this workorder item's collection /// public bool HasScheduledUsers { get { return (mScheduledUsers.Count>0); } } /// /// UI Helper returns true if more than zero objects in this workorder item's collection /// public bool HasTasks { get { return (mTasks.Count>0); } } /// /// UI Helper returns true if more than zero objects in this workorder item's collection /// public bool HasExpenses { get { return (mExpenses.Count>0); } } /// /// UI Helper returns true if more than zero objects in this workorder item's collection /// public bool HasLoans { get { return (mLoans.Count>0); } } /// /// UI Helper returns true if is not Guid.Empty /// public bool HasOutsideService { get { return (mOutsideService.VendorSentToID!=Guid.Empty); } } //Added:25-Oct-2006 to support wbi /// /// UI Helper returns true if there is a unit and it's metered /// public bool HasMeteredUnit { get { if (mUnitID != Guid.Empty) return (Unit.IsMetered(mUnitID)); else return false; } } /// /// UI Helper returns true if there is a request date entered /// public bool HasRequestDate//case 1975 { get { return (!mRequestDate.IsEmpty); } } /// /// UI Helper returns formatted unit name /// public string UnitName//case 1975 { get { if (HasUnit) return (UnitNameFetcher.GetUnitNameFromWorkorderItemID(mID)); else return string.Empty; } } #region Custom Fields //********************* //CUSTOM FIELDS /// /// Custom1 /// 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(); } } } } /// /// Custom2 /// 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(); } } } } /// /// Custom3 /// 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(); } } } } /// /// Custom4 /// 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(); } } } } /// /// Custom5 /// 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(); } } } } /// /// Custom6 /// 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(); } } } } /// /// Custom7 /// 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(); } } } } /// /// Custom8 /// 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(); } } } } /// /// Custom9 /// 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(); } } } } /// /// Custom0 /// 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 /// /// 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 /// /// Either true or the rights allowed for the current user 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); } /// /// Sets all parts for this workorder item /// to part status "UsedInService" /// public void SetAllPartsToUsedInService() { foreach(WorkorderItemPart wip in this.Parts) { //case 3192 if(!wip.Used) wip.Used=true; } } /// /// 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 /// /// /// 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; } /// /// 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 /// 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 /// /// True means there are WorkorderItemPartRequest items /// not yet ordered or received /// (used by workorder to prevent closing when unordered part requests still exist) /// 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; } } /// /// A list of unique Guid's of parts selected /// on this work order item. /// /// /// public System.Collections.Generic.List ListOfPartsSelected() { System.Collections.Generic.List l = new System.Collections.Generic.List(); foreach (WorkorderItemPart wl in mParts) { if (!l.Contains(wl.PartID)) l.Add(wl.PartID); } return l; } /// /// 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) /// private void ThrowSetError() { throw new System.Security.SecurityException ( string.Format ( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"), LocalizedTextTable.GetLocalizedTextDirect("O.WorkorderItem") ) ); } #endregion #region System.object overrides /// /// /// /// public override string ToString() { return "WorkorderItem" + mID.ToString(); } /// /// /// /// /// public override bool Equals(Object obj) { if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; WorkorderItem c=(WorkorderItem)obj; return mID==c.mID; } /// /// /// /// public override int GetHashCode() { return ("WorkorderItem"+mID).GetHashCode(); } #endregion #region Searching /// /// Returns a search result object based on search terms /// for the ID specified /// /// /// /// 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 /// /// New item /// /// /// 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"))); } /// /// Get Item /// 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 /// /// /// /// 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 /// /// Update child /// /// /// 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 /// /// Called by collection and by the Update method in this object /// to remove all child collections and workorder item itself /// /// /// 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 /// /// /// 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; } } /// /// /// 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