1

这是我想做的:

我们有一个基于特定子系统(比如说 SAP)的 POS 系统,但需要能够切换到另一个子系统(例如 MS Dynamics)。

我想创建一个新的付款窗口,用户可以在其中使用一种或多种付款方式(现金、借记卡、VISA ......)支付他的发票。

所以,我虽然会为存在的不同 PaymentMode 创建一个 ENUM(..)。这样,从一个子系统 (SAP) 切换到另一个子系统 (SAP) 将很容易,因为枚举应该是相同的:

Public enum PaymentMode
{
    AccountReceivable = 0,
    Cash = 1,
    Debit = 2,
    Check = 3,
    GiftCertificate = 4,
    Other_01 = 10, //depend on the sub-system...may be VISA/AMEX/MasterCard...
    Other_02 = 11, //depend on the sub-system...may be VISA/AMEX/MasterCard...
    Other_03 = 12, //depend on the sub-system...may be VISA/AMEX/MasterCard...
    Other_04 = 13  //depend on the sub-system...may be VISA/AMEX/MasterCard...
} 

另外,我有一个代表真实客户付款的课程:

public class Payment
{
    public PaymentMode PaymentMode {get;set;} //here is my enum.  
    public double dbl_Amount {get; set;}
    public Datetime date_Payment {get; set;}
}

然后,有了这个,我发现向发票中添加付款很简单:

   double dbl_TotalAmountToPay = 399,41;

   //can accept a multi-payment for a single invoice..
   List<Payment> myWholePayments = new List<Payment>();

   //FIRST PAYMENT
   Payment myFirstPayment  = new Payment; 
   myFirstPayment.PaymentMode = PaymentMode.Cash;
   myFirstPayment.dbl_Amount = 100;
   myWholePayments.add(myFirstPayment);

   //SECOND PAYMENT
   Payment mySecondPayment  = new Payment;
   mySecondPayment.PaymentMode = PaymentMode.Other_02; //based on the name shown on the button pressed (visa/AMEX...)
   mySecondPayment.dbl_Amount = 299.41;
   myWholePayments.add(mySecondPayment);

然后我可以轻松移动我的付款清单,甚至在网格中显示它......

这是我的问题(是的,最后):

  1. 基于它不是真正静态的事实(比如几个月),我尝试使用 ENUM 是错误的吗?

  2. 基于可能从一个系统/客户更改的事实(信用卡名称由 SAP 系统的经理编写),我如何设法显示付款类型的名称。PaymentMode.Other_01 在一个系统中可以命名为“VISA”,在另一个系统中可以命名为“AMEX”。

    同样的问题也适用于我的翻译器(将 ENUM 转换为终端系统代码)。在 SAP 中,“CASH”支付模式将是一个整数 0。在 Dynamics 中,它是一个 GUID {3131-3-b;ablabla}。我怎样才能优雅地翻译呢?

现在是星期五下午...如果那里有任何愚蠢,很抱歉...:|

4

2 回答 2

1

Yes, an enum should be "static" or at least not expected to change per implementation.

You should consider using the enum to handle general payment modes, and implement code to translate this meaning to the correct backend system.

Public enum PaymentMode
{
    AccountReceivable = 0,
    Cash = 1,
    Debit = 2,
    Check = 3,
    GiftCertificate = 4,
    AMEX = 5, 
    VISA = 6,
    etc
} 

The translate code would be something like this, which you would invoke prior to calling the target system.

   public static object GetTranslatedValueForPaymentMode(PaymentMode pm)
    {
        if (backendSystem == "SAP)
        {    
            switch case (pm)
            {
                case PaymentMode.AMEX:
                    return "33"; //whatever code this is
                case PaymentMode.VISA:
                    return "AVC"; //whatever code this is
            }
        }
        else if (backendSystem == "GreatPains")
        {
            switch case (pm)
            {
                case PaymentMode.AMEX:
                    return new Guid("GKSKJDS"); //whatever code this is
                case PaymentMode.VISA:
                    return new Guid("DADADA"); //whatever code this is
            }
        }
    }
于 2013-09-27T17:47:38.533 回答
0

我想我会采用这种方法:

public enum PaymentMode
{
    AccountReceivable = 0,
    Cash = 1,
    Debit = 2,
    Check = 3,
    GiftCertificate = 4,
    Visa = 5,
    Amex = 6,
    MasterCard = 7,
    Other = 20,
}

然后,不是简单地将按钮 1、2、3、4 映射到值Other_01020304,而是为每个不同的键布局设置一些代码以映射到正确的支付类型。例如

public class Layout1 : LayoutBase
{
    public override PaymentMode GetPaymentType(int key)
    {
        switch (key)
        {
            case 1:
                return PaymentMode.Visa;
            // others...
        }
    }
}
public class Layout2 : LayoutBase
{
    public override PaymentMode GetPaymentType(int key)
    {
        switch (key)
        {
            case 1:
                return PaymentMode.MasterCard;
            // others...
        }
    }
}

对于CASH由 GUID 或 a 表示的问题0,我想说您也可以使用代码来处理它:

public class DynamicsLayout : LayoutBase
{
    public override PaymentMode GetPaymentType(object raw)
    {
        if (raw is string && raw.ToString() == "{3131-3-b;ablabla}")
            return PaymentMode.Cash;
        // others
    }
}
于 2013-09-27T17:52:22.173 回答