Exemple #1
0
        //买入按钮
        private void btn_submit_Click(object sender, EventArgs e)
        {
            if (this.buy_quantity == 0)
            {
                MessageBox.Show("请输入购买数量!");
                return;
            }
            if (!this.isCanBuy)
            {
                MessageBox.Show("请输入有效的A股代码!");
                return;
            }
            //MessageBox.Show(string.Format("买入价格:{0}, 买入数量:{1}",this.buy_price,this.buy_quantity));

            //生成买入的委托记录
            Commission model = new Commission();

            model.hold_stock_info   = this.hold_stock_info_select;
            model.commission_price  = this.buy_price;
            model.commission_amount = this.buy_quantity;
            // 1.买入 2. 卖出
            model.direction = 1;
            // 状态:1.已撤销 2.已成交 3.已提交(默认值)
            model.state          = 3;
            model.remain         = this.buy_quantity;
            model.stockholder_id = Utility.user.id;

            if (this.hold_stock_info_select == null)
            {
                //生成持有股票记录 (数据库中无持有此股票)
                Hold_Stock_Info holdStockInfo = new Hold_Stock_Info();
                holdStockInfo.stock_name      = this.stock_name;
                holdStockInfo.stock_code      = this.stock_code;
                holdStockInfo.amount_useable  = 0;
                holdStockInfo.hold_quantity   = this.buy_quantity;
                holdStockInfo.cost_price      = this.buy_price * this.buy_quantity;
                holdStockInfo.stock_holder_id = Utility.user.id;
                holdStockInfo.type            = 1; // 1. 持有股 2. 自选股
                commissionService.AddCommission(model, holdStockInfo);

                //委托交易成功后,减少 bankroll的金额 cost_price
                //TODO
            }
            else
            {
                commissionService.AddCommission(model, this.hold_stock_info_select);

                hold_stock_infoService.UpdateAmountUseableBuy(this.buy_quantity, this.buy_price, this.hold_stock_info_select);
                //委托交易成功后,减少 bankroll的金额
                //TODO
            }

            this.DialogResult = DialogResult.OK;
            //关闭窗口
            this.Close();
        }
Exemple #2
0
        //卖出按钮
        private void btn_submit_Click(object sender, EventArgs e)
        {
            if (this.sell_quantity == 0)
            {
                MessageBox.Show("请输入卖出数量!");
                return;
            }

            if (this.canSell == 0)
            {
                MessageBox.Show("当前股票可用股票为0不可卖出!");
                return;
            }

            if (this.sell_quantity > this.canSell)
            {
                this.sell_quantity = 100;
                this.numericUpDown_sell_quantity.Value = 100;
                MessageBox.Show("卖出数量不能超过可买数量!");
                return;
            }

            //MessageBox.Show(string.Format("卖出价格:{0}, 卖出数量:{1}", this.sell_price, this.sell_quantity));

            //生成卖出的委托记录
            Commission model = new Commission();

            model.hold_stock_info   = this.hold_stock_info_select;
            model.commission_price  = this.sell_price;
            model.commission_amount = this.sell_quantity;
            // 1.买入 2. 卖出
            model.direction = 2;
            // 状态:1.已撤销 2.已成交 3.已提交(默认值)
            model.state          = 3;
            model.remain         = this.sell_quantity;
            model.stockholder_id = Utility.user.id;

            commissionService.AddCommission(model);
            hold_stock_infoService.UpdateAmountUseable(this.hold_stock_info_select.amount_useable - this.sell_quantity, this.hold_stock_info_select);
            //委托交易成功后,增加 bankroll_freezed的金额

            this.DialogResult = DialogResult.OK;
            //关闭窗口
            this.Close();
        }