Esempio n. 1
0
        //验证用户密码
        public Stock_Holder verifyPassword(string username, string password)
        {
            string sql = "select * from t_stock_holder where username = @username and password = @password limit 1";
            List <MySqlParameter> Paramter = new List <MySqlParameter>();

            Paramter.Add(new MySqlParameter("@username", username));
            Paramter.Add(new MySqlParameter("@password", password));

            DataTable dt = DBHelperSQL.Ins.ExcuteDataTable(sql, Paramter.ToArray());

            if (dt.Rows.Count > 0)
            {
                var list = DataConvert <Stock_Holder> .ToList(dt);

                //根据ID获取所有的用户信息
                //TODO
                Stock_Holder result = getStockHoderByID(list[0].id);
                return(result);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        //定时获取上证指数等信息
        private void query(string stock_code)
        {
            string stock_data_content;                                                    //股票数据内容

            WebRequest req = WebRequest.Create("http://hq.sinajs.cn/list=" + stock_code); //上证指数

            WebResponse resp = req.GetResponse();

            Stream stream = resp.GetResponseStream();

            StreamReader streamReader = new StreamReader(stream, Encoding.Default);

            stock_data_content = streamReader.ReadToEnd();

            //股票数据
            string stock_data = stock_data_content.Substring(stock_data_content.IndexOf("\"") + 1, (stock_data_content.LastIndexOf("\"") - stock_data_content.IndexOf("\"") - 1));

            string[] divide = new string[] { "," };
            string[] divide_result;

            divide_result = stock_data.Split(divide, StringSplitOptions.None);

            if (divide_result.Length != 33)
            {
                //MessageBox.Show("数据信息获取错误,请输入正确的上证代码!");
                return;
            }

            this.时间标签.Text = divide_result[30] + " " + divide_result[31];
            //买
            this.sell_1.Text       = divide_result[10];
            this.sell_1_price.Text = divide_result[11];

            this.sell_2.Text       = divide_result[12];
            this.sell_2_price.Text = divide_result[13];

            this.sell_3.Text       = divide_result[14];
            this.sell_3_price.Text = divide_result[15];

            this.sell_4.Text       = divide_result[16];
            this.sell_4_price.Text = divide_result[17];

            this.sell_5.Text       = divide_result[18];
            this.sell_5_price.Text = divide_result[19];

            this.涨跌标签.Text = "涨跌:" + (double.Parse(divide_result[3]) - double.Parse(divide_result[2])).ToString("f2");
            if (double.Parse(divide_result[3]) >= double.Parse(divide_result[2]))
            {
                this.涨跌标签.ForeColor = Color.Red;
            }
            else
            {
                this.涨跌标签.ForeColor = Color.Chartreuse;
            }
            this.lab_stock_name.Text = divide_result[0];

            //计算可买股票数量
            int          stock_id = Utility.user.id;
            Stock_Holder sh       = stock_HolderService.getStockHolder(stock_id);

            double bankroll_useable = sh.account.bankroll_useable;

            this.current_price = double.Parse(divide_result[3]);
            this.sell_price    = double.Parse(divide_result[3]);

            //可以卖的股票数量
            var datalist = sh.HoldStockInfo.Where(hsi => hsi.stock_code.Equals(stock_code)).ToList();

            this.hold_stock_info_select = datalist[0];
            this.canSell = hold_stock_info_select.amount_useable;

            this.lab_cansell.Text = canSell.ToString();
            this.btn_max.Enabled  = true;

            //买入的默认价格
            this.numericUpDown_sell_price.Value = Convert.ToDecimal(divide_result[3]);

            this.lab_get_money.Text = Convert.ToDouble(current_price * sell_quantity).ToString();
        }
Esempio n. 3
0
        //ListView 窗口数据绑定(持有股票信息)
        private void DataBinding_Stock_Holder()
        {
            Stock_Holder sh = stock_HolderService.getStockHolder(Utility.user.id);

            if (sh.HoldStockInfo == null)
            {
                return;
            }
            //持有股票信息
            listView1.Items.Clear();
            string tempString;

            double stockTotalAssets = 0;            //持有股票总价值
            double lossProfit       = 0;            //盈亏
            double lossProfitPer    = 0;            //盈亏百分比

            foreach (Hold_Stock_Info item in sh.HoldStockInfo)
            {
                ListViewItem Lvitem = new ListViewItem(item.stock_name);
                Lvitem.SubItems.Add(item.stock_code);
                Lvitem.SubItems.Add(item.amount_useable.ToString());
                Lvitem.SubItems.Add(item.hold_quantity.ToString());
                Lvitem.SubItems.Add(item.market_price.ToString());
                //计算持有股票总价值
                stockTotalAssets += item.market_price;
                Lvitem.SubItems.Add(item.profit_loss.ToString());
                //计算总盈亏
                lossProfit += item.profit_loss;
                Lvitem.SubItems.Add(item.profit_loss_per.ToString("f2"));
                //计算总盈亏百分比
                lossProfitPer += item.profit_loss_per;
                Lvitem.SubItems.Add(item.current_price.ToString("f2"));
                Lvitem.SubItems.Add(item.cost_price.ToString());

                if (item.tactics != null && item.tactics.profit_tactics == 1)
                {
                    //上涨减仓
                    tempString = string.Format("上涨{0}%,卖出{1}股", item.tactics.profit_per, item.tactics.profit_quantity);
                }
                else if (item.tactics != null && item.tactics.profit_tactics == 2)
                {
                    //上涨加仓
                    tempString = string.Format("上涨{0}%,买入{1}股", item.tactics.profit_per, item.tactics.profit_quantity);
                }
                else if (item.tactics.profit_tactics == 3)
                {
                    tempString = string.Format("涨停买入,买入{0}股", item.tactics.profit_quantity);
                }
                else if (item.tactics.profit_tactics == 4)
                {
                    tempString = string.Format("涨停卖出,卖出{0}股", item.tactics.profit_quantity);
                }
                else if (item.tactics.profit_tactics == 5)
                {
                    tempString = string.Format("转折点卖出,卖出{0}股", item.tactics.profit_quantity);
                }
                else if (item.tactics.profit_tactics == 6)
                {
                    tempString = string.Format("转折点买入,买入{0}股", item.tactics.profit_quantity);
                }
                else
                {
                    tempString = string.Format(" ");
                }

                Lvitem.SubItems.Add(tempString);

                if (item.tactics != null && item.tactics.loss_tactics == 1 && item.tactics.loss_per != 0)
                {
                    //下跌减仓
                    tempString = string.Format("下跌{0}%,卖出{1}股", item.tactics.loss_per, item.tactics.loss_quantity);
                }
                else if (item.tactics != null && item.tactics.loss_tactics == 2 && item.tactics.loss_per != 0)
                {
                    //下跌加仓
                    tempString = string.Format("下跌{0}%,买入{1}股", item.tactics.loss_per, item.tactics.loss_quantity);
                }
                else if (item.tactics.loss_tactics == 3)
                {
                    tempString = string.Format("跌停卖出,卖出{0}股", item.tactics.loss_quantity);
                }
                else if (item.tactics.loss_tactics == 4)
                {
                    tempString = string.Format("跌停买入,买入{0}股", item.tactics.loss_quantity);
                }
                else if (item.tactics.loss_tactics == 5)
                {
                    tempString = string.Format("转折点买入,买入{0}股", item.tactics.loss_quantity);
                }
                else if (item.tactics.loss_tactics == 6)
                {
                    tempString = string.Format("转折点卖出,卖出{0}股", item.tactics.loss_quantity);
                }
                else
                {
                    tempString = string.Format(" ");
                }

                Lvitem.SubItems.Add(tempString);
                Lvitem.SubItems.Add("无");
                Lvitem.Tag = item.id;       //id 标识

                listView1.Items.Add(Lvitem);

                Lvitem.UseItemStyleForSubItems = false;

                if (item.profit_loss > 0)
                {
                    Lvitem.SubItems[5].ForeColor = Color.Red;
                    Lvitem.SubItems[6].ForeColor = Color.Red;
                }
                else if (item.profit_loss < 0)
                {
                    Lvitem.SubItems[5].ForeColor = Color.Green;
                    Lvitem.SubItems[6].ForeColor = Color.Green;
                }
            }

            // 持有股票汇总
            ListViewItem LvitemCount = new ListViewItem("汇总:");

            LvitemCount.BackColor = Color.Orange;

            LvitemCount.SubItems.Add(" ");
            LvitemCount.SubItems.Add(" ");
            LvitemCount.SubItems.Add(" ");
            LvitemCount.SubItems.Add("总盈亏:");
            if (lossProfit > 0)
            {
                LvitemCount.SubItems.Add("+" + lossProfit.ToString());
                LvitemCount.SubItems.Add("+" + lossProfitPer.ToString() + "%");
            }
            else if (lossProfit < 0)
            {
                LvitemCount.SubItems.Add("-" + lossProfit.ToString());
                LvitemCount.SubItems.Add("-" + lossProfitPer.ToString() + "%");
            }
            else
            {
                LvitemCount.SubItems.Add(lossProfit.ToString());
                LvitemCount.SubItems.Add(lossProfitPer.ToString() + "%");
            }

            LvitemCount.SubItems.Add(" ");
            LvitemCount.SubItems.Add(" ");
            LvitemCount.SubItems.Add("股票总值:¥" + stockTotalAssets);
            LvitemCount.SubItems.Add("持有股票数量:" + sh.HoldStockInfo.Count().ToString());
            this.CountStockAssets = stockTotalAssets;

            listView1.Items.Add(LvitemCount);

            this.listView1.Focus();
            this.listView1.Items[SelectedIndices].Selected = true;
        }