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.
243 lines
7.7 KiB
243 lines
7.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace n5coredll
|
|
{
|
|
class ObjectUtil {
|
|
|
|
public static bool isNull(object obj) {
|
|
if (obj == null || "".Equals(obj.ToString())) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static TxnType getTxnType(String pTxnType) {
|
|
switch (pTxnType) {
|
|
case "SALE":
|
|
return TxnType.SALE;
|
|
case "REFUND":
|
|
return TxnType.REFUND;
|
|
default:
|
|
return TxnType.NONE;
|
|
}
|
|
}
|
|
|
|
public static string getTxnTypeValue(TxnType pTxnType) {
|
|
switch (pTxnType) {
|
|
case TxnType.SALE:
|
|
return "SALE";
|
|
case TxnType.REFUND:
|
|
return "REFUND";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static TxnStatus getTxnStatus(String pTxnStatus)
|
|
{
|
|
switch (pTxnStatus)
|
|
{
|
|
case "A":
|
|
return TxnStatus.Approved;
|
|
case "P":
|
|
return TxnStatus.Confirming;
|
|
case "V":
|
|
return TxnStatus.Voided;
|
|
case "S":
|
|
return TxnStatus.Settled;
|
|
default:
|
|
return TxnStatus.Failed;
|
|
}
|
|
}
|
|
|
|
public static LoyaltyType getLoyaltyType(String pLoyalType) {
|
|
switch (pLoyalType) {
|
|
case "UP":
|
|
return LoyaltyType.UP;
|
|
case "MT":
|
|
return LoyaltyType.MT;
|
|
case "BK":
|
|
return LoyaltyType.BK;
|
|
case "LM":
|
|
return LoyaltyType.LM;
|
|
default:
|
|
return LoyaltyType.NONE;
|
|
}
|
|
}
|
|
|
|
public static string getLoyaltyTypeValue(LoyaltyType pLoyalType) {
|
|
switch (pLoyalType) {
|
|
case LoyaltyType.UP:
|
|
return "UP";
|
|
case LoyaltyType.MT:
|
|
return "MT";
|
|
case LoyaltyType.BK:
|
|
return "BK";
|
|
case LoyaltyType.LM:
|
|
return "LM";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static PaymentApp getPaymentApp(String pPaymentApp) {
|
|
switch (pPaymentApp) {
|
|
case "CC":
|
|
return PaymentApp.CC;
|
|
case "QRC":
|
|
return PaymentApp.QRC;
|
|
case "CPN":
|
|
return PaymentApp.CPN;
|
|
case "AE":
|
|
return PaymentApp.AMEX;
|
|
case "DC":
|
|
return PaymentApp.DC;
|
|
case "FPS":
|
|
return PaymentApp.FPS;
|
|
case "EPS":
|
|
return PaymentApp.EPS;
|
|
case "OPS":
|
|
return PaymentApp.OPS;
|
|
default:
|
|
return PaymentApp.NONE;
|
|
}
|
|
}
|
|
|
|
public static string getPaymentAppValue(PaymentApp pPaymentApp) {
|
|
switch (pPaymentApp) {
|
|
case PaymentApp.CC:
|
|
return "CC";
|
|
case PaymentApp.QRC:
|
|
return "QRC";
|
|
case PaymentApp.CPN:
|
|
return "CPN";
|
|
case PaymentApp.AMEX:
|
|
return "AE";
|
|
case PaymentApp.DC:
|
|
return "DC";
|
|
case PaymentApp.FPS:
|
|
return "FPS";
|
|
case PaymentApp.EPS:
|
|
return "EPS";
|
|
case PaymentApp.OPS:
|
|
return "OPS";
|
|
default:
|
|
return "NONE";
|
|
}
|
|
}
|
|
|
|
public static PaymentType getPaymentType(String pPaymentType) {
|
|
switch (pPaymentType) {
|
|
case "VC":
|
|
return PaymentType.VC;
|
|
case "VC-QR":
|
|
return PaymentType.VC_QR;
|
|
case "MC":
|
|
return PaymentType.MC;
|
|
case "MC-QR":
|
|
return PaymentType.MC_QR;
|
|
case "JCB":
|
|
return PaymentType.JCB;
|
|
case "JCB-QR":
|
|
return PaymentType.JCB_QR;
|
|
case "UP":
|
|
return PaymentType.UP;
|
|
case "UP-QR":
|
|
return PaymentType.UP_QR;
|
|
case "AE":
|
|
return PaymentType.AE;
|
|
case "DC":
|
|
return PaymentType.DC;
|
|
case "ALP":
|
|
return PaymentType.ALP;
|
|
case "WCP":
|
|
return PaymentType.WCP;
|
|
case "EPS":
|
|
return PaymentType.EPS;
|
|
default:
|
|
return PaymentType.NONE;
|
|
}
|
|
}
|
|
|
|
public static string getPaymentTypeValue(PaymentType pPaymentType) {
|
|
switch (pPaymentType) {
|
|
case PaymentType.VC:
|
|
return "VC";
|
|
case PaymentType.VC_QR:
|
|
return "VC-QR";
|
|
case PaymentType.MC:
|
|
return "MC";
|
|
case PaymentType.MC_QR:
|
|
return "MC-QR";
|
|
case PaymentType.JCB:
|
|
return "JCB";
|
|
case PaymentType.JCB_QR:
|
|
return "JCB-QR";
|
|
case PaymentType.UP:
|
|
return "UP";
|
|
case PaymentType.UP_QR:
|
|
return "UP-QR";
|
|
case PaymentType.AE:
|
|
return "AE";
|
|
case PaymentType.DC:
|
|
return "DC";
|
|
case PaymentType.ALP:
|
|
return "ALP";
|
|
case PaymentType.WCP:
|
|
return "WCP";
|
|
case PaymentType.EPS:
|
|
return "EPS";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static Byte[] ConvertFrom(string strTemp) {
|
|
try {
|
|
if (Convert.ToBoolean(strTemp.Length & 1))//数字的二进制码最后1位是1则为奇数
|
|
{
|
|
strTemp = "0" + strTemp;//数位为奇数时前面补0
|
|
}
|
|
Byte[] aryTemp = new Byte[strTemp.Length / 2];
|
|
for (int i = 0; i < (strTemp.Length / 2); i++) {
|
|
aryTemp[i] = (Byte)(((strTemp[i * 2] - '0') << 4) | (strTemp[i * 2 + 1] - '0'));
|
|
}
|
|
return aryTemp;//高位在前
|
|
}
|
|
catch { return null; }
|
|
}
|
|
|
|
public static Byte lrc(Byte[] datas) {
|
|
byte tmp = 0;
|
|
for (int i = 0; i < datas.Length; i++) {
|
|
tmp ^= datas[i];
|
|
}
|
|
return tmp;
|
|
}
|
|
|
|
public static string bcd2Str(byte[] bytes) {
|
|
Console.WriteLine("Execute bcd2Str!");
|
|
|
|
StringBuilder temp = new StringBuilder();
|
|
for (int i = 0; i < bytes.Length; i++) {
|
|
int h = ((bytes[i] & 0xff) >> 4) + 48;
|
|
temp.Append((char)h);
|
|
int l = ((bytes[i] & 0x0f)) + 48;
|
|
temp.Append((char)l);
|
|
}
|
|
return temp.ToString();
|
|
}
|
|
|
|
public static string desToHex(byte[] bytes) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (int i = 0; i < bytes.Length; i++) {
|
|
string st = string.Format("%02X", bytes[i]);
|
|
sb.Append(st);
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|
|
|