using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

 

using System.Data;

using Utilities;

using System.Collections;

 

namespace Services

{

    /// <summary>

    /// Summary description for CustomerService

    /// </summary>

    [WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    [System.ComponentModel.ToolboxItem(false)]

    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

    // [System.Web.Script.Services.ScriptService]

    public class CustomerService : System.Web.Services.WebService

    {

 

        // This method retrieves all the records from the AirlineCustomer table

        [WebMethod]

        public DataSet GetCustomers()

        {

            DBConnect objDB = new DBConnect();

            String strSQL = "SELECT * FROM AirlineCustomer";

            DataSet myDS;

 

            myDS = objDB.GetDataSet(strSQL);

 

            return myDS;

        }

 

        // This method accepts a Customer object and creates a new record based on the values

        // set for the object passed into the method.

        [WebMethod]

        public Boolean AddCustomer(Customer cust)

        {

            if (cust != null)

            {

                DBConnect objDB = new DBConnect();

                String strSQL = "INSERT INTO AirlineCustomer (CustomerName, Address, City, State, Zip, Email) " +

                                 "VALUES ('" + cust.Name + "','" + cust.Address + "','" + cust.City + "','" + cust.State + "'," + cust.Zip + ",'" + cust.Email + "')";

 

                int retVal = objDB.DoUpdate(strSQL);

 

                if (retVal > 0)

                    return true;

                else

                    return false;

            }

            else

            {

                return false;

            }

        }

 

        // This method receives a name for a customer and returns a Customer object with the field values from the database record.

        // This method returns only the first occurrence of a customer name.

        [WebMethod]

        public Customer GetCustomerByName(String name)

        {

            Customer cust = null;

            DBConnect objDB = new DBConnect();

            String strSQL = "SELECT * FROM AirlineCustomer WHERE CustomerName='" + name + "'";

            int count = 0;

 

            objDB.GetDataSet(strSQL, out count);

 

            if (count > 0)

            {

                cust = new Customer();

                cust.Name =  objDB.GetField("CustomerName", 0).ToString();

                cust.Address = objDB.GetField("Address", 0).ToString();

                cust.City = objDB.GetField("City", 0).ToString();

                cust.State = objDB.GetField("State", 0).ToString();

                cust.Zip = (int)objDB.GetField("Zip", 0);

                cust.Email = objDB.GetField("Email", 0).ToString();

            }

 

            return cust;

        }

 

        // This method receives a name for a customer and returns a Customer object with the field values from the database.

        // This method returns an ArrayList of Customer objects that represents all the customers with a given name.

        [WebMethod]

        public ArrayList GetCustomersByName(String name)

        {

            ArrayList customerList = new ArrayList();

            DBConnect objDB = new DBConnect();

            String strSQL = "SELECT * FROM AirlineCustomer WHERE CustomerName='" + name + "'";

            int count = 0;

 

            objDB.GetDataSet(strSQL, out count);

 

            for (int i = 0; i < count; i++ )

            {

                Customer cust = new Customer();

                cust.Name = objDB.GetField("CustomerName", i).ToString();

                cust.Address = objDB.GetField("Address", i).ToString();

                cust.City = objDB.GetField("City", i).ToString();

                cust.State = objDB.GetField("State", i).ToString();

                cust.Zip = (int)objDB.GetField("Zip", i);

                cust.Email = objDB.GetField("Email", i).ToString();

 

                customerList.Add(cust);

            }

 

            return customerList;

        }

    }

}