Esempio n. 1
0
        public List <string> GetAllBusPlusOnRoat(int id)
        {
            List <string> busList = new WaybillDAO().GetAllBus();
            Waybil        waybil  = new WaybillDAO().GetById(id);

            Connect();
            try
            {
                string     query       = "SELECT*FROM Bus where NumberPlate='@BusId'";
                SqlCommand commandRead = new SqlCommand(query, Connection);
                commandRead.Parameters.AddWithValue("@BusId", waybil.BusId);
                SqlDataReader reader = commandRead.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        busList.Add(Convert.ToString(reader["NumberPlate"]));
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("ERROR: " + e.Message);
            }
            finally
            {
                Disconnect();
            }
            return(busList);
        }
Esempio n. 2
0
        public List <Conductor> GetAllConductorPlusOnRoat(int id)
        {
            List <Conductor> conductors = new WaybillDAO().GetAllConductor();
            Waybil           waybil     = new WaybillDAO().GetById(id);

            Connect();
            try
            {
                string     query       = "SELECT*FROM Conductor INNER JOIN Employees ON Conductor.id=Employees.personnelNumber where Id=@ConductorId";
                SqlCommand commandRead = new SqlCommand(query, Connection);
                commandRead.Parameters.AddWithValue("@ConductorId", waybil.ConductorId);
                SqlDataReader reader = commandRead.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Conductor conductor = new Conductor();
                        conductor.PersonnelNumber = Convert.ToInt32(reader["personnelNumber"]);
                        conductor.LastName        = Convert.ToString(reader["LastName"]) + Convert.ToString(reader["FirstName"]);
                        conductors.Add(conductor);
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("ERROR: " + e.Message);
            }
            finally
            {
                Disconnect();
            }
            return(conductors);
        }
Esempio n. 3
0
        public bool DeleteWaybil(int id)
        {
            bool result = true;

            log.Info("Вызывается метод который удаляет запись в таблице Путевых листов");
            WaybillDAO waybillD = new WaybillDAO();
            Waybil     waybil   = waybillD.GetById(id);

            Connect();
            try
            {
                string sql = "UPDATE Bus SET Status=@Status where numberPlate='@BusId';";
                sql += "UPDATE Conductor SET onRoute=@onRoute1 where Id=@ConductorId;";
                sql += "UPDATE Driver SET onRoute=@onRoute2 where Id=@DriverId;";
                SqlCommand cmd_SQL = new SqlCommand(sql, Connection);
                cmd_SQL.Parameters.AddWithValue("@BusId", waybil.BusId);
                cmd_SQL.Parameters.AddWithValue("@ConductorId", waybil.ConductorId);
                cmd_SQL.Parameters.AddWithValue("@DriverId", waybil.DriverId);
                cmd_SQL.Parameters.AddWithValue("@Status", false);
                cmd_SQL.Parameters.AddWithValue("@onRoute1", false);
                cmd_SQL.Parameters.AddWithValue("@onRoute2", false);
                cmd_SQL.ExecuteNonQuery();
            }
            catch (SqlException e)
            {
                log.Error("ERROR: " + e.Message);
                result = false;
            }
            finally
            {
                Disconnect();
            }

            if (result)
            {
                Connect();
                try
                {
                    string     sql     = "DELETE FROM Waybil WHERE Id =@id";
                    SqlCommand cmd_SQL = new SqlCommand(sql, Connection);
                    cmd_SQL.Parameters.AddWithValue("@id", id);
                    cmd_SQL.ExecuteNonQuery();
                }
                catch (SqlException e)
                {
                    log.Error("ERROR: " + e.Message);
                    result = false;
                }
                finally
                {
                    Disconnect();
                }
            }

            return(result);
        }