Example #1
0
File: Form1.cs Project: nak9x/WCF
        public Form1()
        {
            InitializeComponent();

            try
            {
                newsControl = new List<Control>();
                analysisControl = new List<Control>();

                EndpointAddress stockPriceAddress = new EndpointAddress("http://localhost:90/StockPrice");
                EndpointAddress stockNewsAddress = new EndpointAddress("http://localhost:90/StockNews");
                EndpointAddress stockFinanceAddress = new EndpointAddress("http://localhost:90/StockFinance");
                EndpointAddress stockForecastAddress = new EndpointAddress("http://localhost:90/StockForecast");

                BasicHttpBinding stockPriceBinding = new BasicHttpBinding();
                BasicHttpBinding stockNewsBinding = new BasicHttpBinding();
                WSDualHttpBinding stockForecastBinding = new WSDualHttpBinding();
                stockForecastBinding.ClientBaseAddress = new Uri("http://localhost:90/");

                stockPriceProxy = ChannelFactory<IStockPrice>.CreateChannel(stockPriceBinding, stockPriceAddress);
                stockNewsProxy = ChannelFactory<IStockNews>.CreateChannel(stockNewsBinding, stockNewsAddress);
                stockFinanceProxy = ChannelFactory<IFinancialIndicatorService>.CreateChannel(new BasicHttpBinding(), stockFinanceAddress);

                InstanceContext insContext = new InstanceContext(this);
                stockForecastProxy = new ForecastServiceClient(insContext, stockForecastBinding, stockForecastAddress);

                List<string[]> mostIncrease = stockPriceProxy.GetMostIncrease();
                List<string[]> mostDecrease = stockPriceProxy.GetMostDecrease();
                List<string[]> mostTraded = stockPriceProxy.GetMostTraded();

                DataTable mostIncreaseSource = ToDataTable(mostIncrease, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume", "Change(%)" }, new int[] { 1, 3, 4, 5, 6, 7, 8 });
                DataTable mostDecreaseSource = ToDataTable(mostDecrease, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume", "Change(%)" }, new int[] { 1, 3, 4, 5, 6, 7, 8 });
                DataTable mostTradedSource = ToDataTable(mostTraded, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume" }, 5);

                dgvMostIncrease.DataSource = mostIncreaseSource;
                dgvMostDecrease.DataSource = mostDecreaseSource;
                dgvMostTraded.DataSource = mostTradedSource;

                int colCount = dgvMostIncrease.Columns.Count;
                int colWidth = (dgvMostIncrease.Width - 41) / 7;

                AutoSizeColumns(dgvMostIncrease, new int[] { 69, 69, 69, 69, 69, 69, 68 });
                AutoSizeColumns(dgvMostDecrease, new int[] { 69, 69, 69, 69, 69, 69, 68 });
                AutoSizeColumns(dgvMostTraded, new int[] { 80, 80, 80, 80, 81, 81 });

                AddNews(stockNewsProxy.GetNews("", Convert.ToInt32(txtViewCount.Value)));
                AddAnalysis(stockNewsProxy.GetExpertAnalysis("", Convert.ToInt32(txtAnalysisCount.Value)));

                List<string[]> periodsList = stockFinanceProxy.GetPeriods("HNM");
                foreach (string[] period in periodsList)
                {
                    string result = "Q" + period[0] + "/" + period[1];
                    cbbQuarter.Items.Add(result);
                }
                cbbQuarter.SelectedIndex = cbbQuarter.Items.Count - 1;

                cbbForecastsNum.SelectedIndex = cbbForecastsNum.Items.Count - 1;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error connecting to service. Press OK to quit");
                Environment.Exit(-1);
            }
        }