You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

232 lines
6.6 KiB

namespace com.hitrust.trustpay.client.b2c
{
using client;
using System;
using System.Collections;
public class Order
{
private double iOrderAmount;
private string iOrderDate;
private string iOrderDesc;
private ArrayList iOrderItems;
private string iOrderNo;
private string iOrderStatus;
private string iOrderTime;
private string iOrderURL;
private double iPayAmount;
private double iRefundAmount;
public const int ORDER_DESC_LEN = 100;
public const int ORDER_NO_LEN = 50;
public const string ORDER_STATUS_CANCEL = "00";
public const string ORDER_STATUS_ISSUE = "99";
public const string ORDER_STATUS_NEW = "01";
public const string ORDER_STATUS_PAY = "03";
public const string ORDER_STATUS_REFUND = "05";
public const string ORDER_STATUS_SETTLED = "04";
public const string ORDER_STATUS_WAIT = "02";
public const int ORDER_URL_LEN = 200;
public Order()
{
this.iOrderNo = "";
this.iOrderDesc = "";
this.iOrderDate = "";
this.iOrderTime = "";
this.iOrderAmount = 0.0;
this.iOrderItems = null;
this.iOrderURL = "";
this.iPayAmount = 0.0;
this.iRefundAmount = 0.0;
this.InitBlock();
this.iOrderItems = new ArrayList();
}
public Order(XMLDocument aXMLDocument)
{
this.iOrderNo = "";
this.iOrderDesc = "";
this.iOrderDate = "";
this.iOrderTime = "";
this.iOrderAmount = 0.0;
this.iOrderItems = null;
this.iOrderURL = "";
this.iPayAmount = 0.0;
this.iRefundAmount = 0.0;
this.InitBlock();
this.initByXMLDocument(aXMLDocument);
}
public virtual Order addOrderItem(OrderItem aOrderItem)
{
this.iOrderItems.Add(aOrderItem);
return this;
}
public virtual Order clearOrderItems()
{
this.iOrderItems = new ArrayList();
return this;
}
public virtual XMLDocument getXMLDocument(int aType)
{
string str = string.Concat(new object[] {"<Order><OrderNo>", this.iOrderNo, "</OrderNo><OrderAmount>", this.iOrderAmount, "</OrderAmount>"});
if ((aType == 1) || (aType == 3)) {
str = str + "<OrderDesc>" + this.iOrderDesc + "</OrderDesc><OrderDate>" + this.iOrderDate + "</OrderDate><OrderTime>" + this.iOrderTime + "</OrderTime><OrderURL>" + this.iOrderURL + "</OrderURL><OrderItems>";
for (int i = 0; i < this.iOrderItems.Count; i++) {
OrderItem item = (OrderItem)this.iOrderItems[i];
str = str + item.XMLDocument.ToString();
}
str = str + "</OrderItems>";
}
if ((aType == 2) || (aType == 3)) {
str = string.Concat(new object[] {str, "<PayAmount>", this.iPayAmount, "</PayAmount><RefundAmount>", this.iRefundAmount, "</RefundAmount><OrderStatus>", this.iOrderStatus, "</OrderStatus>"});
}
return new XMLDocument(str + "</Order>");
}
private void InitBlock()
{
this.iOrderStatus = "01";
}
public Order initByString(string aOrderString)
{
this.initByXMLDocument(new XMLDocument(aOrderString));
return this;
}
private Order initByXMLDocument(XMLDocument aXMLDocument)
{
this.OrderItems = new ArrayList();
this.OrderNo = aXMLDocument.getValueNoNull("OrderNo");
this.OrderDesc = aXMLDocument.getValueNoNull("OrderDesc");
this.OrderDate = aXMLDocument.getValueNoNull("OrderDate");
this.OrderTime = aXMLDocument.getValueNoNull("OrderTime");
this.OrderURL = aXMLDocument.getValueNoNull("OrderURL");
this.OrderStatus = aXMLDocument.getValueNoNull("OrderStatus");
this.OrderAmount = double.Parse(aXMLDocument.getValueNoNull("OrderAmount"));
this.PayAmount = double.Parse(aXMLDocument.getValueNoNull("PayAmount"));
this.RefundAmount = double.Parse(aXMLDocument.getValueNoNull("RefundAmount"));
ArrayList list = aXMLDocument.getDocuments("OrderItem");
for (int i = 0; i < list.Count; i++) {
this.addOrderItem(new OrderItem((XMLDocument)list[i]));
}
return this;
}
public virtual string isValid()
{
if (this.iOrderNo == null) {
return "订单号为空";
}
if (this.iOrderDate == null) {
return "订单日期为空";
}
if (this.iOrderTime == null) {
return "订单时间为空";
}
if (this.iOrderAmount <= 0.0) {
return "订单金额小于等于零";
}
if (this.iOrderURL == null) {
return "订单查询网址为空";
}
if (this.iOrderNo.Length == 0) {
return "订单号长度为零";
}
if (this.iOrderURL.Length == 0) {
return "订单查询网址为空";
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrderNo)).Length > 50) {
return "订单号超长";
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrderDesc)).Length > 100) {
return "订单说明超长";
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrderURL)).Length > 200) {
return "订单网址超长";
}
if (!DataVerifier.isValidDate(this.iOrderDate)) {
return "订单日期不合法";
}
if (!DataVerifier.isValidTime(this.iOrderTime)) {
return "订单时间不合法";
}
if (!DataVerifier.isValidAmount(this.iOrderAmount, 2)) {
return "订单金额不合法";
}
if ((this.iOrderURL.Length > 0) && !DataVerifier.isValidURL(this.iOrderURL)) {
return "订单查询网址不合法";
}
for (int i = 0; i < this.iOrderItems.Count; i++) {
string str = ((OrderItem)this.iOrderItems[i]).isValid();
if (str.Length > 0) {
return str;
}
}
return "";
}
public virtual double OrderAmount
{
get { return this.iOrderAmount; }
set { this.iOrderAmount = value; }
}
public virtual string OrderDate
{
get { return this.iOrderDate; }
set { this.iOrderDate = value.Trim(); }
}
public virtual string OrderDesc
{
get { return this.iOrderDesc; }
set { this.iOrderDesc = value.Trim(); }
}
public virtual ArrayList OrderItems
{
get { return this.iOrderItems; }
set { this.iOrderItems = value; }
}
public virtual string OrderNo
{
get { return this.iOrderNo; }
set { this.iOrderNo = value.Trim(); }
}
public virtual string OrderStatus
{
get { return this.iOrderStatus; }
set { this.iOrderStatus = value; }
}
public virtual string OrderTime
{
get { return this.iOrderTime; }
set { this.iOrderTime = value.Trim(); }
}
public virtual string OrderURL
{
get { return this.iOrderURL; }
set { this.iOrderURL = value.Trim(); }
}
public virtual double PayAmount
{
get { return this.iPayAmount; }
set { this.iPayAmount = value; }
}
public virtual double RefundAmount
{
get { return this.iRefundAmount; }
set { this.iRefundAmount = value; }
}
}
}