Esempio n. 1
0
    private void ParseRowCommand(GridView view, GridViewCommandEventArgs e)
    {
        //We want to obey OnSort and OnChart events
        string[] commands = new string[1] {
            "buy"
        };

        if (commands.Contains(e.CommandName))
        {
            int         index = e.GetSelectedRowIndex() % view.PageSize;
            GridViewRow row   = view.Rows[index];
            string      Id    = (row.Cells[0].Text.Trim());

            var    Auction = new ShareOnMarket(Convert.ToInt32(Id));
            Member User    = Member.Current;

            if (e.CommandName == "buy")
            {
                SPanel.Visible = false;
                EPanel.Visible = false;
                try
                {
                    Money PriceWithFee = SharesMarketManager.CalculatePriceWithFee(Auction.Price);

                    //Balance check
                    if (PriceWithFee > User.MainBalance)
                    {
                        throw new MsgException(L1.NOTENOUGHFUNDS);
                    }

                    //Take money
                    User.SubtractFromMainBalance(PriceWithFee, "Sh. Market buy");
                    User.SaveBalances();

                    //Sell shares
                    SharesMarketManager.SellShare(Auction, User);

                    SPanel.Visible = true;
                    SText.Text     = U4000.SHARESSUCC;
                }
                catch (MsgException ex)
                {
                    EPanel.Visible = true;
                    EText.Text     = ex.Message;
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                    throw ex;
                }
            }
        }
    }
Esempio n. 2
0
    protected void AuctionGrid1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ShareOnMarket Share = new ShareOnMarket(Convert.ToInt32(e.Row.Cells[0].Text));

            // 3 - Portfolio Product
            // 5 - Price WITH FEE

            PortfolioProduct Product = new PortfolioProduct(Share.PortfolioProductId);

            e.Row.Cells[3].Text = "<a href=\"products.aspx?id=" + Product.Id + "\">" + Product.Name + "</a>";
            e.Row.Cells[5].Text = SharesMarketManager.CalculatePriceWithFee(Share.Price).ToString();

            ((LiteralControl)e.Row.Cells[6].Controls[2]).Text = " " + L1.BUY;
        }
    }