using System;
using System.Web;
using System.Data;
using System.Data.Odbc;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    public Service () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string getQuotesWS(string organization_name)
    {

        string connString = "DSN=MySQLODBC;UID=root;PWD=ateet";
        OdbcConnection conn = new OdbcConnection(connString);
        OdbcCommand comm = new OdbcCommand();
        comm.Connection = conn;

        comm.CommandText = "select OrganizationID from organizationtable where OrganizationName = '" + organization_name + "'";
        conn.Open();

        OdbcDataAdapter da = new OdbcDataAdapter(comm);
        DataSet ds = new DataSet();
        da.Fill(ds);

        DataRow row = ds.Tables[0].Rows[0];
        string organization_id = row[0].ToString();

        comm.CommandText = "select currentprice from organizationpredict where OrganizationID = " + organization_id + "";
        OdbcDataAdapter da1 = new OdbcDataAdapter(comm);
        DataSet ds1 = new DataSet();
        da1.Fill(ds1);

        DataRow row1 = ds1.Tables[0].Rows[0];
        string currentQuotePrice = row1[0].ToString();

        return currentQuotePrice;

    }

    [WebMethod]
    public string getPredictionWS(string organization_name)
    {
        string connString = "DSN=MySQLODBC;UID=root;PWD=ateet";
        OdbcConnection conn = new OdbcConnection(connString);
        OdbcCommand comm = new OdbcCommand();
        comm.Connection = conn;
        comm.CommandTimeout = 300;
        comm.CommandText = "select OrganizationID from organizationtable where OrganizationName = '" + organization_name + "'";
        conn.Open();

        OdbcDataAdapter da = new OdbcDataAdapter(comm);
        DataSet ds = new DataSet();
        da.Fill(ds);

        DataRow row = ds.Tables[0].Rows[0];
        string organization_id = row[0].ToString();

        comm.CommandText = "select predictsignal,predictprice,recognitionrate from organizationpredict where OrganizationID = " + organization_id + "";
        OdbcDataAdapter da1 = new OdbcDataAdapter(comm);
        DataSet ds1 = new DataSet();
        da1.Fill(ds1);

        string predictionarray;
        predictionarray = ds1.Tables[0].Rows[0].ItemArray[0] + "," + ds1.Tables[0].Rows[0].ItemArray[1] + "," + ds1.Tables[0].Rows[0].ItemArray[2];

        return predictionarray;
    }
    
}
