Example #1
0
        public CurrencyModels GetCurrencyCurrent()
        {
            CurrencyModels obj = new CurrencyModels();

            try
            {
                GetCurrencyRequest paraBody = new GetCurrencyRequest();
                paraBody.IsActive = true;

                NSLog.Logger.Info("GetCurrencyCurrent Request", paraBody);
                var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CurrencyAPIGetList, null, paraBody);
                NSLog.Logger.Info("GetCurrencyCurrent Response", paraBody);
                dynamic data                   = result.Data;
                var     lstDataRaw             = data["ListCurrency"];
                var     lstObject              = JsonConvert.SerializeObject(lstDataRaw);
                List <CurrencyModels> listData = JsonConvert.DeserializeObject <List <CurrencyModels> >(lstObject);
                if (listData != null && listData.Any())
                {
                    obj = listData.FirstOrDefault();
                }
                return(obj);
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("GetCurrencyCurrent_Fail", e);
                return(obj);
            }
        }
Example #2
0
        // 기준통화 데이터 목록을 리턴한다
        public static List <CurrencyModels> GetCurrencyDataList(string rainbow_code)
        {
            string sql1 = "select "
                          + "CC.SEQNO"
                          + ", CC.RAINBOWCODE"
                          + ", CC.CURRENCY_UNIT"
                          + ", CC.CURRENCY_SYMBOL"
                          + ", CC.BASIC_UNIT"
                          + ", CC.MEMO"
                          + ", (select CE.AMNT from CONFIG_EXCHANGE_RATE CE where CE.RAINBOWCODE=CC.RAINBOWCODE and CE.CURRENCY_UNIT=CC.CURRENCY_UNIT order by CE.SEQNO desc limit 1) as EXCHANGE_RATE"
                          + ", (select DATE_FORMAT(CE.DATETIME_UPD,'%Y-%m-%d %T') from CONFIG_EXCHANGE_RATE CE where CE.RAINBOWCODE=CC.RAINBOWCODE and CE.CURRENCY_UNIT=CC.CURRENCY_UNIT order by CE.SEQNO desc limit 1) as DATETIME_UPD"
                          + " from CONFIG_CURRENCY CC"
                          + string.Format(" where CC.RAINBOWCODE='{0}'", rainbow_code)
                          + " order by CC.SEQNO"
                          + "";
            string    err1 = "";
            DataTable dt1  = DatabaseConnection.GetDataTableMySQL(sql1, out err1);

            if (dt1 == null)
            {
                return(null);
            }



            List <CurrencyModels> CURRENCY_LIST = new List <CurrencyModels>();

            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                CurrencyModels CURRENCY = new CurrencyModels();

                CURRENCY.SEQNO           = GlobalFunction.GetInt(dt1.Rows[i]["SEQNO"].ToString().Trim());               // 순번
                CURRENCY.RAINBOWCODE     = dt1.Rows[i]["RAINBOWCODE"].ToString().Trim();                                // 지점코드
                CURRENCY.CURRENCY_UNIT   = dt1.Rows[i]["CURRENCY_UNIT"].ToString().Trim().ToUpper();                    // 기준통화 종류(USD, CNY, KRW, EUR ...)
                CURRENCY.CURRENCY_SYMBOL = dt1.Rows[i]["CURRENCY_SYMBOL"].ToString().Trim();                            // 기준통화 기호($, ¥, ₩, € ...)
                CURRENCY.BASIC_UNIT      = GlobalFunction.GetDouble(dt1.Rows[i]["BASIC_UNIT"].ToString().Trim(), 2);    // 기준 단위
                CURRENCY.MEMO            = dt1.Rows[i]["MEMO"].ToString().Trim();                                       // 메모
                CURRENCY.EXCHANGE_RATE   = GlobalFunction.GetDouble(dt1.Rows[i]["EXCHANGE_RATE"].ToString().Trim(), 4); // 최근 환율
                CURRENCY.DATETIME_UPD    = dt1.Rows[i]["DATETIME_UPD"].ToString().Trim();                               // 최근 환율 저장날짜

                CURRENCY_LIST.Add(CURRENCY);
            }

            return(CURRENCY_LIST);
        }
Example #3
0
        // 금액을 목적지 화폐로 변환한다
        public static double ExchangePrice(
            string rainbow_code
            , string branch_currency
            , double price
            , string from_currency
            , string to_currency
            , List <CurrencyModels> CURRENCY_LIST = null
            )
        {
            string BRANCH_CURRENCY = branch_currency.Trim().ToUpper();      // 출발국가 화폐단위
            double exchange_price  = price;
            string FROM_CURRENCY   = from_currency.Trim().ToUpper();        // 변환전 화폐단위
            string TO_CURRENCY     = to_currency.Trim().ToUpper();          // 목적지 화폐단위

            // 일단 출발국가 화폐로 변경한뒤 목적지 화폐로 변환한다
            if (FROM_CURRENCY != TO_CURRENCY)
            {
                // 먼저 출발국가 화폐로 변경한다
                if (FROM_CURRENCY != BRANCH_CURRENCY)
                {
                    double from_rate  = 0.0;
                    int    basic_unit = 0;
                    if (CURRENCY_LIST != null && CURRENCY_LIST.Count > 0)
                    {
                        CurrencyModels CURRENCY = CURRENCY_LIST.Find(m => m.RAINBOWCODE == rainbow_code && m.CURRENCY_UNIT == FROM_CURRENCY);
                        if (CURRENCY != null && CURRENCY.CURRENCY_UNIT == FROM_CURRENCY)
                        {
                            from_rate  = CURRENCY.EXCHANGE_RATE;
                            basic_unit = (int)CURRENCY.BASIC_UNIT;
                        }
                    }
                    else
                    {
                        GetExchangeRate(rainbow_code, FROM_CURRENCY, ref from_rate, ref basic_unit);
                    }

                    if (from_rate <= 0.0 || basic_unit < 0)
                    {
                        return(price);
                    }

                    if (BRANCH_CURRENCY == "KRW")
                    {
                        exchange_price = exchange_price * from_rate / basic_unit;
                    }
                    else                     //if (BRANCH_CURRENCY == "USD")
                    {
                        exchange_price = exchange_price / from_rate * basic_unit;
                    }
                }

                // 목적지 화폐로 변경한다
                if (TO_CURRENCY != BRANCH_CURRENCY)
                {
                    double to_rate    = 0.0;
                    int    basic_unit = 0;
                    if (CURRENCY_LIST != null && CURRENCY_LIST.Count > 0)
                    {
                        CurrencyModels CURRENCY = CURRENCY_LIST.Find(m => m.RAINBOWCODE == rainbow_code && m.CURRENCY_UNIT == TO_CURRENCY);
                        if (CURRENCY != null && CURRENCY.CURRENCY_UNIT.Length > 0)
                        {
                            to_rate    = CURRENCY.EXCHANGE_RATE;
                            basic_unit = (int)CURRENCY.BASIC_UNIT;
                        }
                    }
                    else
                    {
                        GetExchangeRate(rainbow_code, TO_CURRENCY, ref to_rate, ref basic_unit);
                    }

                    if (to_rate <= 0.0 || basic_unit < 0)
                    {
                        return(price);
                    }

                    if (BRANCH_CURRENCY == "KRW")
                    {
                        exchange_price = exchange_price / to_rate * basic_unit;
                    }
                    else                     //if (BRANCH_CURRENCY == "USD")
                    {
                        exchange_price = exchange_price * to_rate / basic_unit;
                    }
                }
            }

            if (TO_CURRENCY == "KRW")
            {
                exchange_price = Math.Round(exchange_price, 0);
            }
            else             //if (BRANCH_CURRENCY == "USD")
            {
                exchange_price = Math.Round(exchange_price, 2);
            }

            return(exchange_price);
        }
Example #4
0
 public CurrenciesController(ApplicationDbContext context)
 {
     _context       = context;
     currencyModels = new CurrencyModels(_context);
 }