DurnyklyYol/DurnyklyYol.Module/BusinessObjects/Payment.cs

95 lines
3.5 KiB
C#
Raw Normal View History

2024-09-02 10:07:25 +00:00
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace DurnyklyYol.Module.BusinessObjects
{
[DefaultClassOptions, NavigationItem("Finance")]
[ImageName("Refund")]
[DefaultProperty(nameof(No))]
//[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)]
//[Persistent("DatabaseTableName")]
// Specify more UI options using a declarative approach (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112701).
public class Payment : 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 Payment(Session session)
: base(session)
{
}
public override void AfterConstruction()
{
base.AfterConstruction();
PaymentDate = DateTime.Now;
}
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("GD-{0:D6}", nextSequence);
}
}
string description;
string no;
decimal amount;
Goods goods;
DateTime paymentDate;
[Size(SizeAttribute.DefaultStringMappingFieldSize), RuleUniqueValue,Indexed(Unique = true), RuleUniqueValue, ReadOnly(true), VisibleInDetailView(false)]
public string No
{
get => no;
set => SetPropertyValue(nameof(No), ref no, value);
}
[RuleValueComparison(ValueComparisonType.GreaterThan, 0)]
[ModelDefault("DisplayFormat", "${0:#,##0.00}")]
public decimal Amount
{
get => amount;
set => SetPropertyValue(nameof(Amount), ref amount, value);
}
[RuleRequiredField(DefaultContexts.Save)]
[ModelDefault("DisplayFormat", "{0:g}"), ModelDefault("EditMask", "g")]
public DateTime PaymentDate
{
get => paymentDate;
set => SetPropertyValue(nameof(PaymentDate), ref paymentDate, value);
}
[Size(SizeAttribute.DefaultStringMappingFieldSize)]
public string Description
{
get => description;
set => SetPropertyValue(nameof(Description), ref description, value);
}
[RuleRequiredField(DefaultContexts.Save), ImmediatePostData]
[Association("Goods-Payments")]
public Goods Goods
{
get => goods;
set => SetPropertyValue(nameof(Goods), ref goods, value);
}
public Client Client => Goods?.Client;
}
}