Beispiel #1
0
        /// <summary>
        /// 自选股增加功能101
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddStockbt_Click(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();
            string stkcode = stockntb.Text;
            Stock_Index si = new Stock_Index();

            //校验是否重复
            foreach (string s in CfgStruct.lns)
            {
                string _stkcode = s.Split(' ')[0];
                if (_stkcode == stkcode)
                {
                    MessageBox.Show("自选股列表存在该股票,请勿重复添加");
                    return;
                }
            }
            //校验stkcode
            if (!gc.stock_checkout(stkcode, ref si))
            {
                MessageBox.Show("e-101001股票代码有误");
                //stockntb.Text = "";
                return;
            }

            if(!gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stkcode, FlagDef.ADD))
            {
                MessageBox.Show("e-101002向数据库增加个股失败");
                return;
            }

            RefreshOptionlist();
            stockntb.Text = "";
            stockntb.Focus();
        }
Beispiel #2
0
        //拼接股票URL
        private void stock_appendurl(string stock, ref string stockurl, string url, bool ispicture)
        {
            GeneralClass gc   = new GeneralClass();
            string       head = stock.Substring(0, 2);
            Stock_Index  si   = new Stock_Index();

            if (!gc.stock_checkout(stock, ref si))
            {
                return;
            }

            StringBuilder s = new StringBuilder(url);

            switch (si.market)
            {
            case FlagDef.SH:     //上海
                s.Append("sh");
                break;

            case FlagDef.SZ:     //深证
                s.Append("sz");
                break;

            default:
                return;
            }

            s.Append(stock);
            if (ispicture)
            {
                s.Append(".gif");
            }

            stockurl = s.ToString();
        }
Beispiel #3
0
        /// <summary>
        /// 自选股删除功能102
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteStockbt_Click(object sender, EventArgs e)
        {
            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
            string            sdel       = "确定要删除" + CfgStruct.stockcur + "吗?";
            DialogResult      dr         = MessageBox.Show(sdel, "删除确定", messButton);

            if (dr == DialogResult.Cancel)  //如果点击“Cancel”按钮
            {
                return;
            }

            GeneralClass gc      = new GeneralClass();
            string       stkcode = stockntb.Text;
            Stock_Index  si      = new Stock_Index();

            //校验stkcode
            if (!gc.stock_checkout(stkcode, ref si))
            {
                MessageBox.Show("e-102001股票代码有误");
                //stockntb.Text = "";
                return;
            }

            //在数据库中删除
            if (!gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stkcode, FlagDef.REMOVE))
            {
                MessageBox.Show("e-102002向数据库删除个股失败");
                return;
            }

            RefreshOptionlist();
            stockntb.SelectAll();
            stockntb.Focus();
        }
Beispiel #4
0
        /// <summary>
        /// 自选股增加功能101
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddStockbt_Click(object sender, EventArgs e)
        {
            GeneralClass gc      = new GeneralClass();
            string       stkcode = stockntb.Text;
            Stock_Index  si      = new Stock_Index();

            //校验是否重复
            foreach (string s in CfgStruct.lns)
            {
                string _stkcode = s.Split(' ')[0];
                if (_stkcode == stkcode)
                {
                    MessageBox.Show("自选股列表存在该股票,请勿重复添加");
                    return;
                }
            }
            //校验stkcode
            if (!gc.stock_checkout(stkcode, ref si))
            {
                MessageBox.Show("e-101001股票代码有误");
                //stockntb.Text = "";
                return;
            }

            if (!gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stkcode, FlagDef.ADD))
            {
                MessageBox.Show("e-101002向数据库增加个股失败");
                return;
            }

            RefreshOptionlist();
            stockntb.Text = "";
            stockntb.Focus();
        }
Beispiel #5
0
        /// <summary>
        /// 选中个股功能100
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void optionallist_SelectedIndexChanged(object sender, EventArgs e)
        {
            string stockget = optionallist.Text.Split(' ')[0];

            Stock_Index  si = new Stock_Index();
            GeneralClass gc = new GeneralClass();

            //检验股票代码是否正确
            if (!gc.stock_checkout(stockget, ref si))
            {
                gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stockget, FlagDef.REMOVE);
                MessageBox.Show("e-100001股票代码不正确,已删除.");
                return;
            }

            stockntb.Text      = stockget;
            CfgStruct.stockcur = stockget;
            lb_syssem.Items.Clear();

            string showstock = "当前选择:" + si.stockname;

            lb_syssem.Items.Add(showstock);

            //实时行情获取
            Cycle_stockmarket(sender, e);
        }
Beispiel #6
0
        /// <summary>
        ///下载历史数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void getstockdatabt_Click(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            statusl.Text = "Download " + AdvStock.mystock + "……";
            string stkcode = AdvStock.mystock;
            if (!gc.downloadstockdata(stkcode))
                statusl.Text = "Download " + AdvStock.mystock + ".csv" + " Failed";
            else
                statusl.Text = "Download " + AdvStock.mystock + ".csv" + " Successed";
        }
Beispiel #7
0
        /// <summary>
        ///股票代码检查
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stockntb_TextChanged(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            if (!gc.IsInt(stockntb.Text))
            {
                MessageBox.Show("Please input stock code!", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                stockntb.SelectAll();
                stockntb.Focus();
                return;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 股票输入框检验,限定为数字
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stockntb_TextChanged(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            if (!gc.IsInt(stockntb.Text))
            {
                MessageBox.Show("应该是一个数字", "数据输入错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                stockntb.SelectAll();
                stockntb.Focus();
                return;
            }
        }
Beispiel #9
0
        /// <summary>
        ///下载历史数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void getstockdatabt_Click(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            statusl.Text = "Download " + AdvStock.mystock + "……";
            string stkcode = AdvStock.mystock;

            if (!gc.downloadstockdata(stkcode))
            {
                statusl.Text = "Download " + AdvStock.mystock + ".csv" + " Failed";
            }
            else
            {
                statusl.Text = "Download " + AdvStock.mystock + ".csv" + " Successed";
            }
        }
Beispiel #10
0
        /// <summary>
        /// 获取股票代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void okbutton_Click(object sender, EventArgs e)
        {
            GeneralClass gc       = new GeneralClass();
            string       stockget = stockntb.Text;
            Stock_Index  si       = new Stock_Index();

            if (gc.stock_checkout(stockget, ref si))
            {
                AdvStock.mystock   = stockget;
                statusl.Text       = AdvStock.mystock + " Get";
                currentstockl.Text = si.stockname;
            }
            else
            {
                MessageBox.Show("Error: " + stockget + " is not a stock code.");
            }
        }
Beispiel #11
0
        /// <summary>
        /// 下载历史数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_dlstockdata_Click(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            lb_syssem.Items.Clear();

            int iTotal   = 0;
            int iSuccess = 0;
            int nthread  = CfgStruct.lns.Count;

            Thread[] tds = new Thread[nthread];
            string[] msg = new string[nthread + 1];

            foreach (string stkcode in CfgStruct.lns)
            {
                gc.Stkcode  = stkcode;
                tds[iTotal] = new Thread(new ThreadStart(delegate()
                {
                    gc.downloadstockdata(msg[iTotal]);
                }));
                ++iTotal;
            }
            foreach (Thread t in tds)
            {
                t.Start();
                ++iSuccess;
            }

            lbstatusdl.Text = iSuccess.ToString();
            //    if (!gc.downloadstockdata(stkcode))
            //    {
            //        //提示
            //        msg = stkcode + "下载失败。";
            //        ++iSuccess;
            //    }
            //    else
            //        msg = stkcode + "下载成功。";

            //    lb_syssem.Items.Add(msg);
            //    ++iTotal;
            //}
            //msg = "处理" + iTotal.ToString() + "," + "成功" + iSuccess.ToString() + "," + "失败" + (iTotal - iSuccess).ToString();
            string msgs = "下载线程启动";

            lb_syssem.Items.Add(msgs);
        }
Beispiel #12
0
        /// <summary>
        /// 下载历史数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_dlstockdata_Click(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();
            lb_syssem.Items.Clear();

            int iTotal = 0;
            int iSuccess = 0;
            int nthread = CfgStruct.lns.Count;
            Thread[] tds = new Thread[nthread];
            string[] msg = new string[nthread + 1];

            foreach (string stkcode in CfgStruct.lns)
            {
                gc.Stkcode = stkcode;
                tds[iTotal] = new Thread(new ThreadStart(delegate ()
                {
                    gc.downloadstockdata(msg[iTotal]);
                }));
                ++iTotal;
            }
            foreach (Thread t in tds)
            {
                t.Start();
                ++iSuccess;
            }

            lbstatusdl.Text = iSuccess.ToString();
            //    if (!gc.downloadstockdata(stkcode))
            //    {
            //        //提示
            //        msg = stkcode + "下载失败。";
            //        ++iSuccess;
            //    }
            //    else
            //        msg = stkcode + "下载成功。";

            //    lb_syssem.Items.Add(msg);
            //    ++iTotal;
            //}
            //msg = "处理" + iTotal.ToString() + "," + "成功" + iSuccess.ToString() + "," + "失败" + (iTotal - iSuccess).ToString();
            string msgs = "下载线程启动";
            lb_syssem.Items.Add(msgs);
        }
Beispiel #13
0
        /// <summary>
        /// 导入数据到DataTable
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void importdatabt_Click(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            string filepath = Directory.GetCurrentDirectory() + "\\" + AdvStock.mystock + ".csv";

            if (File.Exists(filepath))
            {
                statusl.Text = "Importing " + AdvStock.mystock + ".csv" + "……";
                stockdata.Clear();
                stockdata                        = gc.OpenCSV(filepath);
                statusl.Text                     = AdvStock.mystock + ".csv" + " data Get.";
                dataGridView.Visible             = true;
                dataGridView.DataSource          = stockdata;
                dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;    //auto columns width
                DatagBox.Text                    = "Data: " + AdvStock.mystock;
                go_bt.Enabled                    = true;
            }
            else
            {
                MessageBox.Show("File " + AdvStock.mystock + ".csv" + " not exist.");
            }
        }
Beispiel #14
0
        //拼接股票URL
        private void stock_appendurl(string stock, ref string stockurl, string url, bool ispicture)
        {
            GeneralClass gc = new GeneralClass();
            string head = stock.Substring(0, 2);
            Stock_Index si = new Stock_Index();

            if (!gc.stock_checkout(stock, ref si))
                return;

            StringBuilder s = new StringBuilder(url);
            switch (si.market)
            {
                case FlagDef.SH: //上海
                    s.Append("sh");
                    break;
                case FlagDef.SZ: //深证
                    s.Append("sz");
                    break;
                default:
                    return;
            }

            s.Append(stock);
            if(ispicture)
                s.Append(".gif");

            stockurl = s.ToString();
        }
Beispiel #15
0
        /// <summary>
        /// 系统初始化
        /// </summary>
        private void System_Init()
        {
            string errorMsg = null;
            GeneralClass gc = new GeneralClass();
            SqlProcess sp = new SqlProcess();
            UserAccount ua = new UserAccount();

            //界面控制
            stockname_l.Visible = false;
            stockprice_l.Visible = false;
            updownpercent_l.Visible = false;
            volumem_l.Visible = false;
            volumev_l.Visible = false;
            preprice_l.Visible = false;
            cirmarketvalue_l.Visible = false;
            totalvalue_l.Visible = false;
            amplitude_l.Visible = false;
            pbratio_l.Visible = false;
            peratio_l.Visible = false;
            turnoverrate_l.Visible = false;
            toolProgressBar.Visible = false;
            //stockdata.txt路径
            CfgStruct.fileName = Directory.GetCurrentDirectory() + "\\stockdata.txt";
            //tmp_his.csv路径
            CfgStruct.hisdatafilepath = Directory.GetCurrentDirectory() + "\\tmp_his.csv";
            //system.ini路径
            string systemfile = Directory.GetCurrentDirectory() + "\\system.ini";
            //读system.ini
            if (!gc.ReadConfigFile(systemfile, ref CfgStruct.dbconnect_str, ref CfgStruct.dbname))
            {
                MessageBox.Show("-10000读取配置文件失败!请检查配置文件system.ini。");
                return;
            }
            //测试数据库连接
            if (!sp.ConnectSQL(CfgStruct.dbconnect_str))
            {
                MessageBox.Show("-10001数据库连接失败!请重新配置。");
                return;
            }

            //读系统配置信息
            if (!gc.GetSysConfigFromDB(ref errorMsg))
            {
                MessageBox.Show(errorMsg);
                MessageBox.Show("-10002数据库配置信息有误!请重新配置");
                return;
            }
            //用户登录
            string username = "******"; //默认admin登陆
            string userpwd = "990818";
            string loginmsg = null;
            bool loginerror = false;
            CfgStruct.curuserid = ua.UserLogin( username, userpwd );
            switch(CfgStruct.curuserid)
            {
                case FlagDef.ACCOUNTWRONG:
                    loginmsg = "-10003没有该账户:" + username;
                    loginerror = true;
                    break;
                case FlagDef.PWDWRONG:
                    loginmsg = "-10003账户密码错误:" + username;
                    loginerror = true;
                    break;
                default:
                    break;
            }
            if (loginerror)
            {
                MessageBox.Show(loginmsg);
                return;
            }

            //读用户配置信息
            if (!gc.GetUserConfigFromDB(CfgStruct.curuserid, ref username))
            {
                MessageBox.Show("-10004用户表及自选股表有误!请检查配置。");
                return;
            }
            lbusername.Text = username; //用户名显示
            RefreshOptionlist();    //刷新自选列表

            //初始化完成显示
            lb_syssem.Items.Clear();
            string showstock = "系统启动成功。";
            lb_syssem.Items.Add(showstock);
        }
Beispiel #16
0
        /// <summary>
        /// 系统初始化
        /// </summary>
        private void System_Init()
        {
            string       errorMsg = null;
            GeneralClass gc       = new GeneralClass();
            SqlProcess   sp       = new SqlProcess();
            UserAccount  ua       = new UserAccount();

            //界面控制
            stockname_l.Visible      = false;
            stockprice_l.Visible     = false;
            updownpercent_l.Visible  = false;
            volumem_l.Visible        = false;
            volumev_l.Visible        = false;
            preprice_l.Visible       = false;
            cirmarketvalue_l.Visible = false;
            totalvalue_l.Visible     = false;
            amplitude_l.Visible      = false;
            pbratio_l.Visible        = false;
            peratio_l.Visible        = false;
            turnoverrate_l.Visible   = false;
            toolProgressBar.Visible  = false;
            //stockdata.txt路径
            CfgStruct.fileName = Directory.GetCurrentDirectory() + "\\stockdata.txt";
            //tmp_his.csv路径
            CfgStruct.hisdatafilepath = Directory.GetCurrentDirectory() + "\\tmp_his.csv";
            //system.ini路径
            string systemfile = Directory.GetCurrentDirectory() + "\\system.ini";

            //读system.ini
            if (!gc.ReadConfigFile(systemfile, ref CfgStruct.dbconnect_str, ref CfgStruct.dbname))
            {
                MessageBox.Show("-10000读取配置文件失败!请检查配置文件system.ini。");
                return;
            }
            //测试数据库连接
            if (!sp.ConnectSQL(CfgStruct.dbconnect_str))
            {
                MessageBox.Show("-10001数据库连接失败!请重新配置。");
                return;
            }

            //读系统配置信息
            if (!gc.GetSysConfigFromDB(ref errorMsg))
            {
                MessageBox.Show(errorMsg);
                MessageBox.Show("-10002数据库配置信息有误!请重新配置");
                return;
            }
            //用户登录
            string username   = "******"; //默认admin登陆
            string userpwd    = "990818";
            string loginmsg   = null;
            bool   loginerror = false;

            CfgStruct.curuserid = ua.UserLogin(username, userpwd);
            switch (CfgStruct.curuserid)
            {
            case FlagDef.ACCOUNTWRONG:
                loginmsg   = "-10003没有该账户:" + username;
                loginerror = true;
                break;

            case FlagDef.PWDWRONG:
                loginmsg   = "-10003账户密码错误:" + username;
                loginerror = true;
                break;

            default:
                break;
            }
            if (loginerror)
            {
                MessageBox.Show(loginmsg);
                return;
            }

            //读用户配置信息
            if (!gc.GetUserConfigFromDB(CfgStruct.curuserid, ref username))
            {
                MessageBox.Show("-10004用户表及自选股表有误!请检查配置。");
                return;
            }
            lbusername.Text = username; //用户名显示
            RefreshOptionlist();        //刷新自选列表

            //初始化完成显示
            lb_syssem.Items.Clear();
            string showstock = "系统启动成功。";

            lb_syssem.Items.Add(showstock);
        }
Beispiel #17
0
        /// <summary>
        /// 股票输入框检验,限定为数字
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stockntb_TextChanged(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            if (!gc.IsInt(stockntb.Text))
            {
                MessageBox.Show("应该是一个数字", "数据输入错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                stockntb.SelectAll();
                stockntb.Focus();
                return;
            }
        }
Beispiel #18
0
        /// <summary>
        /// 选中个股功能100
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void optionallist_SelectedIndexChanged(object sender, EventArgs e)
        {
            string stockget = optionallist.Text.Split(' ')[0];

            Stock_Index si = new Stock_Index();
            GeneralClass gc = new GeneralClass();

            //检验股票代码是否正确
            if (!gc.stock_checkout(stockget, ref si))
            {
                gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stockget, FlagDef.REMOVE);
                MessageBox.Show("e-100001股票代码不正确,已删除.");
                return;
            }

            stockntb.Text = stockget;
            CfgStruct.stockcur = stockget;
            lb_syssem.Items.Clear();

            string showstock = "当前选择:" + si.stockname;
            lb_syssem.Items.Add(showstock);

            //实时行情获取
            Cycle_stockmarket(sender, e);
        }
Beispiel #19
0
        /// <summary>
        /// 自选股删除功能102
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteStockbt_Click(object sender, EventArgs e)
        {
            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
            string sdel = "确定要删除" + CfgStruct.stockcur + "吗?";
            DialogResult dr = MessageBox.Show(sdel, "删除确定", messButton);
            if (dr == DialogResult.Cancel)  //如果点击“Cancel”按钮
                return;

            GeneralClass gc = new GeneralClass();
            string stkcode = stockntb.Text;
            Stock_Index si = new Stock_Index();

            //校验stkcode
            if (!gc.stock_checkout(stkcode, ref si))
            {
                MessageBox.Show("e-102001股票代码有误");
                //stockntb.Text = "";
                return;
            }

            //在数据库中删除
            if (!gc.ModiUserStocklistFromDB(CfgStruct.curuserid, stkcode, FlagDef.REMOVE))
            {
                MessageBox.Show("e-102002向数据库删除个股失败");
                return;
            }

            RefreshOptionlist();
            stockntb.SelectAll();
            stockntb.Focus();
        }
Beispiel #20
0
        /// <summary>
        /// 导入数据到DataTable
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void importdatabt_Click(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            string filepath = Directory.GetCurrentDirectory() + "\\" + AdvStock.mystock + ".csv";
            if (File.Exists(filepath))
            {
                statusl.Text = "Importing " + AdvStock.mystock + ".csv" + "……";
                stockdata.Clear();
                stockdata = gc.OpenCSV(filepath);
                statusl.Text = AdvStock.mystock + ".csv" + " data Get.";
                dataGridView.Visible = true;
                dataGridView.DataSource = stockdata;
                dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;    //auto columns width
                DatagBox.Text = "Data: " + AdvStock.mystock;
                go_bt.Enabled = true;
            }
            else
                MessageBox.Show("File " + AdvStock.mystock + ".csv" + " not exist.");
        }
Beispiel #21
0
        /// <summary>
        /// 获取股票代码 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void okbutton_Click(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();
            string stockget = stockntb.Text;
            Stock_Index si = new Stock_Index();

            if (gc.stock_checkout(stockget, ref si))
            {
                AdvStock.mystock = stockget;
                statusl.Text = AdvStock.mystock + " Get";
                currentstockl.Text = si.stockname;
            }
            else
                MessageBox.Show("Error: " + stockget + " is not a stock code.");
        }
Beispiel #22
0
        /// <summary>
        ///股票代码检查
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stockntb_TextChanged(object sender, EventArgs e)
        {
            GeneralClass gc = new GeneralClass();

            if (!gc.IsInt(stockntb.Text))
            {
                MessageBox.Show("Please input stock code!", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                stockntb.SelectAll();
                stockntb.Focus();
                return;
            }
        }