⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stockquote.cs

📁 NSEGrabber is application to take live feed from nse stock exchange.
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace NSEGrabber {
    public partial class StockQuote : Form {
        string compCode;
        string strProxyPortAddress;
        string strProxyAddress;
        bool expand = false;
        public StockQuote() {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) {
           compCode = companyCode.Text;
            if (string.IsNullOrEmpty(compCode)) {
                MessageBox.Show("Please enter Company code ");
                return;
            }
            try {
                WebRequest request = WebRequest.Create(@"http://www.nseindia.com/marketinfo/equities/cmquote_printer.jsp?key=" + compCode + "EQN&symbol=" + compCode + "&flag=0");
                if (!string.IsNullOrEmpty(strProxyAddress) && !string.IsNullOrEmpty(strProxyPortAddress)) {
                    WebProxy proxy = new WebProxy(strProxyAddress, Int32.Parse(strProxyPortAddress));
                    proxy.UseDefaultCredentials = true;
                    request.Proxy = proxy;
                } else {
                    request.Proxy = WebRequest.DefaultWebProxy;
                }
                
                // Send the 'HttpWebRequest' and wait for response. 
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                System.IO.Stream stream = response.GetResponseStream();
                System.Text.Encoding ec = System.Text.Encoding.GetEncoding("utf-8");
                System.IO.StreamReader reader = new System.IO.StreamReader(stream, ec);
                string str = reader.ReadToEnd();
                float lastTradePrice = NSEUtilities.getLastTradePrice(str);
                float prevDayClose = NSEUtilities.getPreviousDayClose(str);
                float percentage = NSEUtilities.calculatePercentage(prevDayClose, lastTradePrice);
                float todayHigh = NSEUtilities.getTodaysHigh(str);
                float todayLow = NSEUtilities.getTodaysLow(str);
                int tradeQuantity = NSEUtilities.getTradeQuantity(str);
                ltp.Text = lastTradePrice.ToString();
                pdc.Text = prevDayClose.ToString();
                tq.Text = tradeQuantity.ToString();
                pc.Text = percentage.ToString();
                th.Text = todayHigh.ToString();
                tl.Text = todayLow.ToString();

                viewGraph.Enabled = true;
                response.Close();
                stream.Close();
                reader.Close();
                
                
            } catch (Exception ex) {
                MessageBox.Show("Failed to get data. Reason: " + ex.Message);
            }
        }

         
        private void button2_Click(object sender, EventArgs e) {
            try {
                graph g = new graph(compCode);
                g.ShowDialog(this);
            } catch (Exception exp) {
                MessageBox.Show("Loading of graph failed. Reason: " + exp.Message);
            }

        }

        private void button1_Click_1(object sender, EventArgs e) {
            this.Close();
        }

        private void button2_Click_1(object sender, EventArgs e) {
            if (expand) {
                button2.Text = "Proxy Settings <<";
                this.Size = new Size(285, 529);
                expand = false;
            } else {
                button2.Text = "Proxy Settings >>";
                this.Size = new Size(285, 411);
                expand = true;   
            }
        }

        private void Form1_Load(object sender, EventArgs e) {
            expand = false;
            button2_Click_1(sender, e);

        }

        private void button3_Click(object sender, EventArgs e) {

            if (radioButton2.Checked) {
                strProxyPortAddress = proxyPortNumber.Text;
                strProxyAddress = proxyAddress.Text;
                try {
                    WebProxy proxy = new WebProxy(strProxyAddress, Int32.Parse(strProxyPortAddress));
                    button2_Click_1(sender, e);
                } catch (Exception) {
                    MessageBox.Show("Invalid proxy . Please re-enter again");
                }
            } else {
                button2_Click_1(sender, e);
            }
           
        }
        private void SetEnableValue(bool val) {
            proxyAddress.Enabled = val;
            proxyPortNumber.Enabled = val;
            label8.Enabled = val;
            label9.Enabled = val;
        }

        private void radioButton1_CheckedChanged_1(object sender, EventArgs e) {
            if (radioButton1.Checked) {
                SetEnableValue(false);
            } else {
                SetEnableValue(true);
            }
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -