Exemplo n.º 1
0
        private void XmlConnector_OnSendUnitesPortfolio(string data)
        {
            UnitedPortfolio portfolio = null;

            Dispatcher.Invoke(() =>
            {
                portfolio =
                    (UnitedPortfolio)
                    new XmlSerializer(typeof(UnitedPortfolio), new XmlRootAttribute("united_portfolio"))
                    .Deserialize(
                        new StringReader(data));
            });

            Dispatcher.Invoke(() =>
            {
                UnitedPortfolioDataGridRows.Add(new UnitedPortfolioDataGridRow()
                {
                    ChrgoffIr  = portfolio.ChrgoffIr,
                    ChrgoffMr  = portfolio.ChrgoffMr,
                    Client     = portfolio.Client,
                    Equity     = portfolio.Equity,
                    Finres     = portfolio.Finres,
                    Go         = portfolio.Go,
                    InitReq    = portfolio.InitReq,
                    MaintReq   = portfolio.MaintReq,
                    OpenEquity = portfolio.OpenEquity,
                    RegEquity  = portfolio.RegEquity,
                    RegIr      = portfolio.RegIr,
                    RegMr      = portfolio.RegMr,
                    Union      = portfolio.Union,
                    Vm         = portfolio.Vm
                });
            });
            Dispatcher.Invoke(() =>
            {
                foreach (var asset in portfolio.Assets)
                {
                    AssetDataGridRowses.Add(new AssetDataGridRow()
                    {
                        Code       = asset.Code,
                        InitReq    = asset.InitReq,
                        MaintReq   = asset.MaintReq,
                        Name       = asset.Name,
                        SetoffRate = asset.SetoffRate
                    });
                    foreach (var security in asset.Securities)
                    {
                        UnitedPortfolioSecurityDataGridRowses.Add(new UnitedPortfolioSecurityDataGridRow()
                        {
                            Balance       = security.Balance,
                            Bought        = security.Bought,
                            Buying        = security.Bought,
                            OpenBalance   = security.OpenBalance,
                            Equity        = security.Equity,
                            Market        = security.Market,
                            Maxbuy        = security.Maxbuy,
                            Maxsell       = security.Maxsell,
                            Pl            = security.Pl,
                            PnlIncome     = security.PnlIncome,
                            Sold          = security.Sold,
                            RegEquity     = security.RegEquity,
                            PnlIntraday   = security.PnlIntraday,
                            Price         = security.Price,
                            ReserateLong  = security.ReserateLong,
                            ReserateShort = security.ReserateShort,
                            RiskrateLong  = security.RiskrateLong,
                            RiskrateShort = security.RiskrateShort,
                            Seccode       = security.Seccode,
                            Secid         = security.Secid,
                            Selling       = security.Selling
                        });
                        foreach (var valuePart in security.ValueParts)
                        {
                            ValuePartDataGridRowses.Add(new ValuePartDataGridRow()
                            {
                                Balance     = valuePart.Balance,
                                Bought      = valuePart.Bought,
                                OpenBalance = valuePart.OpenBalance,
                                Register    = valuePart.Register,
                                Settled     = valuePart.Settled,
                                Sold        = valuePart.Sold
                            });
                        }
                    }
                }
            });
            Dispatcher.Invoke(() =>
            {
                foreach (var money in portfolio.Money)
                {
                    MoneyDataGridRowses.Add(new MoneyDataGridRow()
                    {
                        Balance     = money.Balance,
                        Bought      = money.Bought,
                        Name        = money.Name,
                        OpenBalance = money.OpenBalance,
                        Settled     = money.Settled,
                        Sold        = money.Sold,
                        Tax         = money.Tax
                    });
                    foreach (var valuePart in money.ValueParts)
                    {
                        ValuePartDataGridRowses.Add(new ValuePartDataGridRow()
                        {
                            Balance     = valuePart.Balance,
                            Bought      = valuePart.Bought,
                            OpenBalance = valuePart.OpenBalance,
                            Register    = valuePart.Register,
                            Settled     = valuePart.Settled,
                            Sold        = valuePart.Sold
                        });
                    }
                }
            });
            TXmlConnector.SendNewUnitedPortfolio -= XmlConnector_OnSendUnitesPortfolio;
        }
Exemplo n.º 2
0
        private void XmlConnector_OnSendUnitesPortfolio(string data)
        {
            //Dispatcher.Invoke(() => {
            //    AssetDataGridRowses.Clear();
            //    MoneyDataGridRowses.Clear();
            //    ValuePartDataGridRowses.Clear();
            //});
            UnitedPortfolio portfolio;

            using (var stringReader = new StringReader(data))
            {
                portfolio = (UnitedPortfolio)
                            _serializer.Deserialize(stringReader);
            }
            var upRow = new UnitedPortfolioDataGridRow
            {
                ChrgoffIr  = portfolio.ChrgoffIr,
                ChrgoffMr  = portfolio.ChrgoffMr,
                Client     = portfolio.Client,
                Equity     = portfolio.Equity,
                Finres     = portfolio.Finres,
                Go         = portfolio.Go,
                InitReq    = portfolio.InitReq,
                MaintReq   = portfolio.MaintReq,
                OpenEquity = portfolio.OpenEquity,
                RegEquity  = portfolio.RegEquity,
                RegIr      = portfolio.RegIr,
                RegMr      = portfolio.RegMr,
                Union      = portfolio.Union,
                Vm         = portfolio.Vm
            };

            if (UnitedPortfolioDataGridRows.Count == 0)
            {
                Dispatcher.Invoke(() => UnitedPortfolioDataGridRows.Add(upRow));
            }
            else
            {
                Dispatcher.Invoke(() => UnitedPortfolioDataGridRows[0] = upRow);
            }
            foreach (var asset in portfolio.Assets)
            {
                //AssetDataGridRowses.Add(new AssetDataGridRow
                //{
                //    Code = asset.Code,
                //    InitReq = asset.InitReq,
                //    MaintReq = asset.MaintReq,
                //    Name = asset.Name,
                //    SetoffRate = asset.SetoffRate
                //});
                foreach (var security in asset.Securities)
                {
                    var UPSrow = new UnitedPortfolioSecurityDataGridRow
                    {
                        Balance       = security.Balance,
                        Bought        = security.Bought,
                        Buying        = security.Bought,
                        OpenBalance   = security.OpenBalance,
                        Equity        = security.Equity,
                        Market        = security.Market,
                        Maxbuy        = security.Maxbuy,
                        Maxsell       = security.Maxsell,
                        Pl            = security.Pl,
                        PnlIncome     = security.PnlIncome,
                        Sold          = security.Sold,
                        RegEquity     = security.RegEquity,
                        PnlIntraday   = security.PnlIntraday,
                        Price         = security.Price,
                        ReserateLong  = security.ReserateLong,
                        ReserateShort = security.ReserateShort,
                        RiskrateLong  = security.RiskrateLong,
                        RiskrateShort = security.RiskrateShort,
                        Seccode       = security.Seccode,
                        Secid         = security.Secid,
                        Selling       = security.Selling
                    };
                    if (!UnitedPortfolioSecurityDataGridRowses.Select(x => x.Seccode).Contains(UPSrow.Seccode))
                    {
                        Dispatcher.Invoke(() => UnitedPortfolioSecurityDataGridRowses.Add(UPSrow));
                    }
                    else
                    {
                        Dispatcher.Invoke(() =>
                                          UnitedPortfolioSecurityDataGridRowses[
                                              UnitedPortfolioSecurityDataGridRowses.IndexOf(
                                                  UnitedPortfolioSecurityDataGridRowses.First(x => x.Seccode == UPSrow.Seccode))] = UPSrow);
                    }
                    TotalBalance = UnitedPortfolioSecurityDataGridRowses.Sum(r => r.Pl);

                    //foreach (var valuePart in security.ValueParts)
                    //{
                    //    ValuePartDataGridRowses.Add(new ValuePartDataGridRow
                    //    {
                    //        Balance = valuePart.Balance,
                    //        Bought = valuePart.Bought,
                    //        OpenBalance = valuePart.OpenBalance,
                    //        Register = valuePart.Register,
                    //        Settled = valuePart.Settled,
                    //        Sold = valuePart.Sold
                    //    });
                    //}
                }
            }
            foreach (var money in portfolio.Money)
            {
                var Mrow = new MoneyDataGridRow
                {
                    Balance     = money.Balance,
                    Bought      = money.Bought,
                    Name        = money.Name,
                    OpenBalance = money.OpenBalance,
                    Settled     = money.Settled,
                    Sold        = money.Sold,
                    Tax         = money.Tax
                };
                if (!MoneyDataGridRowses.Select(x => x.Name).Contains(Mrow.Name))
                {
                    Dispatcher.Invoke(() => MoneyDataGridRowses.Add(Mrow));
                }
                else
                {
                    Dispatcher.Invoke(() => MoneyDataGridRowses[
                                          MoneyDataGridRowses.IndexOf(
                                              MoneyDataGridRowses.First(x => x.Name == Mrow.Name))] = Mrow);
                }
                //foreach (var valuePart in money.ValueParts)
                //{
                //    ValuePartDataGridRowses.Add(new ValuePartDataGridRow
                //    {
                //        Balance = valuePart.Balance,
                //        Bought = valuePart.Bought,
                //        OpenBalance = valuePart.OpenBalance,
                //        Register = valuePart.Register,
                //        Settled = valuePart.Settled,
                //        Sold = valuePart.Sold
                //    });
                //}
            }
            //send realtime balance to the server
            SendBalanceToInsideServer();
        }