DurnyklyYol/DurnyklyYol.Module/BusinessObjects/Goods.cs

241 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);
}
[Size(SizeAttribute.DefaultStringMappingFieldSize), RuleRequiredField(DefaultContexts.Save), Index(2), VisibleInLookupListView(true)]
public string Name
{
get => name;
set => SetPropertyValue(nameof(Name), ref name, value);
}
[ModelDefault("DisplayFormat", "{0:g}"), ModelDefault("EditMask", "g"), ReadOnly(true)]
public DateTime CreatedAt
{
get => createdAt;
set => SetPropertyValue(nameof(CreatedAt), ref createdAt, value);
}
[RuleValueComparison(ValueComparisonType.GreaterThan, 0)]
public double Volume
{
get => volume;
set => SetPropertyValue(nameof(Volume), ref volume, value);
}
[RuleValueComparison(ValueComparisonType.GreaterThan, 0)]
public uint PlaceCount
{
get => placeCount;
set => SetPropertyValue(nameof(PlaceCount), ref placeCount, value);
}
[RuleValueComparison(ValueComparisonType.GreaterThan, 0)]
public uint PackageCount
{
get => packageCount;
set => SetPropertyValue(nameof(PackageCount), ref packageCount, value);
}
[Size(SizeAttribute.DefaultStringMappingFieldSize), IgnoreDataMember]
public string PackingType
{
get => packingType;
set => SetPropertyValue(nameof(PackingType), ref packingType, value);
}
public DateTime ReceivedAt
{
get => receivedAt;
set => SetPropertyValue(nameof(ReceivedAt), ref receivedAt, value);
}
[ModelDefault("DisplayFormat", "${0:#,##0.00}")]
public decimal Price
{
get => price;
set => SetPropertyValue(nameof(Price), ref price, value);
}
public uint Height
{
get => height;
set => SetPropertyValue(nameof(Height), ref height, value);
}
public uint Width
{
get => width;
set => SetPropertyValue(nameof(Width), ref width, value);
}
public uint Depth
{
get => depth;
set => SetPropertyValue(nameof(Depth), ref depth, value);
}
//[RuleRequiredField(DefaultContexts.Save), Index(1)]
//public Shop Shop
//{
// get => shop;
// set => SetPropertyValue(nameof(Shop), ref shop, value);
//}
[Size(SizeAttribute.DefaultStringMappingFieldSize)]
public string ShopNo
{
get => shopNo;
set => SetPropertyValue(nameof(ShopNo), ref shopNo, value);
}
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never), ImmediatePostData]
public FileSystemStoreObject Image1
{
get { return GetPropertyValue<FileSystemStoreObject>("Image1"); }
set { SetPropertyValue<FileSystemStoreObject>("Image1", value); }
}
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never), ImmediatePostData]
public FileSystemStoreObject Image2
{
get { return GetPropertyValue<FileSystemStoreObject>("Image2"); }
set { SetPropertyValue<FileSystemStoreObject>("Image2", value); }
}
[Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never), ImmediatePostData]
public FileSystemStoreObject Image3
{
get { return GetPropertyValue<FileSystemStoreObject>("Image3"); }
set { SetPropertyValue<FileSystemStoreObject>("Image3", value); }
}
[Association("Goods-Payments"), Aggregated]
public XPCollection<Payment> Payments
{
get
{
return GetCollection<Payment>(nameof(Payments));
}
}
[Association("Goods-GoodsImages"), Aggregated]
public XPCollection<GoodsImage> Images
{
get { return GetCollection<GoodsImage>(nameof(Images)); }
}
[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 => Price - TotalPayment;
public GoodsState State
{
get => state;
set => SetPropertyValue(nameof(State), ref state, value);
}
string shopNo;
DateTime createdAt;
GoodsState state;
//Shop shop;
uint depth;
uint width;
uint height;
uint packageCount;
string packingType;
DateTime receivedAt;
decimal price;
uint placeCount;
double 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,
}
}