using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ajans
{
    class car:connection
    {
        protected string car_id;
        protected string car_type;
        protected string car_number;
        protected string car_status;
        protected string car_class;

        public car()
        {
            car_id = "";
            car_type = "";
            car_number = "";
            car_status = "";
            car_class = "";
        }

        public void SetCarID(string carID)
        {
            car_id = carID;
        }
        public void SetCarType(string carType)
        {
            car_type = carType;
        }
        public void SetCarNumber(string carNumber)
        {
            car_number = carNumber;
        }
        public void SetCarStatus(string carStatus)
        {
            car_status = carStatus;
        }
        public void SetCarClass(string carClass)
        {
            car_class = carClass;
        }

        public void InsertCar()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "INSERT INTO car VALUES(N'" + car_id + "',N'" + car_type + "',N'" + car_number + "',N'" + car_status + "',N'" + car_class + "',0)";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public DataSet SelectCar()
        {
            objds.Clear();
            objda.SelectCommand = new SqlCommand();
            objda.SelectCommand.Connection = objconn;
            objda.SelectCommand.CommandText = "select car_id as [کد ماشین] , car_type as [نوع ماشین], car_number as [نمره ماشین],car_class as [کلاس ماشین],car_status as [وضعیت] from car WHERE car_id != 0 AND car_delete = 0";
            objda.SelectCommand.CommandType = CommandType.Text;
            objconn.Open();
            objda.Fill(objds, "car");
            objconn.Close();
            return objds;
        }

        public DataSet SelectCar(string carID)
        {
            objds.Clear();
            objda.SelectCommand = new SqlCommand();
            objda.SelectCommand.Connection = objconn;
            objda.SelectCommand.CommandText = "select car_id as [کد ماشین] , car_type as [نام ماشین], car_number as [نمره ماشین],car_class as [کلاس ماشین], car_status as [وضعیت] from car WHERE car_id='" + carID + "'AND car_id != 0 AND car_delete = 0";
            objda.SelectCommand.CommandType = CommandType.Text;
            objconn.Open();
            objda.Fill(objds, "car");
            objconn.Close();
            return objds;
        }

        public DataSet SelectCar2(string carType)
        {
            objds.Clear();
            objda.SelectCommand = new SqlCommand();
            objda.SelectCommand.Connection = objconn;
            objda.SelectCommand.CommandText = "select car_id as [کد ماشین] , car_type as [نام ماشین] ,car_number as [نمره ماشین],car_class as [کلاس ماشین], car_status as [وضعیت] from car WHERE car_type LIKE N'%" + carType + "%' AND car_id !=0 AND car_delete = 0";
            objda.SelectCommand.CommandType = CommandType.Text;
            objconn.Open();
            objda.Fill(objds, "car");
            objconn.Close();
            return objds;
        }

        public void UpdateCar()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "UPDATE car SET car_type='" + car_type + "',car_number='" + car_number + "',car_class='" + car_class + "' WHERE car_id='" + car_id + "'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
            objcomm.CommandText = "UPDATE driver SET dvr_car='" + car_type + "',dvr_car_class='" + car_class + "' FROM driver INNER JOIN car ON driver.car_id=car.car_id WHERE car.car_id='" + car_id + "'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public void UpdateCarStatus()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "UPDATE car SET car_status='" + "مشغول" + "' WHERE car_id='" + car_id + "'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public void UpdateCarStatus2()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "UPDATE car SET car_status='" + "آزاد" + "' WHERE car_id='" + car_id + "'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public void UpdateAllCarStatus()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "UPDATE car SET car_status='" + "آزاد" + "' WHERE car_id !='0'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public DataSet MaxCarID()
        {
            objds.Clear();
            objda.SelectCommand = new SqlCommand();
            objda.SelectCommand.Connection = objconn;
            objda.SelectCommand.CommandText = "SELECT MAX(car_id) as [MAX] FROM car";
            objda.SelectCommand.CommandType = CommandType.Text;
            objconn.Open();
            objda.Fill(objds, "car");
            objconn.Close();
            return objds;
        }

        public void DeleteCar()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "UPDATE car SET car_delete=1 WHERE car_id='" + car_id + "'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public void DeleteAllCar()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "UPDATE car SET car_delete=1 WHERE  car_id !='0'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }
    }
}
