예제 #1
0
        protected void gvUnitTrust_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow    row   = gvUnitTrust.Rows[e.RowIndex];
            string         code  = (gvUnitTrust.DataKeys[e.RowIndex].Value.ToString());
            string         sql   = "delete [UnitTrust] where [code]='" + code + "'";
            SqlTransaction trans = myExternalData.beginTransaction();

            myExternalData.setData(sql, trans);
            myExternalData.commitTransaction(trans);
            Response.Redirect("ManageUnitTrust.aspx");
        }
        protected void gvStock_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row      = gvStock.Rows[e.RowIndex];
            TextBox     txtClose = (TextBox)row.FindControl("txtClose");
            string      code     = (gvStock.DataKeys[e.RowIndex].Value.ToString());
            decimal     close    = Decimal.Parse(txtClose.Text);
            // Upate the close value of the stock.
            string         sql   = "update [Stock] set [close]='" + close + "' where [code]='" + code + "'";
            SqlTransaction trans = myExternalData.beginTransaction();

            myExternalData.setData(sql, trans);
            myExternalData.commitTransaction(trans);
            Response.Redirect("ManageStock.aspx");
        }
예제 #3
0
        protected void gvBondBuyOrder_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            lblBuyMessage.Visible = false;
            // Get the index of the row that was clicked, the order reference number and the bond code.
            int         index           = Convert.ToInt32(e.CommandArgument);
            GridViewRow row             = gvBondBuyOrder.Rows[index];
            int         referenceNumber = Convert.ToInt32(row.Cells[3].Text);
            string      bondCode        = row.Cells[4].Text;

            if (e.CommandName == "ExecuteOrder")
            {
                // Get the buying price and dollar amount to buy, and calculate the number of shares to buy.
                decimal buyPrice;
                if (!decimal.TryParse(((TextBox)row.FindControl("txtExecutedPrice")).Text, out buyPrice) || buyPrice <= 0)
                {
                    showMessage("buy", "The buying price is not valid.", "danger");
                    return;
                }
                decimal buyAmount = Convert.ToDecimal(row.Cells[7].Text.Trim().Replace(",", ""));
                decimal buyShares = Math.Round((convertAmountToBase(bondCode, buyAmount) / buyPrice), 2);
                if (sharesExceedLimit(buyShares))
                {
                    return;
                }

                // Create a transaction for the buy order, change the buy order status to completed, update the security price and refresh the buy orders.
                SqlTransaction trans = myExternalData.beginTransaction();
                myExternalData.setData("insert into [Transaction]([referenceNumber], [executeDate], [executeShares], [executePrice]) values (" +
                                       referenceNumber + ", '" + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "', " + buyShares + ", " + buyPrice + ")", trans);
                myExternalData.setData("update [Order] set [status]='completed' where [referenceNumber]=" + referenceNumber, trans);
                myExternalData.setData("update [Bond] set [price]=" + buyPrice + " where [code]='" + bondCode + "'", trans);
                myExternalData.commitTransaction(trans);
                getBondBuyOrders();
            }

            if (e.CommandName == "GetPrice")
            {
                string currentPrice = myExternalFunctions.getSecuritiesPrice("bond", bondCode).ToString();
                showMessage("buy", "The current price of bond " + bondCode + " is " + currentPrice + ".", "info");
            }
        }
예제 #4
0
        protected void gvStockBuyOrder_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            lblBuyMessage.Visible = false;
            // Get the index of the row that was clicked, the order reference number and the stock code.
            int         index           = Convert.ToInt32(e.CommandArgument);
            GridViewRow row             = gvStockBuyOrder.Rows[index];
            int         referenceNumber = Convert.ToInt32(row.Cells[6].Text.Trim());
            string      stockCode       = row.Cells[7].Text.Trim();

            if (e.CommandName == "ExecuteOrder")
            {
                // Get required values from the order.
                decimal limitPrice  = 0;
                decimal stopPrice   = 0;
                string  price       = ((System.Web.UI.WebControls.TextBox)row.FindControl("txtExecutePrice")).Text.Trim();
                string  buyAmount   = ((System.Web.UI.WebControls.TextBox)row.FindControl("txtExecuteAmount")).Text.Trim();
                decimal orderAmount = Convert.ToDecimal(row.Cells[9].Text);
                string  orderType   = row.Cells[10].Text.Trim();
                if (orderType == "limit" || orderType == "stop limit")
                {
                    limitPrice = Convert.ToDecimal(row.Cells[13].Text.Trim());
                }
                if (orderType == "stop" || orderType == "stop limit")
                {
                    stopPrice = Convert.ToDecimal(row.Cells[14].Text.Trim());
                }

                // Check if inputs are valid.
                if (!executionIsValid("buy", orderType, price, buyAmount, orderAmount, limitPrice, stopPrice))
                {
                    return;
                }

                // Calculate the number of shares to buy, the number of shares remaining to buy and set the status accordingly.
                decimal buyShares       = Convert.ToDecimal(buyAmount) / Convert.ToDecimal(price);
                decimal remainingAmount = orderAmount - Convert.ToDecimal(buyAmount);
                string  orderStatus     = "partial";
                if (remainingAmount == 0)
                {
                    orderStatus = "completed";
                }

                // Create a transaction for the buy order, change the buy order status, update the security price and refresh the buy orders.
                SqlTransaction trans = myExternalData.beginTransaction();
                myExternalData.setData("insert into [Transaction]([referenceNumber], [executeDate], [executeShares], [executePrice]) values (" +
                                       referenceNumber + ", '" + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "', " + buyShares + ", '" + price + "')", trans);
                myExternalData.setData("update [Order] set [status]='" + orderStatus + "', [amount]=" + remainingAmount + " where [referenceNumber]=" + referenceNumber, trans);
                myExternalData.setData("update [Stock] set [close]='" + price + "' where [code]='" + stockCode + "'", trans);
                myExternalData.commitTransaction(trans);
                getStockBuyOrders();
            }

            if (e.CommandName == "CancelOrder")
            {
                SqlTransaction trans = myExternalData.beginTransaction();
                myExternalData.setData("update [Order] set [status]='cancelled' where [referenceNumber]=" + referenceNumber, trans);
                myExternalData.commitTransaction(trans);
                getStockBuyOrders();
            }

            if (e.CommandName == "GetPrice")
            {
                string currentPrice = myExternalFunctions.getSecuritiesPrice("stock", stockCode).ToString();
                showMessage("buy", "The current price of stock " + stockCode + " is " + currentPrice + ".", "info");
            }
        }