コード例 #1
0
        internal List <mTransaction> ReadMPU_BCOM(string filepath)
        {
            if (HttpContext.Session["UID"] == null)
            {
                return(new List <mTransaction>());
            }
            List <mTransaction> Tran_List = new List <mTransaction>();
            string error_Lines            = "Terminated!!! \nError : ";

            try
            {
                if (!string.IsNullOrEmpty(filepath))
                {
                    //Get Trx Date
                    string datestr = Path.GetFileName(filepath);

                    string year  = "20" + datestr.Substring(3, 2);
                    string month = datestr.Substring(5, 2);
                    string day   = datestr.Substring(7, 2);

                    DateTime TRXDate = DateTime.ParseExact(year + "-" + month + "-" + day, "yyyy-MM-dd", null);

                    //Read File
                    string[] lines = System.IO.File.ReadAllLines(filepath);

                    foreach (var line in lines)
                    {
                        string[]     arr  = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                        mTransaction tran = new mTransaction();
                        tran.CardNo = arr[4].ToString();

                        mCardType cardtype = new mCardType();
                        cardtype.BINCode = tran.CardNo.Substring(0, 4).ToString();
                        tran.CardType    = cardtype.get_card_type();

                        tran.TrxAmount       = Convert.ToDouble(arr[5].ToString()) / 100;
                        tran.MPU_Merchant_ID = arr[12].ToString();
                        tran.ProcessingCode  = arr[19].ToString();
                        tran.TerminalID      = arr[11].ToString();

                        if (tran.ProcessingCode.Length > 3)
                        {
                            tran.ProcessingCode = arr[18].ToString();
                            tran.TerminalID     = arr[15].ToString();
                        }

                        double rate = 0;

                        mMerchant merchant = new mMerchant();
                        merchant.MPU_Merchant_ID = tran.MPU_Merchant_ID;
                        rate = merchant.get_mdr_rate_mpuonus(merchant);

                        if (rate == -123)
                        {
                            // rate -123 means that cannot get merchant's MDR rate or merchant info does not exist
                            // so we need to block transaction to upload and show warning
                            Global_Error = true;
                            error_Lines += merchant.MPU_Merchant_ID + ",";
                            TempData["MerchantInfoError"] = error_Lines;
                            TempData.Keep();
                        }
                        tran.TRXMDRRate = rate;
                        tran.MDRValue   = (tran.TrxAmount * rate) / 100;
                        tran.SettAmount = tran.TrxAmount - tran.MDRValue;
                        tran.TrxDate    = TRXDate;
                        tran.TRXRemark  = Session["UID"].ToString();
                        tran.RecordType = "MPU_ON_US";
                        Tran_List.Add(tran);
                    }
                }
            }
            catch (Exception ex)
            {
                TempData["MerchantInfoError"] = ex.Message;
                TempData.Keep();
            }


            return(Tran_List);
        }