1803 lines
44 KiB
C#
1803 lines
44 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Part.cs
|
|
// Implementation of Class Part
|
|
// CSLA type: Editable Root
|
|
// Created on: 07-Jun-2004 8:41:26 AM
|
|
// Object design: Joyce
|
|
// Coded: John 20-Jul-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Part object representing a part used in service
|
|
/// </summary>
|
|
[Serializable]
|
|
public class Part : BusinessBase {
|
|
|
|
#region Attributes
|
|
|
|
private bool bReadOnly;
|
|
private Guid mID;
|
|
private string mName="";
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private bool mActive;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
private AssignedDocs mDocs;
|
|
private string mNotes="";
|
|
//Display warning message of some kind when
|
|
//part selected
|
|
private string mAlert="";
|
|
|
|
|
|
private string mPartNumber=null;
|
|
private string mManufacturerNumber="";
|
|
private string mWholesalerNumber="";
|
|
private string mAlternativeWholesalerNumber="";
|
|
private decimal mCost;
|
|
private Guid mUnitOfMeasureID;
|
|
private decimal mRetail;
|
|
|
|
private Guid mPartCategoryID;
|
|
private Guid mWholesalerID;
|
|
private Guid mManufacturerID;
|
|
private Guid mAlternativeWholesalerID;
|
|
private Guid mPartAssemblyID;
|
|
private string mUPC="";
|
|
private bool mTrackSerialNumber;
|
|
|
|
|
|
|
|
//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="";
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private Part()
|
|
{
|
|
|
|
|
|
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
PartNumber="";
|
|
Active=true;
|
|
|
|
//Set record history to defaults
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
mDocs=AssignedDocs.NewItems();
|
|
|
|
}
|
|
|
|
#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>
|
|
/// Set/get Part name
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mName!=value)
|
|
{
|
|
mName = value;
|
|
|
|
|
|
BrokenRules.Assert("NameLength",
|
|
"Error.Object.FieldLengthExceeded255,Part.Label.Name",
|
|
"Name",value.Length>255);
|
|
MarkDirty();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get /set active status of Part
|
|
/// If active = true then Part is selectable for workorders etc
|
|
/// If active = false then Part in not selectable, but history can be viewed
|
|
/// </summary>
|
|
public bool Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mActive!=value)
|
|
{
|
|
mActive = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Corresponds to Parts.generalnotes in AyaNova v1
|
|
/// </summary>
|
|
public string Notes
|
|
{
|
|
get
|
|
{
|
|
return mNotes;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mNotes!=value)
|
|
{
|
|
mNotes = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Display warning message when part selected
|
|
/// DEPRECATED: THIS PROPERTY IS NOT IMPLEMENTED IN THE UI AND WILL BE REMOVED
|
|
/// </summary>
|
|
public string Alert
|
|
{
|
|
get
|
|
{
|
|
return mAlert;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mAlert!=value)
|
|
{
|
|
mAlert = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The <see cref="AssignedDocs"/> collection assigned to this part
|
|
/// </summary>
|
|
public AssignedDocs Docs
|
|
{
|
|
get
|
|
{
|
|
return mDocs;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Alternative wholesaler to order from if first does not have
|
|
/// </summary>
|
|
public Guid AlternativeWholesalerID
|
|
{
|
|
get
|
|
{
|
|
return mAlternativeWholesalerID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mAlternativeWholesalerID!=value)
|
|
{
|
|
mAlternativeWholesalerID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// who made it - ie 3COM
|
|
/// </summary>
|
|
public Guid ManufacturerID
|
|
{
|
|
get
|
|
{
|
|
return mManufacturerID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mManufacturerID!=value)
|
|
{
|
|
mManufacturerID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Part is made part of a category for display purposes and reporting. A way of
|
|
/// grouping
|
|
/// </summary>
|
|
public Guid PartCategoryID
|
|
{
|
|
get
|
|
{
|
|
return mPartCategoryID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPartCategoryID!=value)
|
|
{
|
|
mPartCategoryID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Displays on reports and Parts screen selection. (e.g. each, per 100, per box,
|
|
/// MBF, etc)
|
|
/// </summary>
|
|
public Guid UnitOfMeasureID
|
|
{
|
|
get
|
|
{
|
|
return mUnitOfMeasureID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mUnitOfMeasureID!=value)
|
|
{
|
|
mUnitOfMeasureID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Who distributes is - i.e Ingram
|
|
/// </summary>
|
|
public Guid WholesalerID
|
|
{
|
|
get
|
|
{
|
|
return mWholesalerID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mWholesalerID!=value)
|
|
{
|
|
mWholesalerID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// #2 wholesaler's part number for use when ordering when not in stock at the main wholesaler
|
|
///
|
|
/// </summary>
|
|
public string AlternativeWholesalerNumber
|
|
{
|
|
get
|
|
{
|
|
return mAlternativeWholesalerNumber;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mAlternativeWholesalerNumber!=value)
|
|
{
|
|
mAlternativeWholesalerNumber = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// cost dollar amt per part
|
|
/// </summary>
|
|
public decimal Cost
|
|
{
|
|
get
|
|
{
|
|
return mCost;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mCost!=value)
|
|
{
|
|
mCost = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Key identifier for part record - Required. 255 character maximum.
|
|
/// </summary>
|
|
public string PartNumber
|
|
{
|
|
get
|
|
{
|
|
return mPartNumber;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPartNumber!=value)
|
|
{
|
|
mPartNumber = value;
|
|
BrokenRules.Assert("PartNumberRequired",
|
|
"Error.Object.RequiredFieldEmpty,Part.Label.PartNumber",
|
|
"PartNumber",value.Length==0);
|
|
|
|
BrokenRules.Assert("PartNumberLength",
|
|
"Error.Object.FieldLengthExceeded255,Part.Label.PartNumber",
|
|
"PartNumber",value.Length>255);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// retail dollar charge for part
|
|
/// </summary>
|
|
public decimal Retail
|
|
{
|
|
get
|
|
{
|
|
return mRetail;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mRetail!=value)
|
|
{
|
|
mRetail = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Part number as given by the wholesaler - i.e Ingram
|
|
/// </summary>
|
|
public string WholesalerNumber
|
|
{
|
|
get
|
|
{
|
|
return mWholesalerNumber;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mWholesalerNumber!=value)
|
|
{
|
|
mWholesalerNumber = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Part number as given by the manufacturer - could be scanned in UPC code
|
|
/// </summary>
|
|
public string ManufacturerNumber
|
|
{
|
|
get
|
|
{
|
|
return mManufacturerNumber;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mManufacturerNumber!=value)
|
|
{
|
|
mManufacturerNumber = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 15 or less numeric digits as text
|
|
/// </summary>
|
|
public string UPC
|
|
{
|
|
get
|
|
{
|
|
return mUPC;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mUPC!=value)
|
|
{
|
|
mUPC = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// default = false Indicates that this part is serialized Triggers prompting for
|
|
/// serial number when part is received in via a purchase number
|
|
///
|
|
/// Note: if an existing part has serial numbers then this can not
|
|
/// be set to false as it would affect history and inventory
|
|
///
|
|
/// Note: if an existing part has inventory then track serial number can not be set to true
|
|
/// </summary>
|
|
public bool TrackSerialNumber
|
|
{
|
|
get
|
|
{
|
|
return mTrackSerialNumber;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
|
|
if(mTrackSerialNumber!=value)
|
|
{
|
|
mTrackSerialNumber = value;
|
|
BrokenRules.Assert("TrackSerialNumberRequired",
|
|
"Part.Error.MustTrackSerial",
|
|
"TrackSerialNumber",
|
|
!this.IsNew && value==false && PartHasSerialNumbers.GetItem(this.mID));
|
|
|
|
//case 1011
|
|
BrokenRules.Assert("TrackSerialHasInventory",
|
|
"Part.Error.TrackSerialHasInventory",
|
|
"TrackSerialNumber",
|
|
!this.IsNew && value == true && PartInventoryValuesFetcher.GetItem(mID).QuantityOnHand>0);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// part is part of an assembly null = no assembly
|
|
/// </summary>
|
|
public Guid PartAssemblyID
|
|
{
|
|
get
|
|
{
|
|
return mPartAssemblyID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mPartAssemblyID!=value)
|
|
{
|
|
mPartAssemblyID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//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,Part.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,Part.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,Part.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,Part.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,Part.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,Part.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,Part.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,Part.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,Part.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,Part.Label.Custom0","Custom0",value.Length>500);
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indicates if item can be duplicated or not
|
|
/// Item can be duplicated if the current user
|
|
/// has write rights to this item and this item
|
|
/// is not dirty or new and IsValid
|
|
/// </summary>
|
|
public bool CanDuplicate
|
|
{
|
|
get
|
|
{
|
|
if (!AyaBizUtils.CanWrite(RootObjectTypes.Part)) return false;
|
|
if (IsDirty || IsNew || (!IsValid)) return false;
|
|
return true;
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generates a duplicate of this item
|
|
/// and returns it.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Part Duplicate()
|
|
{//case 652
|
|
Part dest = Part.NewItem();
|
|
|
|
dest.Alert = Alert;
|
|
dest.AlternativeWholesalerID = AlternativeWholesalerID;
|
|
dest.AlternativeWholesalerNumber = AlternativeWholesalerNumber;
|
|
dest.Cost = Cost;
|
|
dest.Custom0 = Custom0;
|
|
dest.Custom1 = Custom1;
|
|
dest.Custom2 = Custom2;
|
|
dest.Custom3 = Custom3;
|
|
dest.Custom4 = Custom4;
|
|
dest.Custom5 = Custom5;
|
|
dest.Custom6 = Custom6;
|
|
dest.Custom7 = Custom7;
|
|
dest.Custom8 = Custom8;
|
|
dest.Custom9 = Custom9;
|
|
dest.ManufacturerID = ManufacturerID;
|
|
dest.ManufacturerNumber = ManufacturerNumber;
|
|
dest.Name = Name;
|
|
dest.Notes = Notes;
|
|
dest.PartAssemblyID = PartAssemblyID;
|
|
dest.PartCategoryID = PartCategoryID;
|
|
dest.PartNumber = DBUtil.CurrentWorkingDateTime.ToString();
|
|
dest.Retail = Retail;
|
|
dest.TrackSerialNumber = TrackSerialNumber;
|
|
dest.UnitOfMeasureID = UnitOfMeasureID;
|
|
dest.UPC = UPC;
|
|
dest.WholesalerID = WholesalerID;
|
|
dest.WholesalerNumber = WholesalerNumber;
|
|
|
|
return dest;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Flag - indicates if current user can open the wiki page for this object
|
|
/// See <see cref="WikiPage.ShowWikiLink(RootObjectTypes, Guid)"/> method for details
|
|
///
|
|
/// This is cached for the lifetime of this object
|
|
/// </summary>
|
|
|
|
public bool CanWiki
|
|
{
|
|
get
|
|
{
|
|
if (!bCanWiki.HasValue)
|
|
bCanWiki = WikiPage.ShowWikiLink(RootObjectTypes.Part, mID);
|
|
return bCanWiki.Value;
|
|
}
|
|
|
|
}
|
|
//cache the result in case the UI calls this repeatedly
|
|
private bool? bCanWiki = null;
|
|
|
|
/// <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.Part")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "Part" + mID.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
Part c=(Part)obj;
|
|
return mID==c.mID;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("Part"+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.Part")<(int)SecurityLevelTypes.ReadOnly)
|
|
return new SearchResult();
|
|
|
|
|
|
SearchResult sr=new SearchResult();
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
SafeDataReader dr = null;
|
|
try
|
|
{//AALTERNATIVEWHOLESALERNUMBER
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
|
|
"SELECT aCreated, aModified, aCreator, aModifier, aName, " +
|
|
"AALERT, aNotes, aPartNumber, aManufacturerNumber, aWholesalerNumber, " +
|
|
" AALTERNATIVEWHOLESALERNUMBER, aUPC, aCustom3, " +
|
|
" aCustom4, aCustom5, aCustom6, aCustom7, aCustom8, " +
|
|
" aCustom9, aCustom0, aCustom2, aCustom1 FROM aPart " +
|
|
"WHERE (aID = @ID)"
|
|
|
|
,ID);
|
|
|
|
if(!dr.Read())
|
|
return new SearchResult();//DBUtil.ThrowFetchError("SearchResult for PartID: " + ID.ToString());
|
|
|
|
|
|
|
|
sr.Description=AyaBizUtils.SS("",dr.GetString("aPartNumber"),"")+
|
|
AyaBizUtils.SS(" ", dr.GetString("aName"),"");
|
|
sb.Append(sr.Description);
|
|
sb.Append(" ");
|
|
sb.Append(dr.GetString("AALERT"));
|
|
sb.Append(" ");
|
|
|
|
sb.Append(dr.GetString("aNotes"));
|
|
sb.Append(" ");
|
|
|
|
sb.Append(dr.GetString("aManufacturerNumber"));
|
|
sb.Append(" ");
|
|
|
|
sb.Append(dr.GetString("aWholesalerNumber"));
|
|
sb.Append(" ");
|
|
|
|
sb.Append(dr.GetString("AALTERNATIVEWHOLESALERNUMBER"));
|
|
sb.Append(" ");
|
|
|
|
sb.Append(dr.GetString("aUPC"));
|
|
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.Part;
|
|
|
|
return sr;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Create new Part
|
|
/// </summary>
|
|
/// <returns>Part</returns>
|
|
public static Part NewItem()
|
|
{
|
|
Part c;
|
|
|
|
if(AyaBizUtils.Right("Object.Part")>(int)SecurityLevelTypes.ReadOnly)
|
|
{
|
|
c = new Part();
|
|
|
|
return c;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Part")));
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetch existing Part
|
|
/// </summary>
|
|
/// <returns>Part</returns>
|
|
/// <param name="_ID">Part Guid</param>
|
|
public static Part GetItem(Guid _ID)
|
|
{
|
|
return GetItemMRU(_ID, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a part, optionally add to MRU list
|
|
/// See <see cref="UserMRU"/>
|
|
/// </summary>
|
|
/// <param name="_ID">Part Guid internal ID number</param>
|
|
/// <param name="TrackMRU">Add to most recently used list</param>
|
|
/// <returns></returns>
|
|
public static Part GetItemMRU(Guid _ID, bool TrackMRU)
|
|
{
|
|
//case 872
|
|
|
|
|
|
if (_ID == AyaBizUtils.NewObjectGuid)
|
|
return NewItem();
|
|
|
|
if(AyaBizUtils.Right("Object.Part")>(int)SecurityLevelTypes.NoAccess)
|
|
return (Part)DataPortal.Fetch(new Criteria(_ID, TrackMRU));
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Part")));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the text to display for the part based on the input parameters and <see cref="PartDisplayFormats"/> format indicated
|
|
/// </summary>
|
|
/// <param name="Name"></param>
|
|
/// <param name="Number"></param>
|
|
/// <param name="UPC"></param>
|
|
/// <param name="Manufacturer"></param>
|
|
/// <param name="Category"></param>
|
|
/// <param name="Assembly"></param>
|
|
/// <param name="Format"></param>
|
|
/// <returns></returns>
|
|
public static string PartDisplayFormatter(
|
|
string Name, string Number, string UPC,
|
|
string Manufacturer, string Category,
|
|
string Assembly, PartDisplayFormats Format)
|
|
{
|
|
switch(Format)
|
|
{
|
|
case PartDisplayFormats.Name:
|
|
return AyaBizUtils.SS("",Name,"");
|
|
|
|
case PartDisplayFormats.NameNumber:
|
|
return AyaBizUtils.SS("",Name," - ") + AyaBizUtils.SS("",Number,"");
|
|
|
|
case PartDisplayFormats.NameUPC:
|
|
return AyaBizUtils.SS("",Name," - ") + AyaBizUtils.SS("",UPC,"");
|
|
|
|
case PartDisplayFormats.Number:
|
|
return AyaBizUtils.SS("",Number,"");
|
|
|
|
case PartDisplayFormats.NumberName:
|
|
return AyaBizUtils.SS("",Number," - ") + AyaBizUtils.SS("",Name,"");
|
|
|
|
case PartDisplayFormats.UPC:
|
|
return AyaBizUtils.SS("",UPC,"");
|
|
|
|
case PartDisplayFormats.NumberNameManufacturer:
|
|
return AyaBizUtils.SS("",Number," - ") + AyaBizUtils.SS("",Name," - ") + AyaBizUtils.SS("",Manufacturer,"");
|
|
|
|
case PartDisplayFormats.ManufacturerName:
|
|
return AyaBizUtils.SS("",Manufacturer," - ") + AyaBizUtils.SS("",Name,"");
|
|
|
|
case PartDisplayFormats.ManufacturerNumber:
|
|
return AyaBizUtils.SS("",Manufacturer," - ") + AyaBizUtils.SS("",Number,"");
|
|
|
|
case PartDisplayFormats.CategoryNumberName:
|
|
return AyaBizUtils.SS("",Category," - ") + AyaBizUtils.SS("",Number," - ") + AyaBizUtils.SS("",Name,"");
|
|
|
|
case PartDisplayFormats.AssemblyNumberName:
|
|
return AyaBizUtils.SS("",Assembly," - ") + AyaBizUtils.SS("",Number," - ") + AyaBizUtils.SS("",Name,"");
|
|
|
|
//case 1995
|
|
case PartDisplayFormats.NameNumberManufacturer:
|
|
return AyaBizUtils.SS("", Name, " - ") + AyaBizUtils.SS("", Number, " - ") + AyaBizUtils.SS("", Manufacturer, "");
|
|
|
|
//case 1995
|
|
case PartDisplayFormats.NameCategoryNumberManufacturer:
|
|
return AyaBizUtils.SS("", Name, " - ") + AyaBizUtils.SS("", Number, " - ") + AyaBizUtils.SS("", Category, " - ") + AyaBizUtils.SS("", Manufacturer, "");
|
|
|
|
|
|
}
|
|
return "Error: Global part display format not set";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check for the existance of a Part
|
|
/// in the database by ID OR by PartNumber
|
|
/// </summary>
|
|
/// <param name="ID">Guid of Part or Guid.Empty if checking by name</param>
|
|
/// <param name="PartNumber">PartNumber of Part or empty string "" if checking by ID</param>
|
|
/// <returns></returns>
|
|
public static bool Exists(Guid ID, string PartNumber)
|
|
{
|
|
//case 498
|
|
//return ExistsHelper.GetExists(ID,PartNumber);
|
|
return PartExistanceChecker.PartExists(ID, PartNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete part
|
|
/// </summary>
|
|
/// <param name="_ID">Part GUID</param>
|
|
public static void DeleteItem(Guid _ID)
|
|
{
|
|
|
|
if (AyaBizUtils.Right("Object.Part") > (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.Part")));
|
|
}
|
|
|
|
|
|
#region fetch id by text methods
|
|
/// <summary>
|
|
/// Retrieve internal ID from name.
|
|
///
|
|
/// </summary>
|
|
/// <param name="Name">Text value</param>
|
|
/// <returns>Guid ID value or Guid.Empty if no match</returns>
|
|
public static Guid GetIDFromName(string Name)
|
|
{
|
|
return GuidFetcher.GetItem("APART", "ANAME", Name);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve internal ID from PartNumber.
|
|
///
|
|
/// </summary>
|
|
/// <param name="PartNumber">Text value</param>
|
|
/// <returns>Guid ID value or Guid.Empty if no match</returns>
|
|
public static Guid GetIDFromPartNumber(string PartNumber)
|
|
{
|
|
return GuidFetcher.GetItem("APART", "APARTNUMBER", PartNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve internal ID from ManufacturerNumber.
|
|
///
|
|
/// </summary>
|
|
/// <param name="ManufacturerNumber">Text value</param>
|
|
/// <returns>Guid ID value or Guid.Empty if no match</returns>
|
|
public static Guid GetIDFromManufacturerNumber(string ManufacturerNumber)
|
|
{
|
|
return GuidFetcher.GetItem("APART", "AMANUFACTURERNUMBER", ManufacturerNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve internal ID from WholesalerNumber.
|
|
///
|
|
/// </summary>
|
|
/// <param name="WholesalerNumber">Text value</param>
|
|
/// <returns>Guid ID value or Guid.Empty if no match</returns>
|
|
public static Guid GetIDFromWholesalerNumber(string WholesalerNumber)
|
|
{
|
|
return GuidFetcher.GetItem("APART", "AWHOLESALERNUMBER", WholesalerNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve internal ID from AlternativeWholesalerNumber.
|
|
///
|
|
/// </summary>
|
|
/// <param name="AlternativeWholesalerNumber">Text value</param>
|
|
/// <returns>Guid ID value or Guid.Empty if no match</returns>
|
|
public static Guid GetIDFromAlternativeWholesalerNumber(string AlternativeWholesalerNumber)
|
|
{
|
|
return GuidFetcher.GetItem("APART", "AALTERNATIVEWHOLESALERNUMBER", AlternativeWholesalerNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve internal ID from UPC.
|
|
///
|
|
/// </summary>
|
|
/// <param name="UPC">Text value</param>
|
|
/// <returns>Guid ID value or Guid.Empty if no match</returns>
|
|
public static Guid GetIDFromUPCCode(string UPC)
|
|
{
|
|
return GuidFetcher.GetItem("APART", "AUPC", UPC);
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
///
|
|
/// <param name="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 aPart WHERE aID=@ID;",crit.ID);
|
|
if(!dr.Read())
|
|
DBUtil.ThrowFetchError("Part 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");
|
|
|
|
//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");
|
|
|
|
//Part fields
|
|
mActive=dr.GetBoolean("AACTIVE");
|
|
mName=dr.GetString("aName");
|
|
mNotes=dr.GetString("aNotes");
|
|
mAlert=dr.GetString("AALERT");
|
|
mAlternativeWholesalerID=dr.GetGuid("AALTERNATIVEWHOLESALERID");//AALTERNATIVEWHOLESALERID
|
|
mAlternativeWholesalerNumber=dr.GetString("AALTERNATIVEWHOLESALERNUMBER");
|
|
mCost=dr.GetDecimal("aCost");
|
|
mManufacturerID=dr.GetGuid("aManufacturerID");
|
|
mManufacturerNumber=dr.GetString("aManufacturerNumber");
|
|
mPartAssemblyID=dr.GetGuid("aPartAssemblyID");
|
|
mPartCategoryID=dr.GetGuid("aPartCategoryID");
|
|
PartNumber=dr.GetString("aPartNumber");
|
|
mRetail=dr.GetDecimal("aRetail");
|
|
mTrackSerialNumber=dr.GetBoolean("aTrackSerialNumber");
|
|
mUnitOfMeasureID=dr.GetGuid("aUnitOfMeasureID");
|
|
mUPC=dr.GetString("aUPC");
|
|
mWholesalerID=dr.GetGuid("aWholesalerID");
|
|
mWholesalerNumber=dr.GetString("aWholesalerNumber");
|
|
|
|
if(dr!=null) dr.Close();
|
|
|
|
//Load children:
|
|
|
|
//Docs
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM AASSIGNEDDOC WHERE (aRootObjectID=@ID and aRootObjectType=14);",crit.ID);
|
|
mDocs = AssignedDocs.GetItems(dr, RootObjectTypes.Part, RootObjectTypes.Part);
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
MarkOld();
|
|
|
|
|
|
if (crit.TrackMRU)
|
|
if (AyaBizUtils.AllowAutomaticMRUOnUpdate) AyaBizUtils.MRU.Add(RootObjectTypes.Part, mID);
|
|
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.Part")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
}
|
|
#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,"aPart");
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
throw new System.ApplicationException
|
|
(
|
|
string.Format
|
|
(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Object.NotDeleteable"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Part")
|
|
)
|
|
);
|
|
}
|
|
|
|
#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 aPart (aID, AACTIVE, aName, aNotes, AALERT, aPartNumber, aPartCategoryID, aManufacturerID, " +
|
|
"aWholesalerID, aManufacturerNumber, aWholesalerNumber, AALTERNATIVEWHOLESALERID, " +
|
|
"AALTERNATIVEWHOLESALERNUMBER, aCost, aRetail, aUnitOfMeasureID, aPartAssemblyID, aUPC, aTrackSerialNumber, aCreated,aModified,aCreator,aModifier, " +
|
|
"aCustom1, aCustom2, aCustom3, aCustom4, aCustom5, aCustom6, aCustom7, aCustom8, aCustom9, aCustom0) " +
|
|
"VALUES (@ID,@Active,@Name,@Notes,@Alert,@PartNumber,@PartCategoryID,@ManufacturerID, " +
|
|
"@WholesalerID,@ManufacturerNumber,@WholesalerNumber,@AlternativeWholesalerID, " +
|
|
"@AlternativeWholesalerNumber,@Cost,@Retail,@UnitOfMeasureID,@PartAssemblyID,@UPC,@TrackSerialNumber,@Created, @Modified, @CurrentUserID,@CurrentUserID, " +
|
|
"@Custom1,@Custom2,@Custom3,@Custom4,@Custom5,@Custom6,@Custom7,@Custom8,@Custom9,@Custom0)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aPart SET aID=@ID, AACTIVE=@Active, aName=@Name, " +
|
|
"aNotes=@Notes, AALERT=@Alert, aPartNumber=@PartNumber, " +
|
|
"aPartCategoryID=@PartCategoryID, aManufacturerID=@ManufacturerID, " +
|
|
"aWholesalerID=@WholesalerID, " +
|
|
"aManufacturerNumber=@ManufacturerNumber, " +
|
|
"aWholesalerNumber=@WholesalerNumber, AALTERNATIVEWHOLESALERID=@AlternativeWholesalerID, " +
|
|
"AALTERNATIVEWHOLESALERNUMBER=@AlternativeWholesalerNumber, " +
|
|
"aCost=@Cost, aRetail=@Retail, aUnitOfMeasureID=@UnitOfMeasureID, " +
|
|
"aPartAssemblyID=@PartAssemblyID, " +
|
|
"aUPC=@UPC, aTrackSerialNumber=@TrackSerialNumber, " +
|
|
"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"
|
|
);
|
|
|
|
|
|
cm.AddInParameter("@ID",DbType.Guid,mID);
|
|
cm.AddInParameter("@Active",DbType.Boolean, mActive);
|
|
cm.AddLargeStringInParameter("@Notes", mNotes);
|
|
cm.AddInParameter("@Name",DbType.String, mName);
|
|
cm.AddLargeStringInParameter("@Alert", mAlert);
|
|
|
|
|
|
|
|
cm.AddInParameter("@AlternativeWholesalerID",DbType.Guid,mAlternativeWholesalerID);
|
|
cm.AddInParameter("@AlternativeWholesalerNumber",DbType.String, mAlternativeWholesalerNumber);
|
|
cm.AddInParameter("@Cost",DbType.Decimal,mCost);
|
|
cm.AddInParameter("@ManufacturerID",DbType.Guid,mManufacturerID);
|
|
cm.AddInParameter("@ManufacturerNumber",DbType.String, mManufacturerNumber);
|
|
cm.AddInParameter("@PartAssemblyID",DbType.Guid,mPartAssemblyID);
|
|
cm.AddInParameter("@PartCategoryID",DbType.Guid,mPartCategoryID);
|
|
cm.AddInParameter("@PartNumber",DbType.String, mPartNumber);
|
|
cm.AddInParameter("@Retail",DbType.Decimal,mRetail);
|
|
cm.AddInParameter("@TrackSerialNumber",DbType.Boolean,mTrackSerialNumber);
|
|
cm.AddInParameter("@UnitOfMeasureID",DbType.Guid,mUnitOfMeasureID);
|
|
cm.AddInParameter("@UPC",DbType.String, mUPC);
|
|
cm.AddInParameter("@WholesalerID",DbType.Guid,mWholesalerID);
|
|
cm.AddInParameter("@WholesalerNumber",DbType.String, mWholesalerNumber);
|
|
|
|
|
|
//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);
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, transaction);
|
|
|
|
//Docs
|
|
mDocs.Update(transaction);
|
|
|
|
//Process keywords
|
|
DBUtil.ProcessKeywords(transaction,this.mID,RootObjectTypes.Part,IsNew,AyaBizUtils.Break(false,
|
|
mName,mNotes,mPartNumber,mManufacturerNumber,mWholesalerNumber,mAlternativeWholesalerNumber,
|
|
mUPC,mAlert,
|
|
/*Custom fields*/
|
|
mCustom1,mCustom2,mCustom3,mCustom4,mCustom5,mCustom6,mCustom7,mCustom8,mCustom9,mCustom0));
|
|
|
|
|
|
|
|
|
|
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;
|
|
if (AyaBizUtils.AllowAutomaticMRUOnUpdate) AyaBizUtils.MRU.Add(RootObjectTypes.Part, mID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
#endregion update
|
|
|
|
#region Delete
|
|
|
|
/// <summary>
|
|
/// Remove a Unit record .
|
|
/// </summary>
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Delete(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aPart 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.Part, crit.ID);
|
|
DBUtil.RemoveDocs(transaction, RootObjectTypes.Part, crit.ID);
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
AyaBizUtils.MRU.Remove(RootObjectTypes.Part, crit.ID);
|
|
|
|
}
|
|
}
|
|
#endregion delete
|
|
|
|
|
|
#endregion
|
|
|
|
#region Override IsValid / IsDirty
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override bool IsValid
|
|
{
|
|
get
|
|
{
|
|
return base.IsValid && mDocs.IsValid;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
return base.IsDirty || mDocs.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
|
|
|
|
#region Exists
|
|
//case 498
|
|
//[Serializable(), System.ComponentModel.Browsable(false)]
|
|
// public class ExistsHelper
|
|
//{
|
|
// bool _Exists = false;
|
|
// Guid _ID;
|
|
// string _PartNumber;
|
|
// public ExistsHelper(Guid ID, string PartNumber)
|
|
// {
|
|
// _ID=ID;
|
|
// _PartNumber=PartNumber;
|
|
// }
|
|
|
|
// public static bool GetExists(Guid ID, string PartNumber)
|
|
// { //todo fix for 425
|
|
// ExistsHelper e=new ExistsHelper(ID,PartNumber);
|
|
// DataPortal.Update(e);
|
|
// return e._Exists;
|
|
// }
|
|
|
|
// public void DataPortal_Update()
|
|
// {
|
|
// if(_PartNumber!=null && _PartNumber!="")
|
|
// {
|
|
// DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
// "SELECT aID FROM aPart WHERE " +
|
|
// "(aPartNumber = @APARTNUMBER)"
|
|
// );
|
|
// dbCommandWrapper.AddInParameter("@APARTNUMBER",DbType.String,_PartNumber);
|
|
// if(DBUtil.ToGuid(DBUtil.DB.ExecuteScalar(dbCommandWrapper))==Guid.Empty)
|
|
// this._Exists=false;
|
|
// else
|
|
// this._Exists=true;
|
|
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// if(DBUtil.ToGuid(DBUtil.GetScalarFromSQLString(
|
|
// "SELECT aID FROM aPart WHERE " +
|
|
// "(aID = @ID)",_ID
|
|
// ))==Guid.Empty)
|
|
// this._Exists=false;
|
|
// else
|
|
// this._Exists=true;
|
|
// }
|
|
// }
|
|
|
|
//}
|
|
|
|
#endregion
|
|
|
|
|
|
}//end Part
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |