Exemple #1
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);
        }