//------------------------------------------------------------------------------
// written by: Shivangi C
// assisted by: NA
// debugged by:Shivangi C
//
// summary: This file has the binding of the UI controls and display with the 
//          bussiness layer functions for the Page which searches for stocks
//          
//------------------------------------------------------------------------------


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


namespace StockForecasterClient
{
    public partial class ForecasterClient : System.Web.UI.Page
    {
        /// <summary>
        /// make the webservice object to call the web methods required
        /// </summary>
        SFSService.StockInfo serviceObj;              

        /// <summary>
        /// The functions to be called and controls to be loaded on Page load event 
        /// are initialize/called here
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
          serviceObj = new SFSService.StockInfo();
          Panel1.Visible = false;
          lblMsg.Visible = false;      

        }
        /// <summary>
        /// Code for on Button Click event for the Search stock functionality
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DataSet compinfo;
            // call to webservice method FindStock
            compinfo =  (DataSet)serviceObj.FindStock(txtInput.Text);
            if (compinfo.Tables[0].Rows.Count != 0)
            {
                Panel1.Visible = true;
                // for dynamic creation of table rows and colums at runtime to 
                //display the matching companies
                for (int i = 0; i < compinfo.Tables[0].Rows.Count; i++)
                {
                    HyperLink lnkStock = new HyperLink();
                    lnkStock.ID = "lnkStock" + i;
                    lnkStock.Text = compinfo.Tables[0].Rows[i][0].ToString().ToUpper();
                    lnkStock.NavigateUrl = "Performance.aspx?ID=" + compinfo.Tables[0].Rows[i][1].ToString();
                    HtmlTableRow row = new HtmlTableRow();
                    HtmlTableCell cell = new HtmlTableCell();
                    cell.Controls.Add(lnkStock);
                    row.Cells.Add(cell);
                    tblMatchStocks.Rows.Add(row);

                }
            }
            else
            {
                lblMsg.Visible = true;
                lblMsg.Font.Bold = true;
                lblMsg.Text = "Sorry!! No Matching Data Found";
            }
        }

        
        protected void txtInput_TextChanged(object sender, EventArgs e)
        {
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
    }
}
