示例#1
0
        protected void Grid_ExchangeRate_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            try
            {
                e.Cancel = true;
                session.BeginTransaction();

                ASPxGridView grid = sender as ASPxGridView;

                ExchangeRate exchangeid     = session.GetObjectByKey <ExchangeRate>(Guid.Parse(e.Keys[0].ToString()));
                object       keyvalue       = grid.GetMasterRowKeyValue();
                CurrencyType currencyTypeid = session.GetObjectByKey <CurrencyType>(Guid.Parse(keyvalue.ToString()));
                NAS.DAL.Accounting.Currency.Currency currencyid = BO.get_Currency_true_master(session, currencyTypeid.CurrencyTypeId.ToString(), true, Utility.Constant.ROWSTATUS_ACTIVE);

                //NAS.DAL.Accounting.Currency.Currency NumeratorCurrencyId = BO.get_CurrencyId_currencyId(session, currencyid.CurrencyId.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                //NAS.DAL.Accounting.Currency.Currency DenomiratorCurrencyId = BO.get_CurrencyId_currencyId(session, Currency_Id.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                //if (!e.NewValues["BankId!Key"].ToString().Equals(e.OldValues["BankId!Key"].ToString()))
                //    if (BO.check_ExchangeRate_BankId(
                //        session,
                //        NumeratorCurrencyId.CurrencyId.ToString(),
                //        DenomiratorCurrencyId.CurrencyId.ToString(),
                //        bankid.BankId.ToString(),
                //        Utility.Constant.ROWSTATUS_ACTIVE
                //        ))
                //    {
                //        throw new Exception(String.Format("Ngân Hàng {0} Trùng, Yêu Cầu Nhập Lại Ngân Hàng", bankid.Code));
                //    }

                exchangeid.AffectedDate = DateTime.Parse(e.NewValues["AffectedDate"].ToString());
                if (e.NewValues["BankId!Key"] != null)
                {
                    Bank bankid = session.GetObjectByKey <Bank>(Guid.Parse(e.NewValues["BankId!Key"].ToString()));
                    if (bankid != null)
                    {
                        exchangeid.BankId.BankId = bankid.BankId;
                        exchangeid.Name          = bankid.Code;
                    }
                }
                exchangeid.Rate = float.Parse(e.NewValues["Rate"].ToString());
                if (e.NewValues["Description"] != null)
                {
                    exchangeid.Description = e.NewValues["Description"].ToString();
                }
                exchangeid.NumeratorCurrencyId   = BO.get_CurrencyId_currencyId(session, currencyid.CurrencyId.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                exchangeid.DenomiratorCurrencyId = BO.get_CurrencyId_currencyId(session, Currency_Id.ToString(), Utility.Constant.ROWSTATUS_ACTIVE);
                exchangeid.Status = short.Parse(e.NewValues["Status"].ToString());
                exchangeid.Save();

                session.CommitTransaction();
                grid.CancelEdit();
                grid.DataBind();
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
        }
示例#2
0
        public ExchangeRates GetExchangeRates(ReqEmpty req)
        {
            ExchangeRates rates = HttpContext.Current.Application["exchangeRates"] as ExchangeRates;

            if (rates == null || rates.Date < Provider.Database.Now.Date)
            {
                rates = new ExchangeRates {
                    Date = Provider.Database.Now.Date
                };

                List <ExchangeRate> list =
                    Provider.Database.ReadList <ExchangeRate>("select * from ExchangeRate where InsertDate>={0}",
                                                              Provider.Database.Now.Date);
                if (list == null || list.Count == 0)
                {
                    XmlTextReader rdr = new XmlTextReader("http://www.tcmb.gov.tr/kurlar/today.xml");
                    DataSet       ds  = new DataSet();
                    ds.ReadXml(rdr);

                    foreach (DataRow dr in ds.Tables["Currency"].Rows)
                    {
                        try
                        {
                            ExchangeRate rate = new ExchangeRate
                            {
                                Currency =
                                    (dr["CurrencyCode"].ToString() == "USD")
                                            ? "$"
                                            : (dr["CurrencyCode"].ToString() == "EUR" ? "€" : dr["CurrencyCode"].ToString()),
                                PriceTL =
                                    Convert.ToInt32(
                                        decimal.Parse(dr["ForexSelling"].ToString(), CultureInfo.InvariantCulture) *
                                        1000000 / int.Parse(dr["Unit"].ToString()))
                            };
                            rate.Save();

                            rates.Add(rate.ToEntityInfo <ExchangeRateInfo>());
                        }
                        catch { }
                    }

                    HttpContext.Current.Application["exchangeRates"] = rates;
                }
                else
                {
                    rates.Date = Provider.Database.Now.Date;
                    rates.AddRange(list.ToEntityInfo <ExchangeRateInfo>());
                    HttpContext.Current.Application["exchangeRates"] = rates;
                }
            }

            return(rates);
        }
示例#3
0
        private static void AddExchangeRate(Currency currency, ICollection <CurrencyPair> collection, StringBuilder errors)
        {
            foreach (var pairCurr in collection.Where(pair => Equals(pair.First, currency)))
            {
                // найдем, есть ли уже недавно запрошенный уровень с такими же
                var firstExchangeRate = Session.GetObjects(Session.GetClassInfo(typeof(ExchangeRate)),
                                                           CriteriaOperator.Parse("[CurrencyPair] = ?", pairCurr.Id),
                                                           new SortingCollection(new SortProperty("Date", SortingDirection.Descending)), 1, false, false)
                                        .Cast <ExchangeRate>().FirstOrDefault();

                if (firstExchangeRate == null || firstExchangeRate.Date.AddHours(1) < DateTime.Now)
                {
                    var tickerContayner =
                        new ExchangeRates.Croptonator.CryptonatorApi().TickerContayner(
                            $"{pairCurr.First.Symbol}-{pairCurr.Second.Symbol}", out var error);

                    if (!string.IsNullOrEmpty(error))
                    {
                        errors.AppendLine(error);
                    }
                    var ticker = tickerContayner?.ticker;

                    if (ticker != null)
                    {
                        var exRate = new ExchangeRate(Session)
                        {
                            CurrencyPair = pairCurr,
                            Date         = DateTime.Now,
                            Rate         = ticker.price
                        };
                        exRate.Save();
                        errors.AppendLine(exRate.ToString());
                    }
                }


                AddExchangeRate(pairCurr.Second, collection, errors);
            }
        }
示例#4
0
 private void UpdateBudgetExchangeRate(int idCurrency, decimal rate)
 {
     try
     {
         object       connManager  = SessionManager.GetConnectionManager(this);
         ExchangeRate exchangeRate = new ExchangeRate(ConnectionManager);
         //Use the year selected in the combo
         exchangeRate.Year       = int.Parse(cmbYear.Items[cmbYear.SelectedIndex].Text);
         exchangeRate.Value      = rate;
         exchangeRate.IdCurrency = idCurrency;
         exchangeRate.IdCategory = ApplicationConstants.ID_EXCHANGE_RATE_FOR_BUDGET;
         exchangeRate.SetModified();
         //save value
         exchangeRate.Save();
         LoadExchangeRates();
         grdExchangeRates.Rebind();
     }
     catch (Exception ex)
     {
         ShowError(new IndException(ex));
     }
 }