DurnyklyYol/DurnyklyYol.Module/BusinessObjects/Goods.cs

231 lines
8.2 KiB
C#

using DevExpress.ExpressApp.ConditionalAppearance;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;
using FileSystemData.BusinessObjects;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace DurnyklyYol.Module.BusinessObjects
{
[DefaultClassOptions, NavigationItem("Clients & Goods")]
[ImageName("BO_Product")]
[DefaultProperty(nameof(No))]
[Appearance("RedBackground", Priority =1, AppearanceItemType = "ViewItem", TargetItems = "Credit", Criteria = "Credit > 0", BackColor = "Red", FontColor = "White")]
[Appearance("StrikeBackground", Priority = 2, AppearanceItemType = "ViewItem", TargetItems = "Credit", Criteria = "Credit = 0", BackColor = "Green",FontColor = "White")]
//[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)]
//[Persistent("DatabaseTableName")]
// Specify more UI options using a declarative approach (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112701).
public class Goods : BaseObject
{ // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx).
// Use CodeRush to create XPO classes and properties with a few keystrokes.
// https://docs.devexpress.com/CodeRushForRoslyn/118557
public Goods(Session session)
: base(session)
{
}
protected override void OnSaving()
{
base.OnSaving();
if (Session is not NestedUnitOfWork
&& (Session.DataLayer != null)
&& Session.IsNewObject(this)
&& (Session.ObjectLayer is SimpleObjectLayer)
//OR
//&& !(Session.ObjectLayer is DevExpress.ExpressApp.Security.ClientServer.SecuredSessionObjectLayer)
&& string.IsNullOrEmpty(No))
{
int nextSequence = DistributedIdGeneratorHelper.Generate(Session.DataLayer, this.GetType().FullName, "ERPrefix");
No = string.Format("PA-{0:D6}", nextSequence);
}
}
public override void AfterConstruction()
{
base.AfterConstruction();
State = GoodsState.Reserved;
CreatedAt = DateTime.Now;
}
[Size(SizeAttribute.DefaultStringMappingFieldSize), NonCloneable, Indexed(Unique = true), ReadOnly(true), VisibleInDetailView(false)]
public string No
{
get => no;
set => SetPropertyValue(nameof(No), ref no, value);
}
[Index(1), VisibleInLookupListView(true)]
[Size(SizeAttribute.DefaultStringMappingFieldSize), RuleRequiredField(DefaultContexts.Save)]
public string Name
{
get => name;
set => SetPropertyValue(nameof(Name), ref name, value);
}
[VisibleInDetailView(false)]
[ModelDefault("DisplayFormat", "{0:g}"), ModelDefault("EditMask", "g")]
public DateTime CreatedAt
{
get => createdAt;
set => SetPropertyValue(nameof(CreatedAt), ref createdAt, value);
}
[RuleValueComparison(ValueComparisonType.GreaterThan, 0), Index(2)]
public uint PlaceCount
{
get => placeCount;
set => SetPropertyValue(nameof(PlaceCount), ref placeCount, value);
}
[RuleValueComparison(ValueComparisonType.GreaterThan, 0), Index(3)]
public uint PackageCount
{
get => packageCount;
set => SetPropertyValue(nameof(PackageCount), ref packageCount, value);
}
[ModelDefault("DisplayFormat", "{0:#,##0.00 }"), ModelDefault("EditMask", "############,##0.00")]
[ImmediatePostData, Index(4), RuleValueComparison(ValueComparisonType.GreaterThan, 0)]
public decimal Volume
{
get => volume;
set => SetPropertyValue(nameof(Volume), ref volume, value);
}
[ModelDefault("DisplayFormat", "${0:#,##0.00}"), ModelDefault("EditMask", "$############,##0.00"), Index(5)]
public decimal Price
{
get => price;
set => SetPropertyValue(nameof(Price), ref price, value);
}
[PersistentAlias("Price * Volume"), ModelDefault("DisplayFormat", "${0:#,##0.00 }"), Index(6)]
public decimal TotalPrice => Convert.ToDecimal(EvaluateAlias(nameof(TotalPrice)));
[Index(7)]
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never), ImmediatePostData, VisibleInListView(false)]
public FileSystemStoreObject Image1
{
get { return GetPropertyValue<FileSystemStoreObject>("Image1"); }
set { SetPropertyValue<FileSystemStoreObject>("Image1", value); }
}
[Index(9)]
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never), ImmediatePostData, VisibleInListView(false)]
public FileSystemStoreObject Image2
{
get { return GetPropertyValue<FileSystemStoreObject>("Image2"); }
set { SetPropertyValue<FileSystemStoreObject>("Image2", value); }
}
[Size(SizeAttribute.DefaultStringMappingFieldSize), Index(10)]
public string ShopNo
{
get => shopNo;
set => SetPropertyValue(nameof(ShopNo), ref shopNo, value);
}
[Index(11)]
public Warehouse ReceivedPoint
{
get => receivedPoint;
set => SetPropertyValue(nameof(ReceivedPoint), ref receivedPoint, value);
}
[Index(12)]
public DateTime? ReceivedAt
{
get => receivedAt;
set => SetPropertyValue(nameof(ReceivedAt), ref receivedAt, value);
}
[Index(13)]
public Warehouse DestinationPoint
{
get => destinationPoint;
set => SetPropertyValue(nameof(DestinationPoint), ref destinationPoint, value);
}
[Index(14), VisibleInListView(false)]
public DateTime? DeliveredAt
{
get => deliveredAt;
set => SetPropertyValue(nameof(DeliveredAt), ref deliveredAt, value);
}
[Index(15), VisibleInListView(false)]
[Size(SizeAttribute.DefaultStringMappingFieldSize)]
public string Note
{
get => note;
set => SetPropertyValue(nameof(Note), ref note, value);
}
[Association("Goods-Payments"), Aggregated]
public XPCollection<Payment> Payments
{
get
{
return GetCollection<Payment>(nameof(Payments));
}
}
[Index(0), VisibleInLookupListView(true), VisibleInDetailView(true), IgnoreDataMember]
[Association("Client-Goods"), RuleRequiredField(DefaultContexts.Save)]
public Client Client
{
get => client;
set => SetPropertyValue(nameof(Client), ref client, value);
}
[VisibleInDetailView(false)]
[ModelDefault("DisplayFormat", "${0:#,##0.00}")]
public decimal TotalPayment => Payments.Sum(ps => ps.Amount);
[VisibleInDetailView(false)]
[ModelDefault("DisplayFormat", "${0:#,##0.00}")]
public decimal Credit => TotalPrice - TotalPayment;
public GoodsState State
{
get => state;
set => SetPropertyValue(nameof(State), ref state, value);
}
string note;
DateTime? deliveredAt;
Warehouse destinationPoint;
Warehouse receivedPoint;
string shopNo;
DateTime createdAt;
GoodsState state;
uint packageCount;
DateTime? receivedAt;
decimal price;
uint placeCount;
decimal volume;
string name;
string no;
Client client;
Cargo cargo;
[Association("Cargo-Goods")]
public Cargo Cargo
{
get => cargo;
set => SetPropertyValue(nameof(Cargo), ref cargo, value);
}
}
public enum GoodsState
{
Reserved,
Received,
Delivered,
}
}