public static RealizedPLData Create(DataRow dr)
 {
     RealizedPLData data = new RealizedPLData();
     CreateHelper(dr, data);
     data.EquvAmount = dr.EscapeDBNULL<decimal>("TradePLValued");
     data.MonthlyChangeRate = data.ExchangeRate;
     data.OriginAmount = data.EquvAmount / data.ExchangeRate;
     data.Type = BusinessTypeEnum.RealizedPL;
     data.ProductName = dr.EscapeDBNULL<string>("ProductName");
     return data;
 }
        public static FloatingPLData Create(DataRow dr)
        {
            FloatingPLData data = new FloatingPLData();
            CreateHelper(dr, data);

            data.EquvAmount = dr.EscapeDBNULL<decimal>("TradePLFloat");
            data.MonthlyChangeRate = data.ExchangeRate;
            data.OriginAmount = data.EquvAmount / data.ExchangeRate;
            data.Type = BusinessTypeEnum.FloatingPL;
            data.ProductName = dr.EscapeDBNULL<string>("ProductName");
            data.AskPrice = dr.EscapeDBNULL<string>("Ask");
            data.BidPrice = dr.EscapeDBNULL<string>("Bid");
            data.TradingAmount = dr.EscapeDBNULL<decimal>("TradingAmount");
            InitializeBeforeData(data, dr);
            return data;
        }
        private static void InitializeBeforeData(FloatingPLData data,DataRow dr)
        {
            data.LastFloatingPLData = new FloatingPLData();
            var lastPL = data.LastFloatingPLData;
            lastPL.Type = data.Type;
            lastPL.FromMt4LoginID = data.FromMt4LoginID;
            lastPL.ToMt4LoginID = data.ToMt4LoginID;
            lastPL.CurrencyCode = data.CurrencyCode;

            if (dr["BfAccountingCurrencyRate"] == DBNull.Value)
            {
                throw new ArgumentNullException("BfAccountingCurrencyRate");
            }
            lastPL.ExchangeRate = (decimal)dr.EscapeDBNULL<double>("BfAccountingCurrencyRate");
            lastPL.EquvAmount = dr.EscapeDBNULL<decimal>("BfTradePLFloat");
            lastPL.MonthlyChangeRate = lastPL.ExchangeRate;
            lastPL.OriginAmount = lastPL.EquvAmount / lastPL.ExchangeRate;
            lastPL.TradingAmount = dr.EscapeDBNULL<decimal>("BfTradingAmount");
            lastPL.AskPrice = dr.EscapeDBNULL<string>("BfAsk");
            lastPL.BidPrice = dr.EscapeDBNULL<string>("BfBid");

            lastPL.ProductName = data.ProductName;

        }
 protected static void CreateHelper(DataRow dr, PLData data)
 {
     data.FromMt4LoginID = dr.EscapeDBNULL<int>("MT4LoginId").ToString();
     if (dr["AccountingMappingCode"] == DBNull.Value)
     {
         throw new ArgumentNullException("AccountingMappingCode");
     }
     data.ToMt4LoginID = dr.EscapeDBNULL<int>("AccountingMappingCode").ToString();
     data.CurrencyCode = dr.EscapeDBNULL<string>("AccountingCurrencyName");
     if (dr["AccountingCurrencyRate"] == DBNull.Value)
     {
         throw new ArgumentNullException("AccountingCurrencyRate");
     }
     data.ExchangeRate = (decimal)dr.EscapeDBNULL<double>("AccountingCurrencyRate");
     var otherPlData = data as InterestStorageLevyCommisionPLData;
     if (otherPlData != null)
     {
         otherPlData.CustomerCode = dr.EscapeDBNULL<string>("CustomerCode");
         otherPlData.CustomerName = dr.EscapeDBNULL<string>("CustomerDesc");
         otherPlData.ProductName = dr.EscapeDBNULL<string>("ProductName");
     }
 }
        private DepositData Fill(DataRow dr, string baseCurrencyName, BusinessTypeEnum businessType)
        {
            DepositData data = new DepositData();
            data.Type = dr.EscapeDBNULL<int>("Type");
            data.AccountCode = dr.EscapeDBNULL<string>("AccountCode");
            data.MT4Code = dr.EscapeDBNULL<int>("MT4LoginId").ToString();
            data.TransactionNo = dr.EscapeDBNULL<string>("Code");
            data.SourceCustomerCode = dr.EscapeDBNULL<string>("CustomerCode");
            data.SourceCustomerName = dr.EscapeDBNULL<string>("CustomerName");
            data.SourceCustomerAliasCode = dr.EscapeDBNULL<string>("CustomerAlias");

            data.AccountingDesription = dr.EscapeDBNULL<string>("AccountingDesription");
            data.SourceAmount = dr.EscapeDBNULL<decimal>("TargetAmount");
            data.SourceCurrency = dr.EscapeDBNULL<Guid>("TargetCurrencyID");
            data.UpdateTime = dr.EscapeDBNULL<DateTime>("UpdateTime");
            data.MarginReference = dr.EscapeDBNULL<long>("MarginReference");

            if (dr["iExchangeCurrencyName"] == DBNull.Value) return null;
            data.SourceCurrencyName = dr.EscapeDBNULL<string>("iExchangeCurrencyName");
            if (dr["iExchangeCurrencyRate"] == DBNull.Value) return null;
            data.SourceCurrencyRate = (decimal)(dr.EscapeDBNULL<double>("iExchangeCurrencyRate"));
            if (businessType == BusinessTypeEnum.Withdraw || businessType == BusinessTypeEnum.Deposit)
            {
                data.BankName = dr.EscapeDBNULL<string>("BankName");
                data.AccountName = dr.EscapeDBNULL<string>("AccountName");
                data.BankCode = dr.EscapeDBNULL<string>("BankCode");
                if (dr["BankCurrencyRate"] == DBNull.Value) return null;
                if (dr["BankCurrencyName"] == DBNull.Value) return null;
                if (dr["BankMt4LoginId"] == DBNull.Value) return null;
                if (dr["BankCurrencyId"] == DBNull.Value) return null;
                data.TargetMt4 = dr.EscapeDBNULL<int>("BankMt4LoginId").ToString();
                data.TargetAmount = dr.EscapeDBNULL<decimal>("AmountRecevided");
                data.TargetCurrency = dr.EscapeDBNULL<Guid>("BankCurrencyId");
                data.TargetCurrencyRate = (decimal)(dr.EscapeDBNULL<double>("BankCurrencyRate"));
                data.TargetCurrencyName = dr.EscapeDBNULL<string>("BankCurrencyName");
                if (data.SourceCurrency != data.TargetCurrency)
                {
                    if (dr["DayTradeRate1"] == DBNull.Value || dr["DayTradeRate2"] == DBNull.Value)
                    {
                        return null;
                    }
                    var dtr1 = dr.EscapeDBNULL<double>("DayTradeRate1");
                    var dtr2 = dr.EscapeDBNULL<double>("DayTradeRate2");
                    data.DayTradeRate = Math.Max(dtr1, dtr2);
                }
            }
            int? iExchangePlAccount = this._AccountService.GetExchangePlAccount();
            if (iExchangePlAccount == null) return null;
            data.iExchangePlMT4LoginID = iExchangePlAccount.Value.ToString();
            data.BaseCurrencyName = baseCurrencyName;
            return data;
        }